|
| 1 | +# AWS SDK Instrumentation for OpenTelemetry PHP |
| 2 | +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](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/welcome.html). |
| 3 | + |
| 4 | + |
| 5 | +## Using the AWS SDK Instrumentation with AWS X-Ray |
| 6 | + |
| 7 | + |
| 8 | +``` |
| 9 | +use OpenTelemetry\Instrumentation\AwsSdk\AwsSdkInstrumentation; |
| 10 | +
|
| 11 | +// Initialize Span Processor, X-Ray ID generator, Tracer Provider, and Propagator |
| 12 | +$spanProcessor = new SimpleSpanProcessor(new OTLPExporter()); |
| 13 | +$xrayIdGenerator = new IdGenerator(); |
| 14 | +$tracerProvider = new TracerProvider($spanProcessor, null, null, null, $xrayIdGenerator); |
| 15 | +$xrayPropagator = new Propagator(); |
| 16 | +
|
| 17 | +// Create new instance of AWS SDK Instrumentation class |
| 18 | +$awssdkinstrumentation = new AwsSdkInstrumentation(); |
| 19 | +
|
| 20 | +// Configure AWS SDK Instrumentation with Propagator and set Tracer Provider (created above) |
| 21 | +$awssdkinstrumentation->setPropagator($xrayPropagator); |
| 22 | +$awssdkinstrumentation->setTracerProvider($tracerProvider); |
| 23 | +
|
| 24 | +// Create and activate root span |
| 25 | +$root = $awssdkinstrumentation->getTracer()->spanBuilder('AwsSDKInstrumentation')->setSpanKind(SpanKind::KIND_SERVER)->startSpan(); |
| 26 | +$rootScope = $root->activate(); |
| 27 | +
|
| 28 | +// Initialize all AWS Client instances |
| 29 | +$s3Client = new S3Client([ |
| 30 | + 'region' => 'us-west-2', |
| 31 | + 'version' => '2006-03-01', |
| 32 | +]); |
| 33 | +
|
| 34 | +// Pass client instances to AWS SDK |
| 35 | +$awssdkinstrumentation->instrumentClients([$s3Client]); |
| 36 | +
|
| 37 | +// Activate Instrumentation -- all AWS Client calls will be automatically instrumented |
| 38 | +$awssdkinstrumentation->activate(); |
| 39 | +
|
| 40 | +// Make S3 client call |
| 41 | +$result = $s3Client->listBuckets(); |
| 42 | +
|
| 43 | +// End the root span after all the calls to the AWS SDK have been made |
| 44 | +$root->end(); |
| 45 | +$rootScope->detach(); |
| 46 | +
|
| 47 | +``` |
| 48 | + |
| 49 | +## Useful Links and Resources |
| 50 | +For more information on how to use the AWS SDK for PHP with AWS X-Ray and using the [AWS Distro for OpenTelemetry](https://aws-otel.github.io/), please see the [aws-otel-php repository](https://github.com/aws-observability/aws-otel-php). |
0 commit comments