Skip to content

Commit 84bbb35

Browse files
RKestcopybara-github
authored andcommitted
feat(telemetry): introduce ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN
Add the ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN env var (1|2) and a resolver that defaults to 2 on Agent Engine (presence of GOOGLE_CLOUD_AGENT_ENGINE_ID) and 1 otherwise. No span/metric behavior changes yet; the resolver is wired into emission in a follow-up revision. Duplicate every telemetry functional test case across both schema versions so the upcoming v2 behavior change can be asserted incrementally. Co-authored-by: Max Ind <maxind@google.com> PiperOrigin-RevId: 939829200
1 parent 7e9345b commit 84bbb35

4 files changed

Lines changed: 2702 additions & 51 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Opt-in for the ADK telemetry schema version.
16+
17+
``ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN`` lets a deployment pin which version of
18+
the ADK telemetry format (span names, span/log attributes, metrics) it emits.
19+
20+
Why this exists:
21+
22+
* **Staged migration.** Telemetry format changes are breaking for anyone who
23+
built dashboards/alerts on the previous shape. The version env lets users
24+
fall back to the legacy format if they rely on it, and migrate on their own
25+
schedule.
26+
* **Fast iteration on managed services.** GCP-managed runtimes (e.g. Agent
27+
Runtime / Vertex Agent Engine) can pin themselves to the latest version and
28+
iterate quickly, decoupled from the broader user base.
29+
* **Eventually removable.** Ideally this knob is phased out once ADK is
30+
({almost,} fully) OTel semconv compliant, after which we no longer expect
31+
breaking telemetry changes.
32+
33+
Default resolution:
34+
35+
* ``2`` on Agent Engine, detected via the presence of the
36+
``GOOGLE_CLOUD_AGENT_ENGINE_ID`` env var.
37+
* ``1`` everywhere else.
38+
39+
Migration plan (steps land incrementally; this comment should be kept in sync
40+
as each one ships):
41+
42+
1. The ``invocation`` span is updated to the ``invoke_workflow`` span.
43+
2. The ``call_llm`` span is removed.
44+
3. The ``execute_tool`` content-bearing attributes become OTel semconv aligned.
45+
4. The experimental OTel GenAI semconv becomes the default in both
46+
``opentelemetry-instrumentation-google-genai`` and ADK's native
47+
instrumentation.
48+
5. ``2`` becomes the global default (this knob flips).
49+
6. After ~6 months, the env var is phased out entirely, along with support for
50+
the LEGACY schema.
51+
"""
52+
53+
from __future__ import annotations
54+
55+
import os
56+
57+
# Env var users set to pin the ADK telemetry schema version ("1" or "2").
58+
ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN = "ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN"
59+
60+
# Presence of this env var indicates the process runs on Vertex Agent Engine.
61+
GOOGLE_CLOUD_AGENT_ENGINE_ID = "GOOGLE_CLOUD_AGENT_ENGINE_ID"
62+
63+
# Legacy telemetry format: top-level ``invocation`` span, no entrypoint
64+
# ``invoke_workflow`` span/metric.
65+
SCHEMA_VERSION_LEGACY = 1
66+
67+
# OTel-semconv-aligned telemetry format: the ``invocation`` span is replaced by
68+
# an entrypoint ``invoke_workflow {entrypoint}`` span + duration metric.
69+
SCHEMA_VERSION_SEMCONV_ALIGNED = 2
70+
71+
72+
def resolve_schema_version() -> int:
73+
"""Resolves the active ADK telemetry schema version.
74+
75+
Precedence: ``ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN`` (if set to a recognized
76+
value) > ``2`` on Agent Engine > ``1``.
77+
78+
Returns:
79+
Either :data:`SCHEMA_VERSION_LEGACY` or
80+
:data:`SCHEMA_VERSION_SEMCONV_ALIGNED`.
81+
"""
82+
opt_in = os.environ.get(ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN, "").strip()
83+
if opt_in == "1":
84+
return SCHEMA_VERSION_LEGACY
85+
if opt_in == "2":
86+
return SCHEMA_VERSION_SEMCONV_ALIGNED
87+
88+
# Unset/unrecognized: default to v2 on Agent Engine, v1 elsewhere.
89+
if os.environ.get(GOOGLE_CLOUD_AGENT_ENGINE_ID):
90+
return SCHEMA_VERSION_SEMCONV_ALIGNED
91+
return SCHEMA_VERSION_LEGACY

0 commit comments

Comments
 (0)