Skip to content

Commit 0f7e5c6

Browse files
committed
Merge branch 'main' into stash_gencontent_changes
2 parents 04bff33 + 7208140 commit 0f7e5c6

28 files changed

Lines changed: 481 additions & 99 deletions

File tree

instrumentation-genai/opentelemetry-instrumentation-anthropic/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ classifiers = [
2525
"Programming Language :: Python :: 3.14",
2626
]
2727
dependencies = [
28-
"opentelemetry-api ~= 1.39",
29-
"opentelemetry-instrumentation ~= 0.60b0",
30-
"opentelemetry-semantic-conventions ~= 0.60b0",
28+
"opentelemetry-api ~= 1.40",
29+
"opentelemetry-instrumentation ~= 0.61b0",
30+
"opentelemetry-semantic-conventions ~= 0.61b0",
3131
"opentelemetry-util-genai >= 0.4b0.dev, <0.5b0",
3232
]
3333

instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.oldest.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pytest==7.4.4
2121
pytest-vcr==1.0.2
2222
pytest-asyncio==0.21.0
2323
wrapt==1.16.0
24-
opentelemetry-api==1.39 # when updating, also update in pyproject.toml
25-
opentelemetry-sdk==1.39 # when updating, also update in pyproject.toml
26-
opentelemetry-semantic-conventions==0.60b0 # when updating, also update in pyproject.toml
24+
opentelemetry-api==1.40 # when updating, also update in pyproject.toml
25+
opentelemetry-sdk==1.40 # when updating, also update in pyproject.toml
26+
opentelemetry-semantic-conventions==0.61b0 # when updating, also update in pyproject.toml
2727

2828
-e instrumentation-genai/opentelemetry-instrumentation-anthropic

instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ classifiers = [
2525
"Programming Language :: Python :: 3.14",
2626
]
2727
dependencies = [
28-
"opentelemetry-api >= 1.39",
29-
"opentelemetry-instrumentation >= 0.58b0",
30-
"opentelemetry-semantic-conventions >= 0.60b0",
28+
"opentelemetry-api >= 1.40",
29+
"opentelemetry-instrumentation >= 0.61b0",
30+
"opentelemetry-semantic-conventions >= 0.61b0",
3131
"opentelemetry-util-genai >= 0.4b0.dev"
3232
]
3333

instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/tests/requirements.oldest.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pytest-asyncio==0.21.0
2626
wrapt==1.16.0
2727
opentelemetry-exporter-otlp-proto-grpc~=1.30
2828
opentelemetry-exporter-otlp-proto-http~=1.30
29-
opentelemetry-api==1.39 # when updating, also update in pyproject.toml
30-
opentelemetry-sdk==1.39 # when updating, also update in pyproject.toml
31-
opentelemetry-semantic-conventions==0.60b0 # when updating, also update in pyproject.toml
29+
opentelemetry-api==1.40 # when updating, also update in pyproject.toml
30+
opentelemetry-sdk==1.40 # when updating, also update in pyproject.toml
31+
opentelemetry-semantic-conventions==0.61b0 # when updating, also update in pyproject.toml
3232
grpcio>=1.60.0; implementation_name != "pypy"
3333
grpcio<1.60.0; implementation_name == "pypy"
3434

instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Pass tool definitions from `tools` kwarg to `InferenceInvocation.tool_definitions`
11+
so `gen_ai.tool.definitions` span attribute is populated on chat completion spans
12+
([#4554](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4554))
13+
1014
## Version 2.4b0 (2026-05-01)
1115

1216

instrumentation-genai/opentelemetry-instrumentation-openai-v2/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ classifiers = [
2525
"Programming Language :: Python :: 3.14",
2626
]
2727
dependencies = [
28-
"opentelemetry-api ~= 1.39",
29-
"opentelemetry-instrumentation ~= 0.60b0",
30-
"opentelemetry-semantic-conventions ~= 0.60b0",
28+
"opentelemetry-api ~= 1.40",
29+
"opentelemetry-instrumentation ~= 0.61b0",
30+
"opentelemetry-semantic-conventions ~= 0.61b0",
3131
"opentelemetry-util-genai >= 0.4b0.dev",
3232
]
3333

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
from opentelemetry.util.genai.handler import TelemetryHandler
3333
from opentelemetry.util.genai.invocation import InferenceInvocation
3434
from opentelemetry.util.genai.types import (
35+
FunctionToolDefinition,
3536
InputMessage,
3637
OutputMessage,
3738
Text,
3839
ToolCallRequest,
3940
ToolCallResponse,
41+
ToolDefinition,
4042
)
4143

4244
_OpenAIOmit = getattr(openai, "Omit", None)
@@ -397,6 +399,9 @@ def create_chat_invocation(
397399
invocation.input_messages = _prepare_input_messages(
398400
kwargs.get("messages", [])
399401
)
402+
invocation.tool_definitions = _prepare_tool_definitions(
403+
kwargs.get("tools")
404+
)
400405
return invocation
401406

402407

@@ -475,6 +480,26 @@ def extract_tool_calls_new(tool_calls) -> list[ToolCallRequest]:
475480
return parts
476481

477482

483+
def _prepare_tool_definitions(tools) -> list[ToolDefinition] | None:
484+
if not tools:
485+
return None
486+
487+
definitions: list[ToolDefinition] = []
488+
for tool in tools:
489+
tool_type = get_property_value(tool, "type")
490+
if tool_type == "function":
491+
func = get_property_value(tool, "function")
492+
if func:
493+
definitions.append(
494+
FunctionToolDefinition(
495+
name=get_property_value(func, "name") or "",
496+
description=get_property_value(func, "description"),
497+
parameters=get_property_value(func, "parameters"),
498+
)
499+
)
500+
return definitions
501+
502+
478503
def _prepare_output_messages(choices) -> List[OutputMessage]:
479504
output_messages = []
480505
for choice in choices:

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/requirements.oldest.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pytest-vcr==1.0.2
2929
pytest-asyncio==0.21.0
3030
wrapt==1.16.0
3131
opentelemetry-exporter-otlp-proto-http~=1.30
32-
opentelemetry-api==1.39 # when updating, also update in pyproject.toml
33-
opentelemetry-sdk==1.39 # when updating, also update in pyproject.toml
34-
opentelemetry-semantic-conventions==0.60b0 # when updating, also update in pyproject.toml
32+
opentelemetry-api==1.40 # when updating, also update in pyproject.toml
33+
opentelemetry-sdk==1.40 # when updating, also update in pyproject.toml
34+
opentelemetry-semantic-conventions==0.61b0 # when updating, also update in pyproject.toml
3535

3636
-e instrumentation-genai/opentelemetry-instrumentation-openai-v2
3737
-e util/opentelemetry-util-genai

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_async_chat_completions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from .test_utils import (
2424
DEFAULT_MODEL,
25+
EXPECTED_TOOL_DEFINITIONS,
2526
USER_ONLY_EXPECTED_INPUT_MESSAGES,
2627
USER_ONLY_PROMPT,
2728
WEATHER_TOOL_EXPECTED_INPUT_MESSAGES,
@@ -616,6 +617,12 @@ async def chat_completion_tool_call(
616617
spans[0].attributes["gen_ai.output.messages"], first_output
617618
)
618619

620+
assert_messages_attribute(
621+
spans[0].attributes["gen_ai.tool.definitions"],
622+
EXPECTED_TOOL_DEFINITIONS,
623+
)
624+
assert "gen_ai.tool.definitions" not in spans[1].attributes
625+
619626
# second call
620627
del first_output[0]["finish_reason"]
621628
second_input = []
@@ -1271,6 +1278,10 @@ async def async_chat_completion_multiple_tools_streaming(
12711278
assert_messages_attribute(
12721279
spans[0].attributes["gen_ai.output.messages"], first_output
12731280
)
1281+
assert_messages_attribute(
1282+
spans[0].attributes["gen_ai.tool.definitions"],
1283+
EXPECTED_TOOL_DEFINITIONS,
1284+
)
12741285
else:
12751286
assert len(logs) == 3
12761287

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
from .test_utils import (
3838
DEFAULT_MODEL,
39+
EXPECTED_TOOL_DEFINITIONS,
3940
USER_ONLY_EXPECTED_INPUT_MESSAGES,
4041
USER_ONLY_PROMPT,
4142
WEATHER_TOOL_EXPECTED_INPUT_MESSAGES,
@@ -747,6 +748,12 @@ def chat_completion_tool_call(
747748
spans[0].attributes["gen_ai.output.messages"], first_output
748749
)
749750

751+
assert_messages_attribute(
752+
spans[0].attributes["gen_ai.tool.definitions"],
753+
EXPECTED_TOOL_DEFINITIONS,
754+
)
755+
assert "gen_ai.tool.definitions" not in spans[1].attributes
756+
750757
# second call
751758
del first_output[0]["finish_reason"]
752759
second_input = []
@@ -1416,6 +1423,10 @@ def chat_completion_multiple_tools_streaming(
14161423
assert_messages_attribute(
14171424
spans[0].attributes["gen_ai.output.messages"], first_output
14181425
)
1426+
assert_messages_attribute(
1427+
spans[0].attributes["gen_ai.tool.definitions"],
1428+
EXPECTED_TOOL_DEFINITIONS,
1429+
)
14191430
else:
14201431
assert len(logs) == 3
14211432

0 commit comments

Comments
 (0)