@@ -21,34 +21,34 @@ import {
2121 Tracer ,
2222} from '@opentelemetry/api' ;
2323import { RequestMetadata , ServiceExtension } from './ServiceExtension' ;
24+ import { DBSYSTEMVALUES_DYNAMODB } from '@opentelemetry/semantic-conventions' ;
2425import {
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' ;
26+ ATTR_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS ,
27+ ATTR_AWS_DYNAMODB_CONSISTENT_READ ,
28+ ATTR_AWS_DYNAMODB_CONSUMED_CAPACITY ,
29+ ATTR_AWS_DYNAMODB_COUNT ,
30+ ATTR_AWS_DYNAMODB_EXCLUSIVE_START_TABLE ,
31+ ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES ,
32+ ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES ,
33+ ATTR_AWS_DYNAMODB_INDEX_NAME ,
34+ ATTR_AWS_DYNAMODB_ITEM_COLLECTION_METRICS ,
35+ ATTR_AWS_DYNAMODB_LIMIT ,
36+ ATTR_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES ,
37+ ATTR_AWS_DYNAMODB_PROJECTION ,
38+ ATTR_AWS_DYNAMODB_PROVISIONED_READ_CAPACITY ,
39+ ATTR_AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY ,
40+ ATTR_AWS_DYNAMODB_SCAN_FORWARD ,
41+ ATTR_AWS_DYNAMODB_SCANNED_COUNT ,
42+ ATTR_AWS_DYNAMODB_SEGMENT ,
43+ ATTR_AWS_DYNAMODB_SELECT ,
44+ ATTR_AWS_DYNAMODB_TABLE_COUNT ,
45+ ATTR_AWS_DYNAMODB_TABLE_NAMES ,
46+ ATTR_AWS_DYNAMODB_TOTAL_SEGMENTS ,
47+ ATTR_DB_NAME ,
48+ ATTR_DB_OPERATION ,
49+ ATTR_DB_STATEMENT ,
50+ ATTR_DB_SYSTEM ,
51+ } from '@opentelemetry/semantic-conventions/incubating' ;
5252import {
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 ] : DBSYSTEMVALUES_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 }
0 commit comments