telemetry-dev-bedrock 0.3.0__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telemetry-dev-bedrock
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: AWS Bedrock integration for telemetry.dev Python SDK
5
5
  Keywords: telemetry,opentelemetry,bedrock,aws,boto3,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.0
17
+ Requires-Dist: telemetry-dev>=0.3.9
18
18
  Requires-Dist: boto3>=1.36
19
19
  Requires-Python: >=3.10
20
20
  Project-URL: Homepage, https://telemetry.dev
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-bedrock"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "AWS Bedrock integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -26,7 +26,7 @@ classifiers = [
26
26
  "Typing :: Typed",
27
27
  ]
28
28
  dependencies = [
29
- "telemetry-dev>=0.3.0",
29
+ "telemetry-dev>=0.3.9",
30
30
  "boto3>=1.36",
31
31
  ]
32
32
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-bedrock"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "AWS Bedrock 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.0",
22
+ "telemetry-dev>=0.3.9",
23
23
  "boto3>=1.36",
24
24
  ]
25
25
 
@@ -2,6 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  from ._instrument import instrument_bedrock, uninstrument_bedrock, wrap_bedrock
4
4
 
5
- __version__ = "0.3.0"
5
+ __version__ = "0.3.2"
6
6
 
7
7
  __all__ = ["__version__", "instrument_bedrock", "uninstrument_bedrock", "wrap_bedrock"]
@@ -5,6 +5,7 @@ from dataclasses import dataclass
5
5
  from typing import Any, Literal, cast
6
6
 
7
7
  import telemetry_dev
8
+ from telemetry_dev._serialize import json_dumps
8
9
 
9
10
  from ._fields import (
10
11
  PROVIDER,
@@ -44,6 +45,40 @@ def _model(params: dict[str, Any]) -> str | None:
44
45
  return params.get("modelId") if isinstance(params.get("modelId"), str) else None
45
46
 
46
47
 
48
+ def _tool_definitions(tool_config: Any) -> dict[str, str]:
49
+ """The tools of ``toolConfig`` as ``gen_ai.tool.definitions``: each tool's name, and with
50
+ input capture on its description and the JSON Schema of its input. A system tool is listed
51
+ as ``system_tool``. The core SDK also strips descriptions and schemas with capture off; this
52
+ check keeps them out with a core older than that rule."""
53
+ tools = tool_config.get("tools") if isinstance(tool_config, dict) else None
54
+ if not isinstance(tools, list):
55
+ return {}
56
+ client = telemetry_dev.get_client()
57
+ content = client is not None and client.capture_input
58
+ definitions: list[dict[str, Any]] = []
59
+ for tool in cast("list[Any]", tools):
60
+ if not isinstance(tool, dict):
61
+ continue
62
+ fields = cast("dict[str, Any]", tool)
63
+ system = fields.get("systemTool")
64
+ if isinstance(system, dict) and isinstance(system.get("name"), str):
65
+ definitions.append({"type": "system_tool", "name": system["name"]})
66
+ continue
67
+ spec = fields.get("toolSpec")
68
+ if not isinstance(spec, dict) or not isinstance(spec.get("name"), str):
69
+ continue
70
+ spec = cast("dict[str, Any]", spec)
71
+ definition: dict[str, Any] = {"type": "function", "name": spec["name"]}
72
+ if content:
73
+ if isinstance(spec.get("description"), str):
74
+ definition["description"] = spec["description"]
75
+ schema = spec.get("inputSchema")
76
+ if isinstance(schema, dict) and "json" in schema:
77
+ definition["parameters"] = schema["json"]
78
+ definitions.append(definition)
79
+ return {"gen_ai.tool.definitions": _tools_json(definitions)} if definitions else {}
80
+
81
+
47
82
  def _converse_request(params: dict[str, Any]) -> dict[str, Any]:
48
83
  inference = (
49
84
  params.get("inferenceConfig") if isinstance(params.get("inferenceConfig"), dict) else {}
@@ -57,7 +92,11 @@ def _converse_request(params: dict[str, Any]) -> dict[str, Any]:
57
92
  "model": _model(params),
58
93
  "input": normalize_messages(params.get("messages")),
59
94
  "system_instructions": normalize_content_list(params.get("system")) or None,
60
- "attributes": prompt_attributes(params.get("messages")) or None,
95
+ "attributes": {
96
+ **_tool_definitions(params.get("toolConfig")),
97
+ **prompt_attributes(params.get("messages")),
98
+ }
99
+ or None,
61
100
  "temperature": inference.get("temperature"),
62
101
  "top_p": inference.get("topP"),
63
102
  "max_tokens": inference.get("maxTokens"),
@@ -530,3 +569,14 @@ def lookup_operation(service_name: str, operation_name: str) -> OperationSpec |
530
569
  if service is None:
531
570
  return None
532
571
  return service.get(operation_name)
572
+
573
+
574
+ def _tools_json(definitions: list[dict[str, Any]]) -> str:
575
+ """The definitions as JSON, or only their types and names when a schema cannot be
576
+ serialized, such as one holding a cycle: the wrapper maps the request outside any catch."""
577
+ try:
578
+ return json_dumps(definitions)
579
+ except (TypeError, ValueError):
580
+ return json_dumps(
581
+ [{key: tool[key] for key in ("type", "name") if key in tool} for tool in definitions]
582
+ )