@@ -84,6 +84,7 @@ public static function schemaUrlsToMergeProvider(): Generator
8484 #[Group('trace-compliance ' )]
8585 public function test_resource_service_name_default (): void
8686 {
87+ $ this ->setEnvironmentVariable ('OTEL_PHP_DETECTORS ' , 'all ' );
8788 $ resource = ResourceInfoFactory::defaultResource ();
8889 $ this ->assertEquals ('open-telemetry/opentelemetry ' , $ resource ->getAttributes ()->get ('service.name ' ));
8990 }
@@ -106,6 +107,7 @@ public function test_resource_with_invalid_environment_variable(): void
106107 #[Group('compliance ' )]
107108 public function test_resource_from_environment_service_name_takes_precedence_over_resource_attribute (): void
108109 {
110+ $ this ->setEnvironmentVariable ('OTEL_PHP_DETECTORS ' , 'all ' );
109111 $ this ->setEnvironmentVariable ('OTEL_RESOURCE_ATTRIBUTES ' , 'service.name=bar ' );
110112 $ this ->setEnvironmentVariable ('OTEL_SERVICE_NAME ' , 'foo ' );
111113 $ resource = ResourceInfoFactory::defaultResource ();
@@ -115,6 +117,7 @@ public function test_resource_from_environment_service_name_takes_precedence_ove
115117 #[Group('compliance ' )]
116118 public function test_resource_from_environment_resource_attribute_takes_precedence_over_default (): void
117119 {
120+ $ this ->setEnvironmentVariable ('OTEL_PHP_DETECTORS ' , 'all ' );
118121 $ this ->setEnvironmentVariable ('OTEL_RESOURCE_ATTRIBUTES ' , 'service.name=foo ' );
119122 $ resource = ResourceInfoFactory::defaultResource ();
120123 $ this ->assertEquals ('foo ' , $ resource ->getAttributes ()->get ('service.name ' ));
@@ -162,6 +165,35 @@ public function test_default_with_all_sdk_detectors(): void
162165 }
163166 }
164167
168+ /**
169+ * From SDK 2.x, the default detectors are reduced to: sdk, sdk_provided, env
170+ */
171+ #[DataProvider('defaultProvider ' )]
172+ public function test_default_detectors (?string $ value ): void
173+ {
174+ $ this ->setEnvironmentVariable ('OTEL_PHP_DETECTORS ' , $ value );
175+ $ resource = ResourceInfoFactory::defaultResource ();
176+ $ keys = array_keys ($ resource ->getAttributes ()->toArray ());
177+ $ expected = [
178+ 'telemetry.sdk.name ' ,
179+ 'telemetry.sdk.language ' ,
180+ 'telemetry.sdk.version ' ,
181+ 'telemetry.distro.name ' ,
182+ 'telemetry.distro.version ' ,
183+ 'service.name ' ,
184+ ];
185+
186+ $ this ->assertEquals ($ expected , $ keys );
187+ }
188+
189+ public static function defaultProvider (): array
190+ {
191+ return [
192+ ['default ' ],
193+ [null ],
194+ ];
195+ }
196+
165197 public function test_default_with_none_detectors (): void
166198 {
167199 $ this ->setEnvironmentVariable ('OTEL_PHP_DETECTORS ' , 'none ' );
0 commit comments