telemetry-dev 0.3.7__tar.gz → 0.3.8__tar.gz
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.
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/PKG-INFO +1 -1
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/pyproject.toml +1 -1
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/pyproject.toml.orig +1 -1
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_semconv.py +2 -2
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_spans.py +94 -2
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/LICENSE +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/README.md +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/__init__.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_api.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_capture.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_ci.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_client.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_config.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_context.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_experiments.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_export.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_logs.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_metrics.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_observe.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_process_lock.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_processor.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_prompts.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_scores.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/_serialize.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/otel.py +0 -0
- {telemetry_dev-0.3.7 → telemetry_dev-0.3.8}/src/telemetry_dev/py.typed +0 -0
|
@@ -7,8 +7,8 @@ SCOPE_NAME = "telemetry_dev"
|
|
|
7
7
|
SpanType = Literal["span", "generation", "tool", "agent", "embedding"]
|
|
8
8
|
LogLevel = Literal["debug", "info", "warn", "warning", "error"]
|
|
9
9
|
|
|
10
|
-
# Plain spans ALWAYS map to "function"
|
|
11
|
-
#
|
|
10
|
+
# Plain spans ALWAYS map to "function": without one, the ingest guesses "llm" from other gen_ai.*
|
|
11
|
+
# keys on the span, such as a gen_ai.agent.name the caller set.
|
|
12
12
|
SPAN_TYPE_TO_OPERATION: dict[str, str] = {
|
|
13
13
|
"span": "function",
|
|
14
14
|
"generation": "chat",
|
|
@@ -10,7 +10,7 @@ from collections.abc import Callable, Mapping, Sequence
|
|
|
10
10
|
from contextvars import Token
|
|
11
11
|
from dataclasses import dataclass
|
|
12
12
|
from datetime import datetime
|
|
13
|
-
from typing import Any, Literal, TypedDict
|
|
13
|
+
from typing import Any, Literal, TypedDict, cast
|
|
14
14
|
from weakref import WeakKeyDictionary, WeakValueDictionary
|
|
15
15
|
|
|
16
16
|
from opentelemetry import context as otel_context
|
|
@@ -151,10 +151,102 @@ def _to_ns(value: TimeInput) -> int | None:
|
|
|
151
151
|
return int(value)
|
|
152
152
|
|
|
153
153
|
|
|
154
|
+
# Error classes that provider SDKs raise for any failed request, whose name says nothing about the
|
|
155
|
+
# cause: openai's and anthropic's APIStatusError (anthropic's for a stream's error event), and
|
|
156
|
+
# google-genai's APIError, ClientError, and ServerError. botocore's ClientError, and its
|
|
157
|
+
# EventStreamError for a Bedrock stream's exception, carry their code in `response`. Plain
|
|
158
|
+
# Exception is here for errors that carry a code, such as the failures that the integrations build
|
|
159
|
+
# from a response body with `code` and `type` attributes. The TypeScript SDK keeps the same rule in
|
|
160
|
+
# `errorTypeOf` (packages/otel/src/errors.ts); change both together.
|
|
161
|
+
_GENERIC_ERROR_NAMES = frozenset(
|
|
162
|
+
{"Exception", "APIError", "APIStatusError", "ClientError", "ServerError", "EventStreamError"}
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _text(value: object) -> str | None:
|
|
167
|
+
return value if isinstance(value, str) and value else None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _error_code(value: object) -> str | None:
|
|
171
|
+
# Some providers send numeric codes, such as Z.ai's "1302" for a rate limit, and openai's SDK
|
|
172
|
+
# turns OpenRouter's numeric code into a string. A number names no cause the way a class does.
|
|
173
|
+
code = _text(value)
|
|
174
|
+
return None if code is None or code.isdigit() else code
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _http_status(value: object) -> int | None:
|
|
178
|
+
return (
|
|
179
|
+
value
|
|
180
|
+
if isinstance(value, int) and not isinstance(value, bool) and 400 <= value <= 599
|
|
181
|
+
else None
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _nested(value: object, *keys: str) -> object:
|
|
186
|
+
for key in keys:
|
|
187
|
+
if not isinstance(value, Mapping):
|
|
188
|
+
return None
|
|
189
|
+
value = cast("Mapping[str, object]", value).get(key)
|
|
190
|
+
return value
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _attribute(error: BaseException, name: str) -> object:
|
|
194
|
+
# A property of a third-party exception can raise anything; recording the error must not.
|
|
195
|
+
try:
|
|
196
|
+
return getattr(error, name, None)
|
|
197
|
+
except Exception:
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _error_type(error: BaseException) -> str:
|
|
202
|
+
"""The error.type of a failure: the provider's error code when the error carries one.
|
|
203
|
+
|
|
204
|
+
- An error with an HTTP status and a code that is not only digits (openai's
|
|
205
|
+
`insufficient_quota`, `context_length_exceeded`) gives the code.
|
|
206
|
+
- A generic provider error class gives its code, else its HTTP status (`429`), else the
|
|
207
|
+
provider's error type (anthropic's `overloaded_error` from a stream).
|
|
208
|
+
- Any other error gives its class name.
|
|
209
|
+
"""
|
|
210
|
+
name = type(error).__name__
|
|
211
|
+
body = _attribute(error, "body")
|
|
212
|
+
code = _error_code(_attribute(error, "code")) or _error_code(_nested(body, "error", "code"))
|
|
213
|
+
status = next(
|
|
214
|
+
(
|
|
215
|
+
status
|
|
216
|
+
for status in (
|
|
217
|
+
_http_status(_attribute(error, attribute))
|
|
218
|
+
for attribute in ("status_code", "code", "status")
|
|
219
|
+
)
|
|
220
|
+
if status is not None
|
|
221
|
+
),
|
|
222
|
+
None,
|
|
223
|
+
)
|
|
224
|
+
if code is not None and status is not None:
|
|
225
|
+
return code
|
|
226
|
+
if name not in _GENERIC_ERROR_NAMES:
|
|
227
|
+
return name
|
|
228
|
+
if code is not None:
|
|
229
|
+
return code
|
|
230
|
+
if status is not None:
|
|
231
|
+
return str(status)
|
|
232
|
+
aws_code = _text(_nested(_attribute(error, "response"), "Error", "Code"))
|
|
233
|
+
if aws_code is not None:
|
|
234
|
+
# botocore names a Bedrock stream's exception by its event, such as
|
|
235
|
+
# modelStreamErrorException; the TypeScript SDK records its class,
|
|
236
|
+
# ModelStreamErrorException.
|
|
237
|
+
aws_code = aws_code[0].upper() + aws_code[1:]
|
|
238
|
+
return (
|
|
239
|
+
_text(_attribute(error, "type"))
|
|
240
|
+
or _text(_nested(body, "error", "type"))
|
|
241
|
+
or aws_code
|
|
242
|
+
or name
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
|
|
154
246
|
def _record_error_on_span(
|
|
155
247
|
client: Client, span: Span, state: _SpanState, error: BaseException
|
|
156
248
|
) -> None:
|
|
157
|
-
error_type =
|
|
249
|
+
error_type = _error_type(error)
|
|
158
250
|
span.set_attribute(ATTR_ERROR_TYPE, error_type)
|
|
159
251
|
span.set_status(Status(StatusCode.ERROR))
|
|
160
252
|
attributes: dict[str, otel_types.AttributeValue] = {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|