Skip to content

Commit f0096d6

Browse files
authored
Merge branch 'main' into django-issue-fix
2 parents a9d30e6 + 74ff31b commit f0096d6

File tree

25 files changed

+648
-316
lines changed

25 files changed

+648
-316
lines changed

.github/component_owners.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ components:
99
instrumentation/opentelemetry-instrumentation-asyncio:
1010
- bourbonkk
1111

12+
instrumentation/opentelemetry-instrumentation-botocore:
13+
- lukeina2z
14+
- yiyuan-he
15+
1216
instrumentation/opentelemetry-instrumentation-pymssql:
13-
- guillaumep
17+
- guillaumep
1418

1519
instrumentation/opentelemetry-instrumentation-urllib:
1620
- shalevr
@@ -43,4 +47,4 @@ components:
4347

4448
instrumentation-genai/opentelemetry-instrumentation-langchain:
4549
- zhirafovod
46-
- wrisa
50+
- wrisa

CHANGELOG.md

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

1616
- `opentelemetry-instrumentation-dbapi`: fix crash retrieving libpq version when enabling commenter with psycopg
1717
([#3796](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3796))
18+
- `opentelemetry-instrumentation-vertexai`: migrate off the deprecated events API to use the logs API
19+
([#3625](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3626))
1820

1921
### Added
2022
- `opentelemetry-instrumentation`: botocore: Add support for AWS Secrets Manager semantic convention attribute

instrumentation-genai/opentelemetry-instrumentation-vertexai/CHANGELOG.md

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

88
## Unreleased
99

10-
- Start making changes to implement the big semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.
11-
Now only a single event (`gen_ai.client.inference.operation.details`) is used to capture Chat History. These changes will be opt-in,
12-
users will need to set the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to `gen_ai_latest_experimental` to see them ([#3386](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3386)).
10+
- Update instrumentation to use the latest semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.
11+
Now only a single event and span (`gen_ai.client.inference.operation.details`) are used to capture prompt and response content. These changes are opt-in,
12+
users will need to set the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to `gen_ai_latest_experimental` to see them ([#3799](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3799)) and ([#3709](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3709)).
1313
- Implement uninstrument for `opentelemetry-instrumentation-vertexai`
1414
([#3328](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3328))
1515
- VertexAI support for async calling

instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/manual/.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,17 @@ OTEL_SERVICE_NAME=opentelemetry-python-vertexai
66

77
# Change to 'false' to hide prompt and completion content
88
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
9+
10+
# Alternatively set this env var to enable the latest semantic conventions:
11+
OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental
12+
13+
# When using the latest experimental flag this env var controls which telemetry signals will have prompt and response content included in them.
14+
# Choices are NO_CONTENT, SPAN_ONLY, EVENT_ONLY, SPAN_AND_EVENT.
15+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT
16+
17+
# Optional hook that will upload prompt and response content to some external destination.
18+
# For example fsspec.
19+
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK = "upload"
20+
21+
# Required if using a completion hook. The path to upload content to for example gs://my_bucket.
22+
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH = "gs://my_bucket"

instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/zero-code/.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
1212

1313
# Change to 'false' to hide prompt and completion content
1414
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
15+
16+
# Alternatively set this env var to enable the latest semantic conventions:
17+
OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental
18+
19+
# When using the latest experimental flag this env var controls which telemetry signals will have prompt and response content included in them.
20+
# Choices are NO_CONTENT, SPAN_ONLY, EVENT_ONLY, SPAN_AND_EVENT.
21+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT
22+
23+
# Optional hook that will upload prompt and response content to some external destination.
24+
# For example fsspec.
25+
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK = "upload"
26+
27+
# Required if using a completion hook. The path to upload content to for example gs://my_bucket.
28+
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH = "gs://my_bucket"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
"Programming Language :: Python :: 3.12",
2525
]
2626
dependencies = [
27-
"opentelemetry-api ~= 1.28",
27+
"opentelemetry-api >= 1.37",
2828
"opentelemetry-instrumentation ~= 0.58b0",
2929
# TODO https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3786: restrict
3030
# version after the first release

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
wrap_function_wrapper, # type: ignore[reportUnknownVariableType]
4848
)
4949

50-
from opentelemetry._events import get_event_logger
50+
from opentelemetry._logs import get_logger
5151
from opentelemetry.instrumentation._semconv import (
5252
_OpenTelemetrySemanticConventionStability,
5353
_OpenTelemetryStabilitySignalType,
@@ -60,6 +60,7 @@
6060
from opentelemetry.instrumentation.vertexai.utils import is_content_enabled
6161
from opentelemetry.semconv.schemas import Schemas
6262
from opentelemetry.trace import get_tracer
63+
from opentelemetry.util.genai.completion_hook import load_completion_hook
6364

6465

6566
def _methods_to_wrap(
@@ -109,6 +110,9 @@ def instrumentation_dependencies(self) -> Collection[str]:
109110

110111
def _instrument(self, **kwargs: Any):
111112
"""Enable VertexAI instrumentation."""
113+
completion_hook = (
114+
kwargs.get("completion_hook") or load_completion_hook()
115+
)
112116
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
113117
_OpenTelemetryStabilitySignalType.GEN_AI,
114118
)
@@ -124,12 +128,12 @@ def _instrument(self, **kwargs: Any):
124128
tracer_provider,
125129
schema_url=schema,
126130
)
127-
event_logger_provider = kwargs.get("event_logger_provider")
128-
event_logger = get_event_logger(
131+
logger_provider = kwargs.get("logger_provider")
132+
logger = get_logger(
129133
__name__,
130134
"",
135+
logger_provider=logger_provider,
131136
schema_url=schema,
132-
event_logger_provider=event_logger_provider,
133137
)
134138
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
135139
_OpenTelemetryStabilitySignalType.GEN_AI,
@@ -138,17 +142,19 @@ def _instrument(self, **kwargs: Any):
138142
# Type checker now knows sem_conv_opt_in_mode is a Literal[_StabilityMode.DEFAULT]
139143
method_wrappers = MethodWrappers(
140144
tracer,
141-
event_logger,
145+
logger,
142146
is_content_enabled(sem_conv_opt_in_mode),
143147
sem_conv_opt_in_mode,
148+
completion_hook,
144149
)
145150
elif sem_conv_opt_in_mode == _StabilityMode.GEN_AI_LATEST_EXPERIMENTAL:
146151
# Type checker now knows it's the other literal
147152
method_wrappers = MethodWrappers(
148153
tracer,
149-
event_logger,
154+
logger,
150155
is_content_enabled(sem_conv_opt_in_mode),
151156
sem_conv_opt_in_mode,
157+
completion_hook,
152158
)
153159
else:
154160
raise RuntimeError(f"{sem_conv_opt_in_mode} mode not supported")

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/events.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from dataclasses import asdict, dataclass
2828
from typing import Any, Iterable, Literal
2929

30-
from opentelemetry._events import Event
30+
from opentelemetry._logs import LogRecord
3131
from opentelemetry.semconv._incubating.attributes import gen_ai_attributes
3232
from opentelemetry.util.types import AnyValue
3333

@@ -36,7 +36,7 @@ def user_event(
3636
*,
3737
role: str = "user",
3838
content: AnyValue = None,
39-
) -> Event:
39+
) -> LogRecord:
4040
"""Creates a User event
4141
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#user-event
4242
"""
@@ -45,8 +45,8 @@ def user_event(
4545
}
4646
if content is not None:
4747
body["content"] = content
48-
return Event(
49-
name="gen_ai.user.message",
48+
return LogRecord(
49+
event_name="gen_ai.user.message",
5050
attributes={
5151
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
5252
},
@@ -58,7 +58,7 @@ def assistant_event(
5858
*,
5959
role: str = "assistant",
6060
content: AnyValue = None,
61-
) -> Event:
61+
) -> LogRecord:
6262
"""Creates an Assistant event
6363
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#assistant-event
6464
"""
@@ -67,8 +67,8 @@ def assistant_event(
6767
}
6868
if content is not None:
6969
body["content"] = content
70-
return Event(
71-
name="gen_ai.assistant.message",
70+
return LogRecord(
71+
event_name="gen_ai.assistant.message",
7272
attributes={
7373
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
7474
},
@@ -80,7 +80,7 @@ def system_event(
8080
*,
8181
role: str = "system",
8282
content: AnyValue = None,
83-
) -> Event:
83+
) -> LogRecord:
8484
"""Creates a System event
8585
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#system-event
8686
"""
@@ -89,8 +89,8 @@ def system_event(
8989
}
9090
if content is not None:
9191
body["content"] = content
92-
return Event(
93-
name="gen_ai.system.message",
92+
return LogRecord(
93+
event_name="gen_ai.system.message",
9494
attributes={
9595
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
9696
},
@@ -103,7 +103,7 @@ def tool_event(
103103
role: str | None,
104104
id_: str,
105105
content: AnyValue = None,
106-
) -> Event:
106+
) -> LogRecord:
107107
"""Creates a Tool message event
108108
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#event-gen_aitoolmessage
109109
"""
@@ -116,8 +116,8 @@ def tool_event(
116116
}
117117
if content is not None:
118118
body["content"] = content
119-
return Event(
120-
name="gen_ai.tool.message",
119+
return LogRecord(
120+
event_name="gen_ai.tool.message",
121121
attributes={
122122
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
123123
},
@@ -158,7 +158,7 @@ def choice_event(
158158
index: int,
159159
message: ChoiceMessage,
160160
tool_calls: Iterable[ChoiceToolCall] = (),
161-
) -> Event:
161+
) -> LogRecord:
162162
"""Creates a choice event, which describes the Gen AI response message.
163163
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#event-gen_aichoice
164164
"""
@@ -174,8 +174,8 @@ def choice_event(
174174
if tool_calls_list:
175175
body["tool_calls"] = tool_calls_list
176176

177-
return Event(
178-
name="gen_ai.choice",
177+
return LogRecord(
178+
event_name="gen_ai.choice",
179179
attributes={
180180
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
181181
},

0 commit comments

Comments
 (0)