@@ -163,11 +163,11 @@ def test_start_model_invoke_span(mock_tracer):
163163 assert span is not None
164164
165165
166- def test_start_model_invoke_span_latest_conventions (mock_tracer ):
166+ def test_start_model_invoke_span_latest_conventions (mock_tracer , monkeypatch ):
167167 """Test starting a model invoke span with the latest semantic conventions."""
168168 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
169+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
169170 tracer = Tracer ()
170- tracer .use_latest_genai_conventions = True
171171 tracer .tracer = mock_tracer
172172
173173 mock_span = mock .MagicMock ()
@@ -244,11 +244,11 @@ def test_end_model_invoke_span(mock_span):
244244 mock_span .end .assert_called_once ()
245245
246246
247- def test_end_model_invoke_span_latest_conventions (mock_span ):
247+ def test_end_model_invoke_span_latest_conventions (mock_span , monkeypatch ):
248248 """Test ending a model invoke span with the latest semantic conventions."""
249249 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
250+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
250251 tracer = Tracer ()
251- tracer .use_latest_genai_conventions = True
252252 message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
253253 usage = Usage (inputTokens = 10 , outputTokens = 20 , totalTokens = 30 )
254254 metrics = Metrics (latencyMs = 20 , timeToFirstByteMs = 10 )
@@ -307,11 +307,11 @@ def test_start_tool_call_span(mock_tracer):
307307 assert span is not None
308308
309309
310- def test_start_tool_call_span_latest_conventions (mock_tracer ):
310+ def test_start_tool_call_span_latest_conventions (mock_tracer , monkeypatch ):
311311 """Test starting a tool call span with the latest semantic conventions."""
312312 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
313+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
313314 tracer = Tracer ()
314- tracer .use_latest_genai_conventions = True
315315 tracer .tracer = mock_tracer
316316
317317 mock_span = mock .MagicMock ()
@@ -396,11 +396,11 @@ def test_start_swarm_span_with_contentblock_task(mock_tracer):
396396 assert span is not None
397397
398398
399- def test_start_swarm_span_with_contentblock_task_latest_conventions (mock_tracer ):
399+ def test_start_swarm_span_with_contentblock_task_latest_conventions (mock_tracer , monkeypatch ):
400400 """Test starting a swarm call span with task as list of contentBlock with latest semantic conventions."""
401401 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
402+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
402403 tracer = Tracer ()
403- tracer .use_latest_genai_conventions = True
404404 tracer .tracer = mock_tracer
405405
406406 mock_span = mock .MagicMock ()
@@ -439,10 +439,10 @@ def test_end_swarm_span(mock_span):
439439 )
440440
441441
442- def test_end_swarm_span_latest_conventions (mock_span ):
442+ def test_end_swarm_span_latest_conventions (mock_span , monkeypatch ):
443443 """Test ending a tool call span with latest semantic conventions."""
444+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
444445 tracer = Tracer ()
445- tracer .use_latest_genai_conventions = True
446446 swarm_final_reuslt = "foo bar bar"
447447
448448 tracer .end_swarm_span (mock_span , swarm_final_reuslt )
@@ -503,10 +503,10 @@ def test_end_tool_call_span(mock_span):
503503 mock_span .end .assert_called_once ()
504504
505505
506- def test_end_tool_call_span_latest_conventions (mock_span ):
506+ def test_end_tool_call_span_latest_conventions (mock_span , monkeypatch ):
507507 """Test ending a tool call span with the latest semantic conventions."""
508+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
508509 tracer = Tracer ()
509- tracer .use_latest_genai_conventions = True
510510 tool_result = {"status" : "success" , "content" : [{"text" : "Tool result" }, {"json" : {"foo" : "bar" }}]}
511511
512512 tracer .end_tool_call_span (mock_span , tool_result )
@@ -558,11 +558,11 @@ def test_start_event_loop_cycle_span(mock_tracer):
558558 assert span is not None
559559
560560
561- def test_start_event_loop_cycle_span_latest_conventions (mock_tracer ):
561+ def test_start_event_loop_cycle_span_latest_conventions (mock_tracer , monkeypatch ):
562562 """Test starting an event loop cycle span with the latest semantic conventions."""
563563 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
564+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
564565 tracer = Tracer ()
565- tracer .use_latest_genai_conventions = True
566566 tracer .tracer = mock_tracer
567567
568568 mock_span = mock .MagicMock ()
@@ -609,10 +609,10 @@ def test_end_event_loop_cycle_span(mock_span):
609609 mock_span .end .assert_called_once ()
610610
611611
612- def test_end_event_loop_cycle_span_latest_conventions (mock_span ):
612+ def test_end_event_loop_cycle_span_latest_conventions (mock_span , monkeypatch ):
613613 """Test ending an event loop cycle span with the latest semantic conventions."""
614+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
614615 tracer = Tracer ()
615- tracer .use_latest_genai_conventions = True
616616 message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
617617 tool_result_message = {
618618 "role" : "assistant" ,
@@ -679,11 +679,11 @@ def test_start_agent_span(mock_tracer):
679679 assert span is not None
680680
681681
682- def test_start_agent_span_latest_conventions (mock_tracer ):
682+ def test_start_agent_span_latest_conventions (mock_tracer , monkeypatch ):
683683 """Test starting an agent span with the latest semantic conventions."""
684684 with mock .patch ("strands.telemetry.tracer.trace_api.get_tracer" , return_value = mock_tracer ):
685+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
685686 tracer = Tracer ()
686- tracer .use_latest_genai_conventions = True
687687 tracer .tracer = mock_tracer
688688
689689 mock_span = mock .MagicMock ()
@@ -749,10 +749,10 @@ def test_end_agent_span(mock_span):
749749 mock_span .end .assert_called_once ()
750750
751751
752- def test_end_agent_span_latest_conventions (mock_span ):
752+ def test_end_agent_span_latest_conventions (mock_span , monkeypatch ):
753753 """Test ending an agent span with the latest semantic conventions."""
754+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_latest_experimental" )
754755 tracer = Tracer ()
755- tracer .use_latest_genai_conventions = True
756756
757757 # Mock AgentResult with metrics
758758 mock_metrics = mock .MagicMock ()
@@ -1329,7 +1329,6 @@ def test_start_event_loop_cycle_span_with_tool_result_message(mock_tracer):
13291329def test_start_agent_span_does_not_include_tool_definitions_by_default ():
13301330 """Verify that start_agent_span does not include tool definitions by default."""
13311331 tracer = Tracer ()
1332- tracer .include_tool_definitions = False
13331332 tracer ._start_span = mock .MagicMock ()
13341333
13351334 tools_config = {
@@ -1349,10 +1348,10 @@ def test_start_agent_span_does_not_include_tool_definitions_by_default():
13491348 assert "gen_ai.tool.definitions" not in attributes
13501349
13511350
1352- def test_start_agent_span_includes_tool_definitions_when_enabled ():
1351+ def test_start_agent_span_includes_tool_definitions_when_enabled (monkeypatch ):
13531352 """Verify that start_agent_span includes tool definitions when enabled."""
1353+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_tool_definitions" )
13541354 tracer = Tracer ()
1355- tracer .include_tool_definitions = True
13561355 tracer ._start_span = mock .MagicMock ()
13571356
13581357 tools_config = {
0 commit comments