Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trace][refactor] Move tracing related functions to a better place #2990

Merged
merged 15 commits into from
Apr 25, 2024
Prev Previous commit
Next Next commit
remove format xxx id
  • Loading branch information
zhengfeiwang committed Apr 24, 2024
commit f99dd8fbc90e2848d8682ca112d506429ff9056a
Original file line number Diff line number Diff line change
@@ -5,8 +5,6 @@
import datetime
import typing

from opentelemetry.trace.span import format_span_id, format_trace_id

from promptflow._sdk._constants import TRACE_DEFAULT_COLLECTION, TRACE_LIST_DEFAULT_LIMIT
from promptflow._sdk._orm.retry import sqlite_retry
from promptflow._sdk._orm.session import trace_mgmt_db_session
@@ -24,24 +22,6 @@ class TraceOperations:
def __init__(self):
self._logger = get_cli_sdk_logger()

@staticmethod
def format_span_id(span_id: bytes) -> str:
"""Format span id to hex string.
Note that we need to add 0x since it is how opentelemetry-sdk does.
Reference: https://github.com/open-telemetry/opentelemetry-python/blob/
642f8dd18eea2737b4f8cd2f6f4d08a7e569c4b2/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L505
"""
return f"0x{format_span_id(int.from_bytes(span_id, byteorder='big', signed=False))}"

@staticmethod
def format_trace_id(trace_id: bytes) -> str:
"""Format trace_id id to hex string.
Note that we need to add 0x since it is how opentelemetry-sdk does.
Reference: https://github.com/open-telemetry/opentelemetry-python/blob/
642f8dd18eea2737b4f8cd2f6f4d08a7e569c4b2/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L505
"""
return f"0x{format_trace_id(int.from_bytes(trace_id, byteorder='big', signed=False))}"

def get_event(self, event_id: str) -> typing.Dict:
return Event.get(event_id=event_id)