Skip to content

Commit

Permalink
Merge pull request #413 from Scale3-Labs/development
Browse files Browse the repository at this point in the history
Fix Sending User feedback
  • Loading branch information
alizenhom authored Nov 21, 2024
2 parents 3755dc6 + 7582a27 commit 33f36e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/langtrace_python_sdk/utils/with_root_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
"""

import base64
import asyncio
import os
from deprecated import deprecated
Expand Down Expand Up @@ -145,7 +146,9 @@ class SendUserFeedback:
_langtrace_api_key: str

def __init__(self):
self._langtrace_host = os.environ.get("LANGTRACE_API_HOST", LANGTRACE_REMOTE_URL)
self._langtrace_host = os.environ.get(
"LANGTRACE_API_HOST", LANGTRACE_REMOTE_URL
)
# When the host is set to /api/trace, remove the /api/trace
if self._langtrace_host.endswith("/api/trace"):
self._langtrace_host = self._langtrace_host.replace("/api/trace", "")
Expand All @@ -162,14 +165,13 @@ def evaluate(self, data: EvaluationAPIData) -> None:
print(Fore.RESET)
return

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

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

evaluation = self.get_evaluation(data["spanId"])
headers = {"x-api-key": self._langtrace_api_key}
Expand Down
2 changes: 1 addition & 1 deletion src/langtrace_python_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.3.7"
__version__ = "3.3.8"

0 comments on commit 33f36e0

Please sign in to comment.