Skip to content

Commit 7e139ac

Browse files
committed
More changes
1 parent 6c57132 commit 7e139ac

File tree

1 file changed

+16
-10
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
request_to_events,
4242
response_to_events,
4343
)
44+
from opentelemetry.semconv._incubating.attributes import (
45+
gen_ai_attributes as GenAI,
46+
)
4447
from opentelemetry.trace import SpanKind, Tracer
4548
from opentelemetry.util.genai.types import ContentCapturingMode
4649

@@ -147,32 +150,35 @@ def _with_new_instrumentation(
147150
):
148151
params = _extract_params(*args, **kwargs)
149152
api_endpoint: str = instance.api_endpoint # type: ignore[reportUnknownMemberType]
150-
span_attributes = {
151-
**get_genai_request_attributes(False, params),
152-
**get_server_attributes(api_endpoint),
153-
}
154-
155-
span_name = get_span_name(span_attributes)
156-
153+
request_attributes = get_genai_request_attributes(True, params)
154+
server_attributes = get_server_attributes(api_endpoint)
157155
with self.tracer.start_as_current_span(
158-
name=span_name,
156+
name=f"{GenAI.GenAiOperationNameValues.CHAT.value} {request_attributes.get(GenAI.GEN_AI_REQUEST_MODEL, '')}",
159157
kind=SpanKind.CLIENT,
160-
attributes=span_attributes,
161158
) as span:
162159

163160
def handle_response(
164161
response: prediction_service.GenerateContentResponse
165162
| prediction_service_v1beta1.GenerateContentResponse
166163
| None,
167164
) -> None:
165+
response_attributes = (
166+
{}
167+
if not response
168+
else get_genai_response_attributes(response)
169+
)
168170
if span.is_recording() and response:
169171
# When streaming, this is called multiple times so attributes would be
170172
# overwritten. In practice, it looks the API only returns the interesting
171173
# attributes on the last streamed response. However, I couldn't find
172174
# documentation for this and setting attributes shouldn't be too expensive.
173175
span.set_attributes(
174-
get_genai_response_attributes(response)
176+
**response_attributes,
177+
**server_attributes,
178+
**request_attributes,
175179
)
180+
# event = Event(name="gen_ai.client.inference.operation.details")
181+
176182
self.event_logger.emit(
177183
create_operation_details_event(
178184
api_endpoint=api_endpoint,

0 commit comments

Comments
 (0)