telemetry-dev-openai 0.2.6__tar.gz → 0.2.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_openai-0.2.6 → telemetry_dev_openai-0.2.8}/PKG-INFO +3 -3
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/README.md +1 -1
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/pyproject.toml +2 -2
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/pyproject.toml.orig +2 -2
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/src/telemetry_dev_openai/__init__.py +54 -3
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/LICENSE +0 -0
- {telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/src/telemetry_dev_openai/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: telemetry-dev-openai
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
4
4
|
Summary: OpenAI integration for telemetry.dev Python SDK
|
|
5
5
|
Keywords: telemetry,opentelemetry,openai,llm,genai,tracing
|
|
6
6
|
Author: telemetry.dev
|
|
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
16
|
Classifier: Typing :: Typed
|
|
17
|
-
Requires-Dist: telemetry-dev>=0.3.
|
|
17
|
+
Requires-Dist: telemetry-dev>=0.3.9
|
|
18
18
|
Requires-Dist: openai>=2,<4
|
|
19
19
|
Requires-Python: >=3.10
|
|
20
20
|
Project-URL: Homepage, https://telemetry.dev
|
|
@@ -103,7 +103,7 @@ Chat completion streams are traced. Requests are sent unchanged by default, so t
|
|
|
103
103
|
|
|
104
104
|
Streamed chat output is kept up to 16 MiB, and all streams in flight share the `max_stream_bytes` bound of the core (64 MiB by default). These bounds need a `telemetry-dev` core with `max_stream_bytes`; with an older core, each stream keeps up to 64 KiB and 1,024 items. Each streamed finish reason is cut to its first 128 characters, without setting `telemetry.dev.capture.truncated`, and the finish reasons of a stream have their own budget, which fits at least 1,000 of them; the configured `max_attribute_length` does not shrink these retention bounds; the core applies it to the exported attribute after the mask runs, with its `...[truncated]` marker, without setting `telemetry.dev.capture.truncated`. A chat stream inspects at most 1,000 choices and 1,000 tool calls in each chunk; past these caps the rest is not kept and `telemetry.dev.capture.truncated` is set. When present, `gen_ai.output.messages` contains bounded partial output. If output and/or finish-reason capture is incomplete, including when a choice ends without `finish_reason`, `telemetry.dev.capture.truncated` is `true`. With a mask configured, incomplete output is omitted because the mask cannot inspect the complete value. When output capture is disabled or omitted, response IDs and models, finish reasons, usage, timing, and errors may still be recorded.
|
|
105
105
|
|
|
106
|
-
Capture flags do not gate stop sequences or caller-supplied metadata or raw attributes; redact those separately when needed. Exception messages and stack traces are recorded only when both `capture_input` and `capture_output` are on, and pass through `mask`.
|
|
106
|
+
Capture flags do not gate stop sequences or caller-supplied metadata or raw attributes; redact those separately when needed. Exception messages and stack traces are recorded only when both `capture_input` and `capture_output` are on, and pass through `mask`. Model spans list the request's tools in `gen_ai.tool.definitions`: each tool's type and name, and with `capture_input` on the description and parameters (a custom tool's input format) of each function and custom tool, which pass through `mask`.
|
|
107
107
|
|
|
108
108
|
```py
|
|
109
109
|
client = wrap_openai(OpenAI(), inject_stream_usage=True)
|
|
@@ -80,7 +80,7 @@ Chat completion streams are traced. Requests are sent unchanged by default, so t
|
|
|
80
80
|
|
|
81
81
|
Streamed chat output is kept up to 16 MiB, and all streams in flight share the `max_stream_bytes` bound of the core (64 MiB by default). These bounds need a `telemetry-dev` core with `max_stream_bytes`; with an older core, each stream keeps up to 64 KiB and 1,024 items. Each streamed finish reason is cut to its first 128 characters, without setting `telemetry.dev.capture.truncated`, and the finish reasons of a stream have their own budget, which fits at least 1,000 of them; the configured `max_attribute_length` does not shrink these retention bounds; the core applies it to the exported attribute after the mask runs, with its `...[truncated]` marker, without setting `telemetry.dev.capture.truncated`. A chat stream inspects at most 1,000 choices and 1,000 tool calls in each chunk; past these caps the rest is not kept and `telemetry.dev.capture.truncated` is set. When present, `gen_ai.output.messages` contains bounded partial output. If output and/or finish-reason capture is incomplete, including when a choice ends without `finish_reason`, `telemetry.dev.capture.truncated` is `true`. With a mask configured, incomplete output is omitted because the mask cannot inspect the complete value. When output capture is disabled or omitted, response IDs and models, finish reasons, usage, timing, and errors may still be recorded.
|
|
82
82
|
|
|
83
|
-
Capture flags do not gate stop sequences or caller-supplied metadata or raw attributes; redact those separately when needed. Exception messages and stack traces are recorded only when both `capture_input` and `capture_output` are on, and pass through `mask`.
|
|
83
|
+
Capture flags do not gate stop sequences or caller-supplied metadata or raw attributes; redact those separately when needed. Exception messages and stack traces are recorded only when both `capture_input` and `capture_output` are on, and pass through `mask`. Model spans list the request's tools in `gen_ai.tool.definitions`: each tool's type and name, and with `capture_input` on the description and parameters (a custom tool's input format) of each function and custom tool, which pass through `mask`.
|
|
84
84
|
|
|
85
85
|
```py
|
|
86
86
|
client = wrap_openai(OpenAI(), inject_stream_usage=True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "telemetry-dev-openai"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.8"
|
|
4
4
|
description = "OpenAI integration for telemetry.dev Python SDK"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -25,7 +25,7 @@ classifiers = [
|
|
|
25
25
|
"Typing :: Typed",
|
|
26
26
|
]
|
|
27
27
|
dependencies = [
|
|
28
|
-
"telemetry-dev>=0.3.
|
|
28
|
+
"telemetry-dev>=0.3.9",
|
|
29
29
|
"openai>=2,<4",
|
|
30
30
|
]
|
|
31
31
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "telemetry-dev-openai"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.8"
|
|
4
4
|
description = "OpenAI integration for telemetry.dev Python SDK"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -19,7 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Typing :: Typed",
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|
|
22
|
-
"telemetry-dev>=0.3.
|
|
22
|
+
"telemetry-dev>=0.3.9",
|
|
23
23
|
"openai>=2,<4",
|
|
24
24
|
]
|
|
25
25
|
|
{telemetry_dev_openai-0.2.6 → telemetry_dev_openai-0.2.8}/src/telemetry_dev_openai/__init__.py
RENAMED
|
@@ -22,8 +22,9 @@ from openai.resources.chat.completions.completions import AsyncCompletions, Comp
|
|
|
22
22
|
from openai.resources.embeddings import AsyncEmbeddings, Embeddings
|
|
23
23
|
from openai.resources.images import AsyncImages, Images
|
|
24
24
|
from openai.resources.responses.responses import AsyncResponses, Responses
|
|
25
|
+
from telemetry_dev._serialize import json_dumps
|
|
25
26
|
|
|
26
|
-
__version__ = "0.2.
|
|
27
|
+
__version__ = "0.2.8"
|
|
27
28
|
|
|
28
29
|
ProviderResolver = Callable[[object | None], str]
|
|
29
30
|
RequestMapper = Callable[[Mapping[str, Any]], tuple[str, dict[str, Any]]]
|
|
@@ -435,9 +436,45 @@ def _prompt_attributes(messages: object) -> dict[str, Any]:
|
|
|
435
436
|
return cast("dict[str, Any]", read(messages)) if callable(read) else {}
|
|
436
437
|
|
|
437
438
|
|
|
439
|
+
def _tool_definitions(tools: Any) -> dict[str, str] | None:
|
|
440
|
+
"""The request tools as ``gen_ai.tool.definitions``: each tool's type and name, and with input
|
|
441
|
+
capture on a function or custom tool's description and its parameters (custom tools: their
|
|
442
|
+
input format). Chat Completions nests a tool under ``function`` or ``custom``; Responses puts
|
|
443
|
+
it at the top. A built-in tool without a name, such as ``web_search``, is listed by its type.
|
|
444
|
+
The core SDK also strips descriptions and schemas with capture off; this check keeps them out
|
|
445
|
+
with a core older than that rule."""
|
|
446
|
+
client = telemetry_dev.get_client()
|
|
447
|
+
content = client is not None and client.capture_input
|
|
448
|
+
definitions: list[dict[str, Any]] = []
|
|
449
|
+
for tool in _sequence_items(tools):
|
|
450
|
+
kind = _string(_field(tool, "type"))
|
|
451
|
+
if kind is None:
|
|
452
|
+
continue
|
|
453
|
+
spec = _field(tool, "custom" if kind == "custom" else "function") or tool
|
|
454
|
+
name = _string(_field(spec, "name"))
|
|
455
|
+
if kind not in ("function", "custom"):
|
|
456
|
+
definitions.append({"type": kind} if name is None else {"type": kind, "name": name})
|
|
457
|
+
continue
|
|
458
|
+
if name is None:
|
|
459
|
+
continue
|
|
460
|
+
definition: dict[str, Any] = {"type": kind, "name": name}
|
|
461
|
+
if content:
|
|
462
|
+
description = _string(_field(spec, "description"))
|
|
463
|
+
if description is not None:
|
|
464
|
+
definition["description"] = description
|
|
465
|
+
parameters = _field(spec, "format" if kind == "custom" else "parameters")
|
|
466
|
+
if parameters is not None:
|
|
467
|
+
definition["parameters"] = parameters
|
|
468
|
+
definitions.append(definition)
|
|
469
|
+
return {"gen_ai.tool.definitions": _tools_json(definitions)} if definitions else None
|
|
470
|
+
|
|
471
|
+
|
|
438
472
|
def _chat_request(params: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
|
|
439
473
|
model = _string(params.get("model"))
|
|
440
|
-
attributes =
|
|
474
|
+
attributes = {
|
|
475
|
+
**(_tool_definitions(params.get("tools")) or {}),
|
|
476
|
+
**_prompt_attributes(params.get("messages")),
|
|
477
|
+
}
|
|
441
478
|
captured, truncated = _bounded_responses_capture(params.get("messages"), "input")
|
|
442
479
|
if truncated:
|
|
443
480
|
attributes["telemetry.dev.capture.truncated"] = True
|
|
@@ -521,7 +558,10 @@ def _chat_response(response: Any) -> dict[str, Any]:
|
|
|
521
558
|
|
|
522
559
|
def _responses_request(params: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
|
|
523
560
|
model = _string(params.get("model"))
|
|
524
|
-
attributes =
|
|
561
|
+
attributes = {
|
|
562
|
+
**(_tool_definitions(params.get("tools")) or {}),
|
|
563
|
+
**_prompt_attributes(params.get("input")),
|
|
564
|
+
}
|
|
525
565
|
captured, truncated = _bounded_responses_capture(params.get("input"), "input")
|
|
526
566
|
if truncated:
|
|
527
567
|
attributes["telemetry.dev.capture.truncated"] = True
|
|
@@ -3231,3 +3271,14 @@ def uninstrument_openai() -> None:
|
|
|
3231
3271
|
|
|
3232
3272
|
|
|
3233
3273
|
__all__ = ["__version__", "instrument_openai", "uninstrument_openai", "wrap_openai"]
|
|
3274
|
+
|
|
3275
|
+
|
|
3276
|
+
def _tools_json(definitions: list[dict[str, Any]]) -> str:
|
|
3277
|
+
"""The definitions as JSON, or only their types and names when a schema cannot be
|
|
3278
|
+
serialized, such as one holding a cycle: the wrapper maps the request outside any catch."""
|
|
3279
|
+
try:
|
|
3280
|
+
return json_dumps(definitions)
|
|
3281
|
+
except (TypeError, ValueError):
|
|
3282
|
+
return json_dumps(
|
|
3283
|
+
[{key: tool[key] for key in ("type", "name") if key in tool} for tool in definitions]
|
|
3284
|
+
)
|
|
File without changes
|
|
File without changes
|