langtrace-python-sdk 2.3.1__py3-none-any.whl → 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,7 +76,29 @@ class LangTraceExporter(SpanExporter):
76
76
  Returns:
77
77
  The result of the export SUCCESS or FAILURE
78
78
  """
79
- if not self.api_key and not self.disable_logging:
79
+ headers = {
80
+ "Content-Type": "application/json",
81
+ "x-api-key": self.api_key,
82
+ "User-Agent": "LangtraceExporter",
83
+ }
84
+
85
+ # Check if the OTEL_EXPORTER_OTLP_HEADERS environment variable is set
86
+ otel_headers = os.getenv("OTEL_EXPORTER_OTLP_HEADERS", None)
87
+ if otel_headers:
88
+ # Parse and add to headers
89
+ for header in otel_headers.split(","):
90
+ key, value = header.split("=")
91
+ headers[key.strip()] = value.strip()
92
+
93
+ # Check if the OTEL_EXPORTER_OTLP_TRACES_HEADERS environment variable is set
94
+ otel_traces_headers = os.getenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS", None)
95
+ if otel_traces_headers:
96
+ # Parse and add to headers
97
+ for header in otel_traces_headers.split(","):
98
+ key, value = header.split("=")
99
+ headers[key.strip()] = value.strip()
100
+
101
+ if not headers["x-api-key"] and not self.disable_logging:
80
102
  print(Fore.RED)
81
103
  print(
82
104
  "Missing Langtrace API key, proceed to https://langtrace.ai to create one"
@@ -101,11 +123,7 @@ class LangTraceExporter(SpanExporter):
101
123
  response = requests.post(
102
124
  url=f"{self.api_host}",
103
125
  data=json.dumps(data),
104
- headers={
105
- "Content-Type": "application/json",
106
- "x-api-key": self.api_key,
107
- "User-Agent": "LangtraceExporter",
108
- },
126
+ headers=headers,
109
127
  timeout=20,
110
128
  )
111
129
 
@@ -113,14 +131,34 @@ class LangTraceExporter(SpanExporter):
113
131
  raise RequestException(response.text)
114
132
  if not self.disable_logging:
115
133
  print(
116
- Fore.GREEN + f"Exported {len(spans)} spans successfully." + Fore.RESET
134
+ Fore.GREEN
135
+ + f"Exported {len(spans)} spans successfully."
136
+ + Fore.RESET
117
137
  )
118
138
  return SpanExportResult.SUCCESS
119
139
  except RequestException as err:
120
140
  if not self.disable_logging:
121
141
  print(Fore.RED + "Failed to export spans.")
122
- print(Fore.RED + f"Error: {err}" + Fore.RESET)
142
+ print(Fore.RED + f"Error: {err}\r\n" + Fore.RESET)
143
+ if (
144
+ "invalid api key" in str(err).lower()
145
+ and self.api_host == f"{LANGTRACE_REMOTE_URL}/api/trace"
146
+ ):
147
+ print(
148
+ Fore.YELLOW
149
+ + "If you're self-hosting Langtrace, make sure to do one of the following to configure your trace endpoint (e.g., http://localhost:3000/api/trace):"
150
+ + Fore.YELLOW
151
+ )
152
+ print(
153
+ Fore.YELLOW
154
+ + "1. Set the `LANGTRACE_API_HOST` environment variable, or\r\n2. Pass the `api_host` parameter to the `langtrace.init()` method.\r\n"
155
+ + Fore.YELLOW
156
+ )
123
157
  return SpanExportResult.FAILURE
124
158
 
125
159
  def shutdown(self) -> None:
126
- print(Fore.WHITE + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace" + Fore.RESET)
160
+ print(
161
+ Fore.WHITE
162
+ + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace"
163
+ + Fore.RESET
164
+ )
@@ -80,11 +80,19 @@ def init(
80
80
  sys.stdout = open(os.devnull, "w")
81
81
 
82
82
  host = (
83
- os.environ.get("LANGTRACE_API_HOST", None) or api_host or LANGTRACE_REMOTE_URL
83
+ os.environ.get("LANGTRACE_API_HOST", None)
84
+ or os.environ.get("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", None)
85
+ or os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT", None)
86
+ or api_host
87
+ or LANGTRACE_REMOTE_URL
84
88
  )
85
89
  check_if_sdk_is_outdated()
86
90
  print(Fore.GREEN + "Initializing Langtrace SDK.." + Fore.RESET)
87
- print(Fore.WHITE + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace" + Fore.RESET)
91
+ print(
92
+ Fore.WHITE
93
+ + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace"
94
+ + Fore.RESET
95
+ )
88
96
  sampler = LangtraceSampler(disabled_methods=disable_tracing_for_functions)
89
97
  resource = Resource.create(
90
98
  attributes={
@@ -1 +1 @@
1
- __version__ = "2.3.1"
1
+ __version__ = "2.3.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.3.1
3
+ Version: 2.3.2
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -79,8 +79,8 @@ examples/vertexai_example/main.py,sha256=gndId5X5ksD-ycxnAWMdEqIDbLc3kz5Vt8vm4YP
79
79
  examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
80
80
  examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
81
81
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
82
- langtrace_python_sdk/langtrace.py,sha256=QNqnla5gQhWLDS6-kXPGV-MnqNDp0BQ4zdbkWI8sC50,8290
83
- langtrace_python_sdk/version.py,sha256=neZxeMmEfjhVZM6xetRikrBdHWt5T5ehL72ZYdPtJ-E,22
82
+ langtrace_python_sdk/langtrace.py,sha256=vtV_sRQfdpdzk4pS2TLZwnsHTpf02kH7peEGyoaumvI,8469
83
+ langtrace_python_sdk/version.py,sha256=J4CRnpR3v72FGOMp8gqSua_XWZpAfXuqgVWiQFB-gTY,22
84
84
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
85
85
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
86
86
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -99,7 +99,7 @@ langtrace_python_sdk/constants/instrumentation/qdrant.py,sha256=yL7BopNQTXW7L7Z-
99
99
  langtrace_python_sdk/constants/instrumentation/vertexai.py,sha256=0s2vX3Y0iwjOPkUg5lAKi-7o3LaNivDSBBbF-o695Ok,1266
100
100
  langtrace_python_sdk/constants/instrumentation/weaviate.py,sha256=gtv-JBxvNGClEMxClmRKzjJ1khgOonsli4D_k9IagSE,2601
101
101
  langtrace_python_sdk/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
102
- langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=2ausFBC9JIitnpu1yECPCL0SXg_IvJTQL0MMsuidTo4,4700
102
+ langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=nbDFxDsDRjpi7otiHHnQ3Z9_LYqLCgxdtP4IWnnOuyI,6307
103
103
  langtrace_python_sdk/extensions/langtrace_filesystem.py,sha256=34fZutG28EJ66l67OvTGsydAH3ZpXgikdE7hVLqBpG4,7863
104
104
  langtrace_python_sdk/instrumentation/__init__.py,sha256=bkyxh6lq_6dgCdbBseFQEbejRTLZv4s9nLBfNSqL6lk,1548
105
105
  langtrace_python_sdk/instrumentation/anthropic/__init__.py,sha256=donrurJAGYlxrSRA3BIf76jGeUcAx9Tq8CVpah68S0Y,101
@@ -214,8 +214,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
214
214
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
215
215
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
216
216
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
217
- langtrace_python_sdk-2.3.1.dist-info/METADATA,sha256=0Fw1oqbrCzau9d3ug7HFvm2D0tyBRW1OmsDroFDey9U,15011
218
- langtrace_python_sdk-2.3.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
219
- langtrace_python_sdk-2.3.1.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
220
- langtrace_python_sdk-2.3.1.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
221
- langtrace_python_sdk-2.3.1.dist-info/RECORD,,
217
+ langtrace_python_sdk-2.3.2.dist-info/METADATA,sha256=vgPuuPsZ-0cWK4ubA2roie37BseA7QZE6lpZ51ZaTQU,15011
218
+ langtrace_python_sdk-2.3.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
219
+ langtrace_python_sdk-2.3.2.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
220
+ langtrace_python_sdk-2.3.2.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
221
+ langtrace_python_sdk-2.3.2.dist-info/RECORD,,