Skip to content

Commit 04789cd

Browse files
Set OTEL_SERVICE_NAME at initialization (#112)
This PR sets `OTEL_SERVICE_NAME` at init-time, so we can leverage this across various platform.
1 parent 9a0ecb8 commit 04789cd

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

internal/cli/agent/frameworks/adk/python/templates/Dockerfile.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ COPY .python-version .python-version
1414

1515
RUN uv sync
1616

17+
ENV OTEL_SERVICE_NAME={{.Name}}
18+
1719
CMD ["{{.Name}}"]
1820

internal/cli/agent/frameworks/adk/python/templates/agent/agent.py.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import random
2+
import os
23

34
from google.adk import Agent
45
from google.adk.tools.tool_context import ToolContext
@@ -8,6 +9,9 @@ from google.adk.models.lite_llm import LiteLlm
89
from .mcp_tools import get_mcp_tools
910

1011
# Initialize OpenTelemetry
12+
# Set service name from environment variable for OpenTelemetry
13+
os.environ.setdefault('OTEL_SERVICE_NAME', '{{.Name}}')
14+
1115
from google.adk.telemetry.setup import maybe_set_otel_providers
1216
maybe_set_otel_providers()
1317

internal/cli/agent/frameworks/adk/python/templates/docker-compose.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ services:
2828
- KAGENT_NAME=placeholder
2929
- KAGENT_NAMESPACE=placeholder
3030
- AGENT_NAME={{.Name}}
31+
- OTEL_SERVICE_NAME={{.Name}}
3132
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}
3233
- MODEL_PROVIDER={{.ModelProvider}}
3334
- MODEL_NAME={{.ModelName}}

internal/cli/mcp/frameworks/python/templates/Dockerfile.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
6565
# Set environment variables
6666
ENV PYTHONPATH=/app
6767
ENV PYTHONUNBUFFERED=1
68+
ENV OTEL_SERVICE_NAME={{.Name}}
6869
6970
# Default command
70-
CMD ["python", "src/main.py"]
71+
CMD ["python", "src/main.py"]

0 commit comments

Comments
 (0)