1414limitations under the License.
1515"""
1616
17+ import base64
1718import asyncio
1819import os
1920from 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 }
0 commit comments