@@ -133,6 +133,47 @@ public function test_provider_logs_startup_and_registration()
133133 $ this ->assertTrue (true ); // Mockery will fail if expectation not met
134134 }
135135
136+ public function test_provider_does_not_register_services_when_disabled ()
137+ {
138+ // Create a fresh Laravel application WITHOUT auto-loading our package provider
139+ $ app = new \Illuminate \Foundation \Application (
140+ realpath (__DIR__ .'/../ ' )
141+ );
142+
143+ $ app ->singleton (
144+ \Illuminate \Contracts \Http \Kernel::class,
145+ \Illuminate \Foundation \Http \Kernel::class
146+ );
147+
148+ $ app ->singleton (
149+ \Illuminate \Contracts \Console \Kernel::class,
150+ \Illuminate \Foundation \Console \Kernel::class
151+ );
152+
153+ $ app ->singleton (
154+ \Illuminate \Contracts \Debug \ExceptionHandler::class,
155+ \Illuminate \Foundation \Exceptions \Handler::class
156+ );
157+
158+ // Set config with enabled = false
159+ $ app ['config ' ] = new \Illuminate \Config \Repository ([
160+ 'otel ' => array_merge (
161+ include __DIR__ .'/../config/otel.php ' ,
162+ ['enabled ' => false ]
163+ ),
164+ ]);
165+
166+ // Create and register service provider
167+ $ provider = new OpenTelemetryServiceProvider ($ app );
168+ $ provider ->register ();
169+
170+ // Verify services are NOT bound when disabled
171+ $ this ->assertFalse ($ app ->bound (Measure::class));
172+ $ this ->assertFalse ($ app ->bound (\OpenTelemetry \API \Trace \TracerInterface::class));
173+ $ this ->assertFalse ($ app ->bound (\OpenTelemetry \API \Metrics \MeterInterface::class));
174+ $ this ->assertFalse ($ app ->bound (\Overtrue \LaravelOpenTelemetry \Support \Metric::class));
175+ }
176+
136177 public function test_tracer_provider_is_initialized ()
137178 {
138179 // 获取全局 TracerProvider
0 commit comments