Skip to content

Commit 129f764

Browse files
committed
Merge branch 'main' of github.com:Scale3-Labs/langtrace-python-sdk into release
2 parents 41c58e8 + 4740f7c commit 129f764

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

src/langtrace_python_sdk/instrumentation/milvus/patch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from langtrace_python_sdk.constants.instrumentation.common import SERVICE_PROVIDERS
12
from langtrace_python_sdk.utils.silently_fail import silently_fail
23
from opentelemetry.trace import Tracer
34
from opentelemetry.trace import SpanKind
45
from langtrace_python_sdk.utils import handle_span_error, set_span_attribute
56
from langtrace_python_sdk.utils.llm import (
7+
get_langtrace_attributes,
68
get_extra_attributes,
79
set_span_attributes,
810
)
@@ -16,6 +18,11 @@ def traced_method(wrapped, instance, args, kwargs):
1618
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
1719
try:
1820
span_attributes = {
21+
**get_langtrace_attributes(
22+
service_provider=SERVICE_PROVIDERS["MILVUS"],
23+
version=version,
24+
vendor_type="Vector Database",
25+
),
1926
"db.system": "milvus",
2027
"db.operation": operation,
2128
"db.name": kwargs.get("collection_name", None),

src/langtrace_python_sdk/instrumentation/mistral/patch.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
def chat_complete(original_method, version, tracer, is_async=False, is_streaming=False):
49-
49+
5050
def traced_method(wrapped, instance, args, kwargs):
5151
service_provider = SERVICE_PROVIDERS["MISTRAL"]
5252
llm_prompts = []
@@ -65,7 +65,6 @@ def traced_method(wrapped, instance, args, kwargs):
6565

6666
attributes = LLMSpanAttributes(**span_attributes)
6767

68-
6968
span = tracer.start_span(
7069
name=get_span_name(APIS[api]["METHOD"]),
7170
kind=SpanKind.CLIENT,
@@ -87,7 +86,6 @@ def traced_method(wrapped, instance, args, kwargs):
8786
span.set_status(StatusCode.OK)
8887
span.end()
8988
return result
90-
9189

9290
except Exception as error:
9391
span.record_exception(error)
@@ -186,7 +184,6 @@ def _set_response_attributes(span, kwargs, result):
186184
for choice in result.choices
187185
]
188186
set_event_completion(span, responses)
189-
190187
# Get the usage
191188
if hasattr(result, "usage") and result.usage is not None:
192-
set_usage_attributes(span, result.usage)
189+
set_usage_attributes(span, dict(result.usage))

src/langtrace_python_sdk/utils/with_root_span.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17+
import base64
1718
import asyncio
1819
import os
1920
from deprecated import deprecated
@@ -145,7 +146,9 @@ class SendUserFeedback:
145146
_langtrace_api_key: str
146147

147148
def __init__(self):
148-
self._langtrace_host = os.environ.get("LANGTRACE_API_HOST", LANGTRACE_REMOTE_URL)
149+
self._langtrace_host = os.environ.get(
150+
"LANGTRACE_API_HOST", LANGTRACE_REMOTE_URL
151+
)
149152
# When the host is set to /api/trace, remove the /api/trace
150153
if self._langtrace_host.endswith("/api/trace"):
151154
self._langtrace_host = self._langtrace_host.replace("/api/trace", "")
@@ -162,14 +165,13 @@ def evaluate(self, data: EvaluationAPIData) -> None:
162165
print(Fore.RESET)
163166
return
164167

165-
# convert spanId and traceId to hexadecimals
166-
span_hex_number = hex(int(data["spanId"], 10))[2:] # Convert to hex and remove the '0x' prefix
167-
formatted_span_hex_number = span_hex_number.zfill(16) # Pad with zeros to 16 characters
168-
data["spanId"] = f"0x{formatted_span_hex_number}"
168+
# convert spanId and traceId to Base64
169+
span_bytes = int(data["spanId"], 10).to_bytes(8, "big")
170+
data["spanId"] = base64.b64encode(span_bytes).decode("ascii")
169171

170-
trace_hex_number = hex(int(data["traceId"], 10))[2:] # Convert to hex and remove the '0x' prefix
171-
formatted_trace_hex_number = trace_hex_number.zfill(32) # Pad with zeros to 32 characters
172-
data["traceId"] = f"0x{formatted_trace_hex_number}"
172+
# Convert traceId to base64
173+
trace_bytes = int(data["traceId"], 10).to_bytes(16, "big")
174+
data["traceId"] = base64.b64encode(trace_bytes).decode("ascii")
173175

174176
evaluation = self.get_evaluation(data["spanId"])
175177
headers = {"x-api-key": self._langtrace_api_key}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.3.6"
1+
__version__ = "3.3.9"

0 commit comments

Comments
 (0)