Skip to content

Commit 37abcef

Browse files
committed
fix(plugins): remove dead BigQuery analytics tracer
Remove the unused plugin tracer so analytics stack bookkeeping cannot create plugin-owned OpenTelemetry spans beside the framework spans. Keep existing trace tests compatible with the intentionally absent module tracer. Fixes google#5889
1 parent 8dcc72f commit 37abcef

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

‎src/google/adk/plugins/bigquery_agent_analytics_plugin.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@
9999
from ..events.event import Event
100100

101101
logger: logging.Logger = logging.getLogger("google_adk." + __name__)
102-
tracer = trace.get_tracer(
103-
"google.adk.plugins.bigquery_agent_analytics", __version__
104-
)
105102

106103
# Bumped when the schema changes (1 → 2 → 3 …). Used as a table
107104
# label for governance and to decide whether auto-upgrade should run.

‎tests/unittests/plugins/test_bigquery_agent_analytics_plugin.py‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,7 @@ async def test_push_pop_does_not_call_tracer_start_span(
29322932
with mock.patch(
29332933
"google.adk.plugins.bigquery_agent_analytics_plugin.tracer",
29342934
mock_tracer,
2935+
create=True,
29352936
):
29362937
span_id = bigquery_agent_analytics_plugin.TraceManager.push_span(
29372938
callback_context, "test_span"
@@ -2978,6 +2979,7 @@ async def test_push_pop_does_not_export_spans_through_real_provider(
29782979
with mock.patch(
29792980
"google.adk.plugins.bigquery_agent_analytics_plugin.tracer",
29802981
real_tracer,
2982+
create=True,
29812983
):
29822984
span_id = bigquery_agent_analytics_plugin.TraceManager.push_span(
29832985
callback_context, "test_span"
@@ -4293,7 +4295,7 @@ def test_plugin_stack_wins_over_ambient_root_span(self, callback_context):
42934295
# Seed the plugin stack with a span.
42944296
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
42954297
with mock.patch.object(
4296-
bigquery_agent_analytics_plugin, "tracer", real_tracer
4298+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
42974299
):
42984300
bigquery_agent_analytics_plugin.TraceManager.push_span(
42994301
callback_context, "plugin-child"
@@ -6967,7 +6969,7 @@ async def test_trace_id_continuity_no_ambient_span(self, callback_context):
69676969
real_tracer = provider.get_tracer("test-plugin")
69686970

69696971
with mock.patch.object(
6970-
bigquery_agent_analytics_plugin, "tracer", real_tracer
6972+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
69716973
):
69726974
# Reset the span records contextvar for a clean invocation.
69736975
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7021,7 +7023,7 @@ async def test_invocation_completed_trace_continuity_no_ambient(
70217023
real_tracer = provider.get_tracer("test-plugin")
70227024

70237025
with mock.patch.object(
7024-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7026+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
70257027
):
70267028
# Reset for a clean invocation; no ambient span.
70277029
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7081,7 +7083,7 @@ async def test_callbacks_emit_same_trace_id_no_ambient(
70817083
real_tracer = provider.get_tracer("test-plugin")
70827084

70837085
with mock.patch.object(
7084-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7086+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
70857087
):
70867088
# Reset span records for a clean invocation.
70877089
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7141,7 +7143,7 @@ async def test_trace_id_continuity_with_ambient_span(self, callback_context):
71417143
real_tracer = provider.get_tracer("test")
71427144

71437145
with mock.patch.object(
7144-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7146+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
71457147
):
71467148
# Reset the span records contextvar.
71477149
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7184,7 +7186,7 @@ async def test_invocation_root_span_isolated_across_turns(
71847186
real_tracer = provider.get_tracer("test")
71857187

71867188
with mock.patch.object(
7187-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7189+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
71887190
):
71897191
# --- Turn 1 ---
71907192
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7249,7 +7251,7 @@ async def test_starting_completed_same_span_with_ambient(
72497251
real_tracer = provider.get_tracer("test")
72507252

72517253
with mock.patch.object(
7252-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7254+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
72537255
):
72547256
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
72557257

@@ -7315,7 +7317,7 @@ async def test_starting_completed_use_plugin_span_without_ambient(
73157317
real_tracer = provider.get_tracer("test")
73167318

73177319
with mock.patch.object(
7318-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7320+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
73197321
):
73207322
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
73217323

@@ -7379,7 +7381,7 @@ async def test_tool_error_captures_span_id(
73797381
)
73807382

73817383
with mock.patch.object(
7382-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7384+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
73837385
):
73847386
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
73857387

@@ -7444,7 +7446,7 @@ def test_ensure_invocation_span_clears_stale_records(self, callback_context):
74447446
real_tracer = provider.get_tracer("test")
74457447

74467448
with mock.patch.object(
7447-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7449+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
74487450
):
74497451
# Simulate stale records from incomplete previous invocation.
74507452
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7494,7 +7496,7 @@ def test_clear_stack_does_not_export_spans(self, callback_context):
74947496
real_tracer = provider.get_tracer("test")
74957497

74967498
with mock.patch.object(
7497-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7499+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
74987500
):
74997501
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
75007502
TM.push_span(callback_context, "span-a")
@@ -7542,7 +7544,7 @@ async def test_after_run_callback_clears_remaining_stack(
75427544
real_tracer = provider.get_tracer("test")
75437545

75447546
with mock.patch.object(
7545-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7547+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
75467548
):
75477549
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
75487550

@@ -7593,7 +7595,7 @@ async def test_next_invocation_clean_after_incomplete_previous(
75937595
real_tracer = provider.get_tracer("test")
75947596

75957597
with mock.patch.object(
7596-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7598+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
75977599
):
75987600
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
75997601
bigquery_agent_analytics_plugin._active_invocation_id_ctx.set(None)
@@ -7645,7 +7647,7 @@ def test_ensure_invocation_span_idempotent_same_invocation(
76457647
real_tracer = provider.get_tracer("test")
76467648

76477649
with mock.patch.object(
7648-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7650+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
76497651
):
76507652
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
76517653
bigquery_agent_analytics_plugin._active_invocation_id_ctx.set(None)
@@ -7697,7 +7699,7 @@ async def test_user_message_then_before_run_same_trace_no_ambient(
76977699
real_tracer = provider.get_tracer("test")
76987700

76997701
with mock.patch.object(
7700-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7702+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
77017703
):
77027704
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
77037705
bigquery_agent_analytics_plugin._active_invocation_id_ctx.set(None)
@@ -7793,7 +7795,7 @@ def _make_inv_ctx(agent_name, inv_id):
77937795
)
77947796

77957797
with mock.patch.object(
7796-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7798+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
77977799
):
77987800
# --- Invocation 1: root agent = "RootA" ---
77997801
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
@@ -7879,7 +7881,7 @@ async def test_cleanup_runs_when_log_event_raises(
78797881
real_tracer = provider.get_tracer("test")
78807882

78817883
with mock.patch.object(
7882-
bigquery_agent_analytics_plugin, "tracer", real_tracer
7884+
bigquery_agent_analytics_plugin, "tracer", real_tracer, create=True
78837885
):
78847886
bigquery_agent_analytics_plugin._span_records_ctx.set(None)
78857887
bigquery_agent_analytics_plugin._active_invocation_id_ctx.set(None)

0 commit comments

Comments
 (0)