From 6bf6252b1b05c8b6f67f6e0ed7063c2a5da5bb7a Mon Sep 17 00:00:00 2001 From: Mateusz Cholewka Date: Thu, 17 Mar 2022 15:49:40 +0100 Subject: [PATCH] Specify AWS attributes to show exact services in XRay --- examples/aws/AwsClientApp/src/main.php | 39 +++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/aws/AwsClientApp/src/main.php b/examples/aws/AwsClientApp/src/main.php index 8ba467b4..f158ac46 100644 --- a/examples/aws/AwsClientApp/src/main.php +++ b/examples/aws/AwsClientApp/src/main.php @@ -58,13 +58,9 @@ $propagator = new Propagator(); // Create root span -$root = $tracer->spanBuilder('root')->startSpan(); +$root = $tracer->spanBuilder('AwsClientApp')->startSpan(); $root->activate(); -$root->setAttribute('item_A', 'cars') - ->setAttribute('item_B', 'motorcycles') - ->setAttribute('item_C', 'planes'); - $carrier = []; if ($line === 'outgoing-http-call') { @@ -74,7 +70,13 @@ try { $client = new Client(); - $client->request('GET', 'https://aws.amazon.com', ['headers' => $carrier, 'timeout' => 2000,]); + $result = $client->request('GET', 'https://aws.amazon.com', ['headers' => $carrier]); + + $span->setAttributes([ + 'http.method' => 'GET', + 'http.url' => 'https://aws.amazon.com', + 'http.status_code' => $result->getStatusCode(), + ]); } catch (\Throwable $e) { echo $e->getMessage() . PHP_EOL; exit(1); @@ -86,9 +88,14 @@ } if ($line === 'aws-sdk-call') { - $span = $tracer->spanBuilder('session.generate.aws.sdk.span')->setSpanKind(SpanKind::KIND_CLIENT)->startSpan(); + $span = $tracer->spanBuilder('S3.CreateBucket')->setSpanKind(SpanKind::KIND_CLIENT)->startSpan(); + $span->activate(); - $propagator->inject($carrier); + $span->setAttributes([ + 'rpc.method' => 'CreateBucket', + 'rpc.service' => 'S3', + 'rpc.system' => 'aws-api', + ]); $s3Client = new S3Client([ 'profile' => 'default', @@ -98,18 +105,30 @@ try { $result = $s3Client->createBucket([ - 'Bucket' => uniqid('test-bucket-'), + 'Bucket' => uniqid('test-bucket-'), ]); echo <<getAwsErrorMessage()}"; + exit(1); } + $span->end(); + + $span = $tracer->spanBuilder('S3.ListBuckets')->setSpanKind(SpanKind::KIND_CLIENT)->startSpan(); + $span->activate(); + + $span->setAttributes([ + 'rpc.method' => 'ListBuckets', + 'rpc.service' => 'S3', + 'rpc.system' => 'aws-api', + ]); + $buckets = $s3Client->listBuckets(); foreach ($buckets['Buckets'] as $bucket) {