Skip to content

Commit 6f7aa72

Browse files
committed
Address comments
1 parent 375e33c commit 6f7aa72

File tree

7 files changed

+1196
-625
lines changed

7 files changed

+1196
-625
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def _extract_params(
9898
)
9999

100100

101+
# For details about GEN_AI_LATEST_EXPERIMENTAL stabilty mode see
102+
# https://github.com/open-telemetry/semantic-conventions/blob/v1.37.0/docs/gen-ai/gen-ai-agent-spans.md?plain=1#L18-L37
101103
class MethodWrappers:
102104
@overload
103105
def __init__(

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/conftest.py

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,16 @@ def vertexai_init(vcr: VCR) -> None:
115115
)
116116

117117

118-
@pytest.fixture(
119-
params=[True, False],
120-
ids=["newStyleInstrumentation", "oldStyleInstrumentation"],
121-
)
118+
@pytest.fixture(scope="function")
122119
def instrument_no_content(
123120
tracer_provider, event_logger_provider, meter_provider, request
124121
):
125122
# Reset global state..
126123
_OpenTelemetrySemanticConventionStability._initialized = False
127-
if request.param:
128-
os.environ.update(
129-
{OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental"}
130-
)
131-
os.environ.update(
132-
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "NO_CONTENT"}
133-
)
134-
else:
135-
os.environ.update({OTEL_SEMCONV_STABILITY_OPT_IN: "stable"})
136-
os.environ.update(
137-
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "False"}
138-
)
124+
os.environ.update({OTEL_SEMCONV_STABILITY_OPT_IN: "stable"})
125+
os.environ.update(
126+
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "False"}
127+
)
139128

140129
instrumentor = VertexAIInstrumentor()
141130
instrumentor.instrument(
@@ -150,29 +139,67 @@ def instrument_no_content(
150139
instrumentor.uninstrument()
151140

152141

153-
@pytest.fixture(
154-
params=[True, False],
155-
ids=["newStyleInstrumentation", "oldStyleInstrumentation"],
156-
)
142+
@pytest.fixture(scope="function")
143+
def instrument_no_content_with_experimental_semconvs(
144+
tracer_provider, event_logger_provider, meter_provider, request
145+
):
146+
# Reset global state..
147+
_OpenTelemetrySemanticConventionStability._initialized = False
148+
os.environ.update(
149+
{OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental"}
150+
)
151+
os.environ.update(
152+
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "NO_CONTENT"}
153+
)
154+
155+
instrumentor = VertexAIInstrumentor()
156+
instrumentor.instrument(
157+
tracer_provider=tracer_provider,
158+
event_logger_provider=event_logger_provider,
159+
meter_provider=meter_provider,
160+
)
161+
162+
yield instrumentor
163+
os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None)
164+
if instrumentor.is_instrumented_by_opentelemetry:
165+
instrumentor.uninstrument()
166+
167+
168+
@pytest.fixture(scope="function")
169+
def instrument_with_experimental_semconvs(
170+
tracer_provider, event_logger_provider, meter_provider
171+
):
172+
# Reset global state..
173+
_OpenTelemetrySemanticConventionStability._initialized = False
174+
os.environ.update(
175+
{OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental"}
176+
)
177+
os.environ.update(
178+
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "SPAN_AND_EVENT"}
179+
)
180+
instrumentor = VertexAIInstrumentor()
181+
instrumentor.instrument(
182+
tracer_provider=tracer_provider,
183+
event_logger_provider=event_logger_provider,
184+
meter_provider=meter_provider,
185+
)
186+
187+
yield instrumentor
188+
os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None)
189+
if instrumentor.is_instrumented_by_opentelemetry:
190+
instrumentor.uninstrument()
191+
192+
193+
@pytest.fixture(scope="function")
157194
def instrument_with_content(
158195
tracer_provider, event_logger_provider, meter_provider, request
159196
):
160197
# Reset global state..
161198
_OpenTelemetrySemanticConventionStability._initialized = False
162-
if request.param:
163-
os.environ.update(
164-
{OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental"}
165-
)
166-
os.environ.update(
167-
{
168-
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "SPAN_AND_EVENT"
169-
}
170-
)
171-
else:
172-
os.environ.update({OTEL_SEMCONV_STABILITY_OPT_IN: "stable"})
173-
os.environ.update(
174-
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"}
175-
)
199+
os.environ.update({OTEL_SEMCONV_STABILITY_OPT_IN: "stable"})
200+
os.environ.update(
201+
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"}
202+
)
176203
instrumentor = VertexAIInstrumentor()
177204
instrumentor.instrument(
178205
tracer_provider=tracer_provider,

0 commit comments

Comments
 (0)