Skip to content

Commit 0897900

Browse files
committed
Removed AWSGlobal class and added ReadMe
1 parent ae36831 commit 0897900

File tree

3 files changed

+56
-48
lines changed

3 files changed

+56
-48
lines changed

src/Instrumentation/AwsSdk/AwsSdkInstrumentation.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class AwsSdkInstrumentation implements InstrumentationInterface
3030
private TextMapPropagatorInterface $propagator;
3131
private TracerProviderInterface $tracerProvider;
3232
private $clients = [] ;
33-
private String $clientName;
34-
private String $region;
33+
private string $clientName = 'awsClient';
34+
private string $region;
3535
private SpanInterface $span;
3636
private ScopeInterface $scope;
3737

@@ -80,16 +80,12 @@ public function getTracer(): TracerInterface
8080
return $this->tracerProvider->getTracer('io.opentelemetry.contrib.php');
8181
}
8282

83-
public function getContext():Context
84-
{
85-
return Context::getRoot();
86-
}
87-
8883
public function instrumentClients($clientsArray) : void
8984
{
9085
$this->clients = $clientsArray;
9186
}
9287

88+
/** @psalm-suppress ArgumentTypeCoercion */
9389
public function activate(): bool
9490
{
9591
try {
@@ -98,11 +94,11 @@ public function activate(): bool
9894
$propagator = $this->getPropagator();
9995

10096
$carrier = [];
101-
102-
$this->span = $tracer->spanBuilder($this->clientName . '.' . $cmd->getName())->setSpanKind(AwsSdkInstrumentation::SPAN_KIND)->startSpan();
97+
/** @phan-suppress-next-line PhanTypeMismatchArgument */
98+
$this->span = $tracer->spanBuilder($this->clientName)->setSpanKind(AwsSdkInstrumentation::SPAN_KIND)->startSpan();
10399
$this->scope = $this->span->activate();
104100

105-
$propagator->inject($carrier, null, $this->getContext());
101+
$propagator->inject($carrier);
106102

107103
$this->span->setAttributes([
108104
'rpc.method' => $cmd->getName(),
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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).

tests/Unit/Instrumentation/AwsSdk/AwsGlobalTest.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)