Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.98 KB

README-AwsSdkInstrumentation.md

File metadata and controls

50 lines (35 loc) · 1.98 KB

AWS SDK Instrumentation for OpenTelemetry PHP

This package supports manual instrumentation for the AWS SDK for PHP. For more information on how to use the AWS SDK, see the AWS SDK for PHP Developer's Guide.

Using the AWS SDK Instrumentation with AWS X-Ray

use OpenTelemetry\Instrumentation\AwsSdk\AwsSdkInstrumentation;

// Initialize Span Processor, X-Ray ID generator, Tracer Provider, and Propagator
$spanProcessor = new SimpleSpanProcessor(new OTLPExporter());
$xrayIdGenerator = new IdGenerator();
$tracerProvider = new TracerProvider($spanProcessor, null, null, null, $xrayIdGenerator);
$xrayPropagator = new Propagator();

// Create new instance of AWS SDK Instrumentation class
$awssdkinstrumentation = new  AwsSdkInstrumentation();

// Configure AWS SDK Instrumentation with Propagator and set Tracer Provider (created above)
$awssdkinstrumentation->setPropagator($xrayPropagator);
$awssdkinstrumentation->setTracerProvider($tracerProvider);

// Create and activate root span
$root = $awssdkinstrumentation->getTracer()->spanBuilder('AwsSDKInstrumentation')->setSpanKind(SpanKind::KIND_SERVER)->startSpan();
$rootScope = $root->activate();

// Initialize all AWS Client instances
$s3Client = new S3Client([
    'region' => 'us-west-2',
    'version' => '2006-03-01',
]);

// Pass client instances to AWS SDK
$awssdkinstrumentation->instrumentClients([$s3Client]);

// Activate Instrumentation -- all AWS Client calls will be automatically instrumented
$awssdkinstrumentation->activate();

// Make S3 client call
$result = $s3Client->listBuckets();

// End the root span after all the calls to the AWS SDK have been made
$root->end();
$rootScope->detach();

Useful Links and Resources

For more information on how to use the AWS SDK for PHP with AWS X-Ray and using the AWS Distro for OpenTelemetry, please see the aws-otel-php repository.