Skip to content

Commit 893e10e

Browse files
committed
chore(aws-sdk): migrate 'SEMATTRS_*' to 'ATTR_*'
1 parent d0fb135 commit 893e10e

File tree

6 files changed

+98
-108
lines changed

6 files changed

+98
-108
lines changed

plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
} from './utils';
6060
import { propwrap } from './propwrap';
6161
import { RequestMetadata } from './services/ServiceExtension';
62-
import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions';
62+
import { ATTR_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions/incubating';
6363

6464
const V3_CLIENT_CONFIG_KEY = Symbol(
6565
'opentelemetry.instrumentation.aws-sdk.client.config'
@@ -348,7 +348,7 @@ export class AwsInstrumentation extends InstrumentationBase<AwsSdkInstrumentatio
348348

349349
const httpStatusCode = response.httpResponse?.statusCode;
350350
if (httpStatusCode) {
351-
span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, httpStatusCode);
351+
span.setAttribute(ATTR_HTTP_STATUS_CODE, httpStatusCode);
352352
}
353353
span.end();
354354
});
@@ -501,10 +501,7 @@ export class AwsInstrumentation extends InstrumentationBase<AwsSdkInstrumentatio
501501
const httpStatusCode =
502502
response.output?.$metadata?.httpStatusCode;
503503
if (httpStatusCode) {
504-
span.setAttribute(
505-
SEMATTRS_HTTP_STATUS_CODE,
506-
httpStatusCode
507-
);
504+
span.setAttribute(ATTR_HTTP_STATUS_CODE, httpStatusCode);
508505
}
509506

510507
const extendedRequestId =
@@ -538,10 +535,7 @@ export class AwsInstrumentation extends InstrumentationBase<AwsSdkInstrumentatio
538535

539536
const httpStatusCode = err?.$metadata?.httpStatusCode;
540537
if (httpStatusCode) {
541-
span.setAttribute(
542-
SEMATTRS_HTTP_STATUS_CODE,
543-
httpStatusCode
544-
);
538+
span.setAttribute(ATTR_HTTP_STATUS_CODE, httpStatusCode);
545539
}
546540

547541
const extendedRequestId = err?.extendedRequestId;

plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/dynamodb.ts

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,33 @@ import {
2222
} from '@opentelemetry/api';
2323
import { RequestMetadata, ServiceExtension } from './ServiceExtension';
2424
import {
25-
DBSYSTEMVALUES_DYNAMODB,
26-
SEMATTRS_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS,
27-
SEMATTRS_AWS_DYNAMODB_CONSISTENT_READ,
28-
SEMATTRS_AWS_DYNAMODB_CONSUMED_CAPACITY,
29-
SEMATTRS_AWS_DYNAMODB_COUNT,
30-
SEMATTRS_AWS_DYNAMODB_EXCLUSIVE_START_TABLE,
31-
SEMATTRS_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES,
32-
SEMATTRS_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES,
33-
SEMATTRS_AWS_DYNAMODB_INDEX_NAME,
34-
SEMATTRS_AWS_DYNAMODB_ITEM_COLLECTION_METRICS,
35-
SEMATTRS_AWS_DYNAMODB_LIMIT,
36-
SEMATTRS_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES,
37-
SEMATTRS_AWS_DYNAMODB_PROJECTION,
38-
SEMATTRS_AWS_DYNAMODB_PROVISIONED_READ_CAPACITY,
39-
SEMATTRS_AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY,
40-
SEMATTRS_AWS_DYNAMODB_SCAN_FORWARD,
41-
SEMATTRS_AWS_DYNAMODB_SCANNED_COUNT,
42-
SEMATTRS_AWS_DYNAMODB_SEGMENT,
43-
SEMATTRS_AWS_DYNAMODB_SELECT,
44-
SEMATTRS_AWS_DYNAMODB_TABLE_COUNT,
45-
SEMATTRS_AWS_DYNAMODB_TABLE_NAMES,
46-
SEMATTRS_AWS_DYNAMODB_TOTAL_SEGMENTS,
47-
SEMATTRS_DB_NAME,
48-
SEMATTRS_DB_OPERATION,
49-
SEMATTRS_DB_STATEMENT,
50-
SEMATTRS_DB_SYSTEM,
51-
} from '@opentelemetry/semantic-conventions';
25+
ATTR_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS,
26+
ATTR_AWS_DYNAMODB_CONSISTENT_READ,
27+
ATTR_AWS_DYNAMODB_CONSUMED_CAPACITY,
28+
ATTR_AWS_DYNAMODB_COUNT,
29+
ATTR_AWS_DYNAMODB_EXCLUSIVE_START_TABLE,
30+
ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES,
31+
ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES,
32+
ATTR_AWS_DYNAMODB_INDEX_NAME,
33+
ATTR_AWS_DYNAMODB_ITEM_COLLECTION_METRICS,
34+
ATTR_AWS_DYNAMODB_LIMIT,
35+
ATTR_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES,
36+
ATTR_AWS_DYNAMODB_PROJECTION,
37+
ATTR_AWS_DYNAMODB_PROVISIONED_READ_CAPACITY,
38+
ATTR_AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY,
39+
ATTR_AWS_DYNAMODB_SCAN_FORWARD,
40+
ATTR_AWS_DYNAMODB_SCANNED_COUNT,
41+
ATTR_AWS_DYNAMODB_SEGMENT,
42+
ATTR_AWS_DYNAMODB_SELECT,
43+
ATTR_AWS_DYNAMODB_TABLE_COUNT,
44+
ATTR_AWS_DYNAMODB_TABLE_NAMES,
45+
ATTR_AWS_DYNAMODB_TOTAL_SEGMENTS,
46+
ATTR_DB_NAME,
47+
ATTR_DB_OPERATION,
48+
ATTR_DB_STATEMENT,
49+
ATTR_DB_SYSTEM,
50+
DB_SYSTEM_VALUE_DYNAMODB,
51+
} from '@opentelemetry/semantic-conventions/incubating';
5252
import {
5353
AwsSdkInstrumentationConfig,
5454
NormalizedRequest,
@@ -71,9 +71,9 @@ export class DynamodbServiceExtension implements ServiceExtension {
7171
const operation = normalizedRequest.commandName;
7272

7373
const spanAttributes: Attributes = {
74-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_DYNAMODB,
75-
[SEMATTRS_DB_NAME]: normalizedRequest.commandInput?.TableName,
76-
[SEMATTRS_DB_OPERATION]: operation,
74+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_DYNAMODB,
75+
[ATTR_DB_NAME]: normalizedRequest.commandInput?.TableName,
76+
[ATTR_DB_OPERATION]: operation,
7777
};
7878

7979
if (config.dynamoDBStatementSerializer) {
@@ -84,7 +84,7 @@ export class DynamodbServiceExtension implements ServiceExtension {
8484
);
8585

8686
if (typeof sanitizedStatement === 'string') {
87-
spanAttributes[SEMATTRS_DB_STATEMENT] = sanitizedStatement;
87+
spanAttributes[ATTR_DB_STATEMENT] = sanitizedStatement;
8888
}
8989
} catch (err) {
9090
diag.error('failed to sanitize DynamoDB statement', err);
@@ -96,21 +96,21 @@ export class DynamodbServiceExtension implements ServiceExtension {
9696
if (normalizedRequest.commandInput?.TableName) {
9797
// Necessary for commands with only 1 table name (example: CreateTable). Attribute is TableName not keys of RequestItems
9898
// single table name returned for operations like CreateTable
99-
spanAttributes[SEMATTRS_AWS_DYNAMODB_TABLE_NAMES] = [
99+
spanAttributes[ATTR_AWS_DYNAMODB_TABLE_NAMES] = [
100100
normalizedRequest.commandInput.TableName,
101101
];
102102
} else if (normalizedRequest.commandInput?.RequestItems) {
103-
spanAttributes[SEMATTRS_AWS_DYNAMODB_TABLE_NAMES] = Object.keys(
103+
spanAttributes[ATTR_AWS_DYNAMODB_TABLE_NAMES] = Object.keys(
104104
normalizedRequest.commandInput.RequestItems
105105
);
106106
}
107107

108108
if (operation === 'CreateTable' || operation === 'UpdateTable') {
109109
// only check for ProvisionedThroughput since ReadCapacityUnits and WriteCapacity units are required attributes
110110
if (normalizedRequest.commandInput?.ProvisionedThroughput) {
111-
spanAttributes[SEMATTRS_AWS_DYNAMODB_PROVISIONED_READ_CAPACITY] =
111+
spanAttributes[ATTR_AWS_DYNAMODB_PROVISIONED_READ_CAPACITY] =
112112
normalizedRequest.commandInput.ProvisionedThroughput.ReadCapacityUnits;
113-
spanAttributes[SEMATTRS_AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY] =
113+
spanAttributes[ATTR_AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY] =
114114
normalizedRequest.commandInput.ProvisionedThroughput.WriteCapacityUnits;
115115
}
116116
}
@@ -121,28 +121,28 @@ export class DynamodbServiceExtension implements ServiceExtension {
121121
operation === 'Query'
122122
) {
123123
if (normalizedRequest.commandInput?.ConsistentRead) {
124-
spanAttributes[SEMATTRS_AWS_DYNAMODB_CONSISTENT_READ] =
124+
spanAttributes[ATTR_AWS_DYNAMODB_CONSISTENT_READ] =
125125
normalizedRequest.commandInput.ConsistentRead;
126126
}
127127
}
128128

129129
if (operation === 'Query' || operation === 'Scan') {
130130
if (normalizedRequest.commandInput?.ProjectionExpression) {
131-
spanAttributes[SEMATTRS_AWS_DYNAMODB_PROJECTION] =
131+
spanAttributes[ATTR_AWS_DYNAMODB_PROJECTION] =
132132
normalizedRequest.commandInput.ProjectionExpression;
133133
}
134134
}
135135

136136
if (operation === 'CreateTable') {
137137
if (normalizedRequest.commandInput?.GlobalSecondaryIndexes) {
138-
spanAttributes[SEMATTRS_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES] =
138+
spanAttributes[ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES] =
139139
this.toArray(
140140
normalizedRequest.commandInput.GlobalSecondaryIndexes
141141
).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));
142142
}
143143

144144
if (normalizedRequest.commandInput?.LocalSecondaryIndexes) {
145-
spanAttributes[SEMATTRS_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES] =
145+
spanAttributes[ATTR_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES] =
146146
this.toArray(
147147
normalizedRequest.commandInput.LocalSecondaryIndexes
148148
).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));
@@ -155,67 +155,66 @@ export class DynamodbServiceExtension implements ServiceExtension {
155155
operation === 'Scan'
156156
) {
157157
if (normalizedRequest.commandInput?.Limit) {
158-
spanAttributes[SEMATTRS_AWS_DYNAMODB_LIMIT] =
158+
spanAttributes[ATTR_AWS_DYNAMODB_LIMIT] =
159159
normalizedRequest.commandInput.Limit;
160160
}
161161
}
162162

163163
if (operation === 'ListTables') {
164164
if (normalizedRequest.commandInput?.ExclusiveStartTableName) {
165-
spanAttributes[SEMATTRS_AWS_DYNAMODB_EXCLUSIVE_START_TABLE] =
165+
spanAttributes[ATTR_AWS_DYNAMODB_EXCLUSIVE_START_TABLE] =
166166
normalizedRequest.commandInput.ExclusiveStartTableName;
167167
}
168168
}
169169

170170
if (operation === 'Query') {
171171
if (normalizedRequest.commandInput?.ScanIndexForward) {
172-
spanAttributes[SEMATTRS_AWS_DYNAMODB_SCAN_FORWARD] =
172+
spanAttributes[ATTR_AWS_DYNAMODB_SCAN_FORWARD] =
173173
normalizedRequest.commandInput.ScanIndexForward;
174174
}
175175

176176
if (normalizedRequest.commandInput?.IndexName) {
177-
spanAttributes[SEMATTRS_AWS_DYNAMODB_INDEX_NAME] =
177+
spanAttributes[ATTR_AWS_DYNAMODB_INDEX_NAME] =
178178
normalizedRequest.commandInput.IndexName;
179179
}
180180

181181
if (normalizedRequest.commandInput?.Select) {
182-
spanAttributes[SEMATTRS_AWS_DYNAMODB_SELECT] =
182+
spanAttributes[ATTR_AWS_DYNAMODB_SELECT] =
183183
normalizedRequest.commandInput.Select;
184184
}
185185
}
186186

187187
if (operation === 'Scan') {
188188
if (normalizedRequest.commandInput?.Segment) {
189-
spanAttributes[SEMATTRS_AWS_DYNAMODB_SEGMENT] =
189+
spanAttributes[ATTR_AWS_DYNAMODB_SEGMENT] =
190190
normalizedRequest.commandInput?.Segment;
191191
}
192192

193193
if (normalizedRequest.commandInput?.TotalSegments) {
194-
spanAttributes[SEMATTRS_AWS_DYNAMODB_TOTAL_SEGMENTS] =
194+
spanAttributes[ATTR_AWS_DYNAMODB_TOTAL_SEGMENTS] =
195195
normalizedRequest.commandInput?.TotalSegments;
196196
}
197197

198198
if (normalizedRequest.commandInput?.IndexName) {
199-
spanAttributes[SEMATTRS_AWS_DYNAMODB_INDEX_NAME] =
199+
spanAttributes[ATTR_AWS_DYNAMODB_INDEX_NAME] =
200200
normalizedRequest.commandInput.IndexName;
201201
}
202202

203203
if (normalizedRequest.commandInput?.Select) {
204-
spanAttributes[SEMATTRS_AWS_DYNAMODB_SELECT] =
204+
spanAttributes[ATTR_AWS_DYNAMODB_SELECT] =
205205
normalizedRequest.commandInput.Select;
206206
}
207207
}
208208

209209
if (operation === 'UpdateTable') {
210210
if (normalizedRequest.commandInput?.AttributeDefinitions) {
211-
spanAttributes[SEMATTRS_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] =
212-
this.toArray(normalizedRequest.commandInput.AttributeDefinitions).map(
213-
(x: { [DictionaryKey: string]: any }) => JSON.stringify(x)
214-
);
211+
spanAttributes[ATTR_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] = this.toArray(
212+
normalizedRequest.commandInput.AttributeDefinitions
213+
).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));
215214
}
216215

217216
if (normalizedRequest.commandInput?.GlobalSecondaryIndexUpdates) {
218-
spanAttributes[SEMATTRS_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES] =
217+
spanAttributes[ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES] =
219218
this.toArray(
220219
normalizedRequest.commandInput.GlobalSecondaryIndexUpdates
221220
).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));
@@ -238,7 +237,7 @@ export class DynamodbServiceExtension implements ServiceExtension {
238237
) {
239238
if (response.data?.ConsumedCapacity) {
240239
span.setAttribute(
241-
SEMATTRS_AWS_DYNAMODB_CONSUMED_CAPACITY,
240+
ATTR_AWS_DYNAMODB_CONSUMED_CAPACITY,
242241
toArray(response.data.ConsumedCapacity).map(
243242
(x: { [DictionaryKey: string]: any }) => JSON.stringify(x)
244243
)
@@ -247,7 +246,7 @@ export class DynamodbServiceExtension implements ServiceExtension {
247246

248247
if (response.data?.ItemCollectionMetrics) {
249248
span.setAttribute(
250-
SEMATTRS_AWS_DYNAMODB_ITEM_COLLECTION_METRICS,
249+
ATTR_AWS_DYNAMODB_ITEM_COLLECTION_METRICS,
251250
this.toArray(response.data.ItemCollectionMetrics).map(
252251
(x: { [DictionaryKey: string]: any }) => JSON.stringify(x)
253252
)
@@ -256,18 +255,18 @@ export class DynamodbServiceExtension implements ServiceExtension {
256255

257256
if (response.data?.TableNames) {
258257
span.setAttribute(
259-
SEMATTRS_AWS_DYNAMODB_TABLE_COUNT,
258+
ATTR_AWS_DYNAMODB_TABLE_COUNT,
260259
response.data?.TableNames.length
261260
);
262261
}
263262

264263
if (response.data?.Count) {
265-
span.setAttribute(SEMATTRS_AWS_DYNAMODB_COUNT, response.data?.Count);
264+
span.setAttribute(ATTR_AWS_DYNAMODB_COUNT, response.data?.Count);
266265
}
267266

268267
if (response.data?.ScannedCount) {
269268
span.setAttribute(
270-
SEMATTRS_AWS_DYNAMODB_SCANNED_COUNT,
269+
ATTR_AWS_DYNAMODB_SCANNED_COUNT,
271270
response.data?.ScannedCount
272271
);
273272
}

plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
import { Span, SpanKind, Tracer, diag, Attributes } from '@opentelemetry/api';
1717
import {
18-
SEMATTRS_FAAS_EXECUTION,
19-
SEMATTRS_FAAS_INVOKED_NAME,
20-
SEMATTRS_FAAS_INVOKED_PROVIDER,
21-
SEMATTRS_FAAS_INVOKED_REGION,
22-
} from '@opentelemetry/semantic-conventions';
18+
ATTR_FAAS_INVOCATION_ID,
19+
ATTR_FAAS_INVOKED_NAME,
20+
ATTR_FAAS_INVOKED_PROVIDER,
21+
ATTR_FAAS_INVOKED_REGION,
22+
} from '@opentelemetry/semantic-conventions/incubating';
2323
import {
2424
AwsSdkInstrumentationConfig,
2525
NormalizedRequest,
@@ -45,11 +45,11 @@ export class LambdaServiceExtension implements ServiceExtension {
4545
switch (request.commandName) {
4646
case 'Invoke':
4747
spanAttributes = {
48-
[SEMATTRS_FAAS_INVOKED_NAME]: functionName,
49-
[SEMATTRS_FAAS_INVOKED_PROVIDER]: 'aws',
48+
[ATTR_FAAS_INVOKED_NAME]: functionName,
49+
[ATTR_FAAS_INVOKED_PROVIDER]: 'aws',
5050
};
5151
if (request.region) {
52-
spanAttributes[SEMATTRS_FAAS_INVOKED_REGION] = request.region;
52+
spanAttributes[ATTR_FAAS_INVOKED_REGION] = request.region;
5353
}
5454
spanName = `${functionName} ${LambdaCommands.Invoke}`;
5555
break;
@@ -85,7 +85,7 @@ export class LambdaServiceExtension implements ServiceExtension {
8585
switch (response.request.commandName) {
8686
case LambdaCommands.Invoke:
8787
{
88-
span.setAttribute(SEMATTRS_FAAS_EXECUTION, response.requestId);
88+
span.setAttribute(ATTR_FAAS_INVOCATION_ID, response.requestId);
8989
}
9090
break;
9191
}

plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import { Span, Tracer, SpanKind, Attributes } from '@opentelemetry/api';
1717
import {
1818
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
19-
SEMATTRS_MESSAGING_DESTINATION,
2019
SEMATTRS_MESSAGING_DESTINATION_KIND,
21-
SEMATTRS_MESSAGING_SYSTEM,
2220
} from '@opentelemetry/semantic-conventions';
21+
import {
22+
ATTR_MESSAGING_DESTINATION_NAME,
23+
ATTR_MESSAGING_SYSTEM,
24+
} from '@opentelemetry/semantic-conventions/incubating';
2325
import {
2426
NormalizedRequest,
2527
NormalizedResponse,
@@ -36,7 +38,7 @@ export class SnsServiceExtension implements ServiceExtension {
3638
let spanKind: SpanKind = SpanKind.CLIENT;
3739
let spanName = `SNS ${request.commandName}`;
3840
const spanAttributes: Attributes = {
39-
[SEMATTRS_MESSAGING_SYSTEM]: 'aws.sns',
41+
[ATTR_MESSAGING_SYSTEM]: 'aws.sns',
4042
};
4143

4244
if (request.commandName === 'Publish') {
@@ -45,16 +47,13 @@ export class SnsServiceExtension implements ServiceExtension {
4547
spanAttributes[SEMATTRS_MESSAGING_DESTINATION_KIND] =
4648
MESSAGINGDESTINATIONKINDVALUES_TOPIC;
4749
const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;
48-
spanAttributes[SEMATTRS_MESSAGING_DESTINATION] =
50+
spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] =
4951
this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);
50-
// ToDO: Use SEMATTRS_MESSAGING_DESTINATION_NAME when implemented
51-
spanAttributes['messaging.destination.name'] =
52-
TopicArn || TargetArn || PhoneNumber || 'unknown';
5352

5453
spanName = `${
5554
PhoneNumber
5655
? 'phone_number'
57-
: spanAttributes[SEMATTRS_MESSAGING_DESTINATION]
56+
: spanAttributes[ATTR_MESSAGING_DESTINATION_NAME]
5857
} send`;
5958
}
6059

0 commit comments

Comments
 (0)