Skip to content

Commit b802671

Browse files
huaiyanrobbenwang
and
robbenwang
authored
Fix unset span_type. Align default value with local sdk (#2753)
# Description Use None for span_type's default value. For customer created span, span_type is not always exist. Use `None` as default value to align with local sdk. # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** - [ ] **Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: [suggested workflow](../CONTRIBUTING.md#suggested-workflow).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. Co-authored-by: robbenwang <[email protected]>
1 parent 160d975 commit b802671

File tree

1 file changed

+8
-11
lines changed
  • src/promptflow-azure/promptflow/azure/_storage/cosmosdb

1 file changed

+8
-11
lines changed

src/promptflow-azure/promptflow/azure/_storage/cosmosdb/summary.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import datetime
21
import logging
32
import time
43
import typing
@@ -36,15 +35,15 @@ class SummaryLine:
3635
session_id: str
3736
trace_id: str
3837
collection_id: str
39-
root_span_id: str = ""
38+
root_span_id: str = None
4039
inputs: typing.Dict = field(default_factory=dict)
4140
outputs: typing.Dict = field(default_factory=dict)
42-
start_time: str = ""
43-
end_time: str = ""
44-
status: str = ""
41+
start_time: str = None
42+
end_time: str = None
43+
status: str = None
4544
latency: float = 0.0
46-
name: str = ""
47-
kind: str = ""
45+
name: str = None
46+
kind: str = None
4847
created_by: typing.Dict = field(default_factory=dict)
4948
cumulative_token_count: typing.Optional[typing.Dict[str, int]] = field(default_factory=dict)
5049
evaluations: typing.Dict = field(default_factory=dict)
@@ -198,9 +197,7 @@ def _persist_line_run(self, client: ContainerProxy):
198197

199198
# Span's original format don't include latency, so we need to calculate it.
200199
# Convert ISO 8601 formatted strings to datetime objects
201-
start_time_date = datetime.datetime.fromisoformat(start_time.replace("Z", "+00:00"))
202-
end_time_date = datetime.datetime.fromisoformat(end_time.replace("Z", "+00:00"))
203-
latency = (end_time_date - start_time_date).total_seconds()
200+
latency = (self.span.end_time - self.span.start_time).total_seconds()
204201
# calculate `cumulative_token_count`
205202
completion_token_count = int(attributes.get(SpanAttributeFieldName.COMPLETION_TOKEN_COUNT, 0))
206203
prompt_token_count = int(attributes.get(SpanAttributeFieldName.PROMPT_TOKEN_COUNT, 0))
@@ -228,7 +225,7 @@ def _persist_line_run(self, client: ContainerProxy):
228225
status=self.span.status[SpanStatusFieldName.STATUS_CODE],
229226
latency=latency,
230227
name=self.span.name,
231-
kind=attributes[SpanAttributeFieldName.SPAN_TYPE],
228+
kind=attributes.get(SpanAttributeFieldName.SPAN_TYPE, None),
232229
cumulative_token_count=cumulative_token_count,
233230
created_by=self.created_by,
234231
)

0 commit comments

Comments
 (0)