@@ -531,6 +531,33 @@ def test_initialize_tracer_with_invalid_otlp_endpoint(
531
531
mock_set_tracer_provider .assert_called_once_with (mock_tracer_provider .return_value )
532
532
533
533
534
+ def test_initialize_tracer_with_missing_module (
535
+ mock_is_initialized , mock_tracer_provider , mock_set_tracer_provider , mock_resource
536
+ ):
537
+ """Test initializing the tracer when the OTLP exporter module is missing."""
538
+ mock_is_initialized .return_value = False
539
+
540
+ mock_resource_instance = mock .MagicMock ()
541
+ mock_resource .create .return_value = mock_resource_instance
542
+
543
+ # Initialize Tracer with OTLP endpoint but missing module
544
+ with (
545
+ mock .patch ("strands.telemetry.tracer.HAS_OTEL_EXPORTER_MODULE" , False ),
546
+ pytest .raises (ModuleNotFoundError ) as excinfo ,
547
+ ):
548
+ Tracer (otlp_endpoint = "http://test-endpoint" )
549
+
550
+ # Verify the error message
551
+ assert "opentelemetry-exporter-otlp-proto-http not detected" in str (excinfo .value )
552
+ assert "otel http exporting is currently DISABLED" in str (excinfo .value )
553
+
554
+ # Verify the tracer provider was created with correct resource
555
+ mock_tracer_provider .assert_called_once_with (resource = mock_resource_instance )
556
+
557
+ # Verify set_tracer_provider was not called since an exception was raised
558
+ mock_set_tracer_provider .assert_not_called ()
559
+
560
+
534
561
def test_initialize_tracer_with_custom_tracer_provider (mock_get_tracer_provider , mock_resource ):
535
562
"""Test initializing the tracer with NoOpTracerProvider."""
536
563
mock_is_initialized .return_value = True
0 commit comments