Skip to content

Commit f60c609

Browse files
authored
Merge branch 'main' into feature/chroma-memory-service
2 parents fb3b5a7 + a08bf62 commit f60c609

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/google/adk/telemetry/tracing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_USAGE_INPUT_TOKENS
5353
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_USAGE_OUTPUT_TOKENS
5454
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GenAiSystemValues
55+
from opentelemetry.semconv._incubating.attributes.user_attributes import USER_ID
5556
from opentelemetry.semconv.schemas import Schemas
5657
from opentelemetry.trace import Span
5758
from opentelemetry.util.types import AnyValue
@@ -438,8 +439,11 @@ def use_generate_content_span(
438439
"""
439440

440441
common_attributes = {
442+
GEN_AI_AGENT_NAME: invocation_context.agent.name,
441443
GEN_AI_CONVERSATION_ID: invocation_context.session.id,
444+
USER_ID: invocation_context.session.user_id,
442445
'gcp.vertex.agent.event_id': model_response_event.id,
446+
'gcp.vertex.agent.invocation_id': invocation_context.invocation_id,
443447
}
444448
if (
445449
_is_gemini_agent(invocation_context.agent)

tests/unittests/telemetry/test_spans.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
from google.adk.tools.base_tool import BaseTool
3535
from google.genai import types
3636
from opentelemetry._logs import LogRecord
37+
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_AGENT_NAME
3738
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_CONVERSATION_ID
3839
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_OPERATION_NAME
3940
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_REQUEST_MODEL
4041
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_RESPONSE_FINISH_REASONS
4142
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_SYSTEM
4243
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_USAGE_INPUT_TOKENS
4344
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_USAGE_OUTPUT_TOKENS
45+
from opentelemetry.semconv._incubating.attributes.user_attributes import USER_ID
4446
import pytest
4547

4648

@@ -709,8 +711,11 @@ async def test_generate_content_span(
709711
mock_span.set_attribute.assert_any_call(GEN_AI_USAGE_OUTPUT_TOKENS, 20)
710712

711713
mock_span.set_attributes.assert_called_once_with({
714+
GEN_AI_AGENT_NAME: invocation_context.agent.name,
712715
GEN_AI_CONVERSATION_ID: invocation_context.session.id,
716+
USER_ID: invocation_context.session.user_id,
713717
'gcp.vertex.agent.event_id': 'event-123',
718+
'gcp.vertex.agent.invocation_id': invocation_context.invocation_id,
714719
})
715720

716721
# Assert Logs

0 commit comments

Comments
 (0)