Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/cli/test_generated_agent_backend_codegen_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"agents/__init__.py": "a6449a6cac3bfda8b834ea39ea95ca2f8d0471ac480e1e876313d7398eea59ba",
"agents/demo_agent/agent.py": "3c28f3e63f185d1ee8402d58b62c8654cf18fe4180a1f348abaa63547d91446c",
"agents/demo_agent/__init__.py": "ba3abbb199bbae74dc75151a44ba53a557e5f47d509835950ca756346c5a9582",
"agents/demo_agent/dynamic_a2a.py": "d8f1854d78267a9a1a8a568881a7630cd1ae98cb8fc2a736d432576b31415ec5",
"agents/demo_agent/dynamic_a2a.py": "7787b2dcc17e0903cf7351bf7171fda439f91ddde716f47f9e8cd53e6949b5ef",
".env.example": "ec3258da9bef4e74333376d8554c265ccb12a4a1e5d4e1e1b0acdf5c9ae93ab6",
"requirements.txt": "9f55ba1a16ae8199165fde7de39f5f93133963634ebb6d1bdb241cc3cefa10ee",
"README.md": "a34208314cf9061c02662028d7a9dd97448e6b73c1d732cb4aeaa8f70dbbc684",
Expand All @@ -87,7 +87,7 @@
"agents/__init__.py": "a6449a6cac3bfda8b834ea39ea95ca2f8d0471ac480e1e876313d7398eea59ba",
"agents/full_agent/agent.py": "35560cfa5ea93955244482d727c8f8369599fa5b9560ba1f3804df7273e245ce",
"agents/full_agent/__init__.py": "ba3abbb199bbae74dc75151a44ba53a557e5f47d509835950ca756346c5a9582",
"agents/full_agent/dynamic_a2a.py": "d8f1854d78267a9a1a8a568881a7630cd1ae98cb8fc2a736d432576b31415ec5",
"agents/full_agent/dynamic_a2a.py": "7787b2dcc17e0903cf7351bf7171fda439f91ddde716f47f9e8cd53e6949b5ef",
".env.example": "2bfd3afda4e661fbb71588ec5f0d584ce6682363cacc81b0394f8da09f7977e8",
"requirements.txt": "3372cfe49df006b3d0e5bdc4f7b4fcc152a16f663d9e10770f09c708e6daa32b",
"README.md": "1bf4dc889c7d1076f50784d253b53412ba7c49bcb69a5d948f9092dbbecb18ac",
Expand Down Expand Up @@ -2443,6 +2443,8 @@ def test_generated_agent_always_enables_per_invocation_metadata() -> None:
in files["agents/demo_agent/dynamic_a2a.py"]
)
dynamic_source = files["agents/demo_agent/dynamic_a2a.py"]
assert "from google.adk.agents.run_config import StreamingMode" in dynamic_source
assert "google.adk.agents._streaming_mode" not in dynamic_source
assert "class _SsePayloadEventIdRewriter" in dynamic_source
assert "event_id_rewriter.prepare(" in dynamic_source
assert ":veid:" in dynamic_source
Expand Down
18 changes: 16 additions & 2 deletions tests/test_adk_tracing_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
from pathlib import Path

import pytest
from google.adk.agents._streaming_mode import StreamingMode
from google.adk.agents.run_config import RunConfig
from google.adk.agents.run_config import RunConfig, StreamingMode
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.runners import InMemoryRunner
from google.genai import types
from opentelemetry import context as context_api
from opentelemetry import trace as trace_api
from opentelemetry.context import set_value
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._once import Once

from veadk import Agent
from veadk.config import settings
from veadk.tracing.telemetry.telemetry import set_common_attributes_on_tool_span
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
from veadk.utils.patches import patch_tracer

Expand Down Expand Up @@ -97,6 +98,19 @@ def _runner(model, tracer, tools=()):
return InMemoryRunner(agent=agent, app_name="tracing-test")


def test_tool_span_common_attributes_ignore_non_recording_parent_span():
context = trace_api.SpanContext(trace_id=1, span_id=1, is_remote=False)
parent = trace_api.NonRecordingSpan(context)
current = trace_api.NonRecordingSpan(context)
token = context_api.attach(
set_value("invocation_span_instance", parent, context=context_api.get_current())
)
try:
set_common_attributes_on_tool_span(current)
finally:
context_api.detach(token)


async def _run(runner, session_id, stream=False):
await runner.session_service.create_session(
app_name=runner.app_name, user_id="test-user", session_id=session_id
Expand Down
2 changes: 1 addition & 1 deletion veadk/cli/generated_agent_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,8 +1751,8 @@ def _render_dynamic_a2a_py() -> str:
from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.responses import StreamingResponse
from google.adk.agents import RunConfig
from google.adk.agents._streaming_mode import StreamingMode
from google.adk.agents.base_agent import BaseAgent
from google.adk.agents.run_config import StreamingMode
from google.adk.apps.app import App
from google.adk.cli.adk_web_server import RunAgentRequest
from google.adk.runners import Runner as AdkRunner
Expand Down
2 changes: 1 addition & 1 deletion veadk/cloud/harness_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
from fastapi import FastAPI, HTTPException, Query, Request
from fastapi.responses import StreamingResponse
from google.adk.agents import RunConfig
from google.adk.agents._streaming_mode import StreamingMode
from google.adk.agents.base_agent import BaseAgent
from google.adk.agents.run_config import StreamingMode
from google.adk.artifacts.in_memory_artifact_service import InMemoryArtifactService
from google.adk.auth.credential_service.in_memory_credential_service import (
InMemoryCredentialService,
Expand Down
2 changes: 1 addition & 1 deletion veadk/integrations/agentkit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
from fastapi.responses import FileResponse, StreamingResponse
from fastapi.staticfiles import StaticFiles
from google.adk.agents import LoopAgent, ParallelAgent, RunConfig, SequentialAgent
from google.adk.agents._streaming_mode import StreamingMode
from google.adk.agents.base_agent import BaseAgent
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
from google.adk.agents.run_config import StreamingMode
from google.adk.apps.app import App
from google.adk.cli.api_server import RunAgentRequest
from google.adk.runners import Runner as AdkRunner
Expand Down
9 changes: 7 additions & 2 deletions veadk/runtime/deepseek_harness/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
)
from veadk.consts import DEFAULT_MODEL_AGENT_NAME
from veadk.utils.logger import get_logger
from veadk.version import VERSION

if TYPE_CHECKING:
from google.adk.agents.invocation_context import InvocationContext
Expand Down Expand Up @@ -650,9 +651,13 @@ def _dsh_session_id(agent: Agent, ctx: InvocationContext) -> str:
def _start_call_llm_span() -> Span | None:
"""Open the ADK-shaped ``call_llm`` span for one DSH invocation."""
try:
from google.adk.telemetry.tracing import tracer
from opentelemetry import trace

return tracer.start_span("call_llm")
return trace.get_tracer(
instrumenting_module_name="veadk",
instrumenting_library_version=VERSION,
schema_url="https://opentelemetry.io/schemas/1.37.0",
).start_span("call_llm")
except Exception: # noqa: BLE001
logger.warning("deepseek_harness_trace_span_start_failed")
return None
Expand Down
9 changes: 5 additions & 4 deletions veadk/tracing/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,16 @@ def set_common_attributes_on_tool_span(current_span: _Span) -> None:
common_attributes = ATTRIBUTES.get("common", {})

invocation_span: Span = get_value("invocation_span_instance") # type: ignore
invocation_span_name = getattr(invocation_span, "name", "")
invocation_span_attributes = getattr(invocation_span, "attributes", None) or {}

for attr_name in common_attributes.keys():
if (
invocation_span
and invocation_span.name.startswith(("invocation", "invoke_workflow"))
and invocation_span.attributes
and attr_name in invocation_span.attributes
and invocation_span_name.startswith(("invocation", "invoke_workflow"))
and attr_name in invocation_span_attributes
):
current_span.set_attribute(attr_name, invocation_span.attributes[attr_name])
current_span.set_attribute(attr_name, invocation_span_attributes[attr_name])


def trace_tool_call(
Expand Down
Loading