Skip to content

Commit 28a512e

Browse files
committed
Updated to use sem covs instead of hardcoding
1 parent 673f2f9 commit 28a512e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/Instrumentation/AwsSdk/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"php": "^8.2",
1313
"aws/aws-sdk-php": "^3",
1414
"ext-opentelemetry": "*",
15-
"open-telemetry/api": "^1.0"
15+
"open-telemetry/api": "^1.0",
16+
"open-telemetry/sem-conv": "^1.30"
1617
},
1718
"require-dev": {
1819
"friendsofphp/php-cs-fixer": "^3",

src/Instrumentation/AwsSdk/src/AwsSdkInstrumentation.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OpenTelemetry\API\Trace\StatusCode;
1515
use OpenTelemetry\Context\Context;
1616
use function OpenTelemetry\Instrumentation\hook;
17+
use OpenTelemetry\SemConv\TraceAttributes;
1718

1819
final class AwsSdkInstrumentation
1920
{
@@ -38,22 +39,22 @@ public static function register(): void
3839
AwsClient $c,
3940
array $params,
4041
string $class,
41-
string $func,
42-
?string $file,
43-
?int $line
42+
string $function,
43+
?string $filename,
44+
?int $lineno
4445
) use ($inst) {
4546
$cmd = $params[0];
4647
$builder = $inst->tracer()
4748
->spanBuilder("{$c->getApi()->getServiceName()}.{$cmd->getName()}")
4849
->setSpanKind(SpanKind::KIND_CLIENT)
49-
->setAttribute('rpc.system', 'aws-api')
50-
->setAttribute('rpc.method', $cmd->getName())
51-
->setAttribute('rpc.service', $c->getApi()->getServiceName())
52-
->setAttribute('aws.region', $c->getRegion())
53-
->setAttribute('code.function', $func)
54-
->setAttribute('code.namespace', $class)
55-
->setAttribute('code.filepath', $file)
56-
->setAttribute('code.line_number', $line);
50+
->setAttribute(TraceAttributes::RPC_SYSTEM, 'aws-api')
51+
->setAttribute(TraceAttributes::RPC_METHOD, $cmd->getName())
52+
->setAttribute(TraceAttributes::RPC_SERVICE, $c->getApi()->getServiceName())
53+
->setAttribute(TraceAttributes::CLOUD_REGION, $c->getRegion())
54+
->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, $function)
55+
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
56+
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
57+
->setAttribute(TraceAttributes::CODE_LINE_NUMBER, $lineno);
5758

5859
$span = $builder->startSpan();
5960
Context::storage()->attach($span->storeInContext(Context::getCurrent()));
@@ -72,12 +73,12 @@ public static function register(): void
7273
$scope->detach();
7374

7475
if ($result instanceof ResultInterface && isset($result['@metadata'])) {
75-
$span->setAttribute('http.status_code', $result['@metadata']['statusCode']);
76-
$span->setAttribute('aws.requestId', $result['@metadata']['headers']['x-amz-request-id']);
76+
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $result['@metadata']['statusCode']);
77+
$span->setAttribute(TraceAttributes::AWS_REQUEST_ID, $result['@metadata']['headers']['x-amz-request-id']);
7778
}
7879
if ($ex) {
7980
if ($ex instanceof AwsException && $ex->getAwsRequestId() !== null) {
80-
$span->setAttribute('aws.requestId', $ex->getAwsRequestId());
81+
$span->setAttribute(TraceAttributes::AWS_REQUEST_ID, $ex->getAwsRequestId());
8182
}
8283
$span->recordException($ex);
8384
$span->setStatus(StatusCode::STATUS_ERROR, $ex->getMessage());

0 commit comments

Comments
 (0)