2222
2323use GuzzleHttp \Client ;
2424use GuzzleHttp \Psr7 \Request ;
25+ use OpenTelemetry \SDK \Attributes ;
26+ use OpenTelemetry \SDK \Resource \ResourceDetectorInterface ;
2527use OpenTelemetry \SDK \Resource \ResourceInfo ;
26- use OpenTelemetry \SDK \Trace \Attributes ;
2728use OpenTelemetry \SemConv \ResourceAttributes ;
2829use Throwable ;
2930
3233 * and return a Resource populated with metadata about the EC2
3334 * instance. Returns an empty Resource if detection fails.
3435 */
35- class Detector
36+ class Detector implements ResourceDetectorInterface
3637{
3738 private const SCHEME = 'http:// ' ;
3839 private const AWS_IDMS_ENDPOINT = '169.254.169.254 ' ;
@@ -44,7 +45,7 @@ class Detector
4445 private const MILLISECOND_TIME_OUT = 1000 ;
4546 private const CLOUD_PROVIDER = 'aws ' ;
4647
47- private $ guzzle ;
48+ private Client $ guzzle ;
4849
4950 public function __construct (Client $ guzzle )
5051 {
@@ -53,12 +54,12 @@ public function __construct(Client $guzzle)
5354
5455 /**
5556 * Attempts to connect and obtain an AWS instance Identity document. If the
56- * connection is succesful it returns a Resource
57+ * connection is successful it returns a Resource
5758 * populated with instance metadata. Returns an empty Resource
5859 * if the connection or parsing of the identity document fails.
5960 *
6061 */
61- public function detect (): ResourceInfo
62+ public function getResource (): ResourceInfo
6263 {
6364 try {
6465 $ token = $ this ->fetchToken ();
@@ -109,7 +110,7 @@ public function detect(): ResourceInfo
109110 $ attributes ->setAttribute (ResourceAttributes::HOST_NAME , $ hostName );
110111 $ attributes ->setAttribute (ResourceAttributes::CLOUD_PROVIDER , self ::CLOUD_PROVIDER );
111112
112- return ResourceInfo::create ($ attributes );
113+ return ResourceInfo::create (new Attributes ( $ attributes), ResourceAttributes:: SCHEMA_URL );
113114 } catch (\Throwable $ e ) {
114115 //TODO: add 'Process is not running on K8S when logging is added
115116 return ResourceInfo::emptyResource ();
0 commit comments