Skip to content

Commit f7cc344

Browse files
authored
Update span pointer env vars (#5266)
* add `DD_TRACE_AWS_ADD_SPAN_POINTERS` env var & update DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS to DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS
1 parent c894085 commit f7cc344

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

packages/datadog-plugin-aws-sdk/src/base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ class BaseAwsSdkPlugin extends ClientPlugin {
9393
this.responseExtractDSMContext(operation, params, response.data ?? response, span)
9494
}
9595
this.addResponseTags(span, response)
96-
this.addSpanPointers(span, response)
96+
97+
if (this._tracerConfig?.trace?.aws?.addSpanPointers) {
98+
this.addSpanPointers(span, response)
99+
}
100+
97101
this.finish(span, response, response.error)
98102
})
99103
}

packages/datadog-plugin-aws-sdk/src/services/dynamodb.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
113113
}
114114

115115
/**
116-
* Parses primary key config from the `DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS` env var.
116+
* Parses primary key config from the `DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS` env var.
117117
* Only runs when needed, and warns when missing or invalid config.
118118
* @returns {Object|undefined} Parsed config from env var or undefined if empty/missing/invalid config.
119119
*/
@@ -123,9 +123,9 @@ class DynamoDb extends BaseAwsSdkPlugin {
123123
return this.dynamoPrimaryKeyConfig
124124
}
125125

126-
const configStr = this._tracerConfig?.aws?.dynamoDb?.tablePrimaryKeys
126+
const configStr = this._tracerConfig?.trace?.dynamoDb?.tablePrimaryKeys
127127
if (!configStr) {
128-
log.warn('Missing DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env variable. ' +
128+
log.warn('Missing DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env variable. ' +
129129
'Please add your table\'s primary keys under this env variable.')
130130
return
131131
}
@@ -138,14 +138,14 @@ class DynamoDb extends BaseAwsSdkPlugin {
138138
config[tableName] = new Set(primaryKeys)
139139
} else {
140140
log.warn(`Invalid primary key configuration for table: ${tableName}.` +
141-
'Please fix the DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env var.')
141+
'Please fix the DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env var.')
142142
}
143143
}
144144

145145
this.dynamoPrimaryKeyConfig = config
146146
return config
147147
} catch (err) {
148-
log.warn('Failed to parse DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
148+
log.warn('Failed to parse DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
149149
}
150150
}
151151

@@ -154,7 +154,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
154154
* @param {string} tableName - Name of the DynamoDB table.
155155
* @param {Object} item - Complete PutItem item parameter to be put.
156156
* @param {Object.<string, Set<string>>} primaryKeyConfig - Mapping of table names to Sets of primary key names
157-
* loaded from DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS.
157+
* loaded from DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS.
158158
* @returns {string|undefined} Hash combining table name and primary key/value pairs, or undefined if unable.
159159
*/
160160
static calculatePutItemHash (tableName, item, primaryKeyConfig) {
@@ -163,14 +163,14 @@ class DynamoDb extends BaseAwsSdkPlugin {
163163
return
164164
}
165165
if (!primaryKeyConfig) {
166-
log.warn('Missing DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
166+
log.warn('Missing DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
167167
return
168168
}
169169
const primaryKeySet = primaryKeyConfig[tableName]
170170
if (!primaryKeySet || !(primaryKeySet instanceof Set) || primaryKeySet.size === 0 || primaryKeySet.size > 2) {
171171
log.warn(
172172
`span pointers: failed to extract PutItem span pointer: table ${tableName} ` +
173-
'not found in primary key names or the DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
173+
'not found in primary key names or the DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
174174
'Please update the env var.'
175175
)
176176
return

packages/datadog-plugin-aws-sdk/test/dynamodb.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Plugin', () => {
128128
describe('span pointers', () => {
129129
beforeEach(() => {
130130
DynamoDb.dynamoPrimaryKeyConfig = null
131-
delete process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS
131+
delete process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS
132132
})
133133

134134
function testSpanPointers ({ expectedHashes, operation }) {
@@ -178,7 +178,7 @@ describe('Plugin', () => {
178178
testSpanPointers({
179179
expectedHashes: '27f424c8202ab35efbf8b0b444b1928f',
180180
operation: (callback) => {
181-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS =
181+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS =
182182
'{"OneKeyTable": ["name"]}'
183183
dynamo.putItem({
184184
TableName: oneKeyTableName,
@@ -194,7 +194,7 @@ describe('Plugin', () => {
194194
it('should not add links or error for putItem when config is invalid', () => {
195195
testSpanPointers({
196196
operation: (callback) => {
197-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
197+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
198198
dynamo.putItem({
199199
TableName: oneKeyTableName,
200200
Item: {
@@ -209,7 +209,7 @@ describe('Plugin', () => {
209209
it('should not add links or error for putItem when config is missing', () => {
210210
testSpanPointers({
211211
operation: (callback) => {
212-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = null
212+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = null
213213
dynamo.putItem({
214214
TableName: oneKeyTableName,
215215
Item: {
@@ -263,7 +263,7 @@ describe('Plugin', () => {
263263
'9682c132f1900106a792f166d0619e0b'
264264
],
265265
operation: (callback) => {
266-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
266+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
267267
dynamo.transactWriteItems({
268268
TransactItems: [
269269
{
@@ -308,7 +308,7 @@ describe('Plugin', () => {
308308
'9682c132f1900106a792f166d0619e0b'
309309
],
310310
operation: (callback) => {
311-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
311+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
312312
dynamo.batchWriteItem({
313313
RequestItems: {
314314
[oneKeyTableName]: [
@@ -340,7 +340,7 @@ describe('Plugin', () => {
340340
testSpanPointers({
341341
expectedHashes: 'cc32f0e49ee05d3f2820ccc999bfe306',
342342
operation: (callback) => {
343-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
343+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
344344
dynamo.putItem({
345345
TableName: twoKeyTableName,
346346
Item: {
@@ -355,7 +355,7 @@ describe('Plugin', () => {
355355
it('should not add links or error for putItem when config is invalid', () => {
356356
testSpanPointers({
357357
operation: (callback) => {
358-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
358+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
359359
dynamo.putItem({
360360
TableName: twoKeyTableName,
361361
Item: {
@@ -370,7 +370,7 @@ describe('Plugin', () => {
370370
it('should not add links or error for putItem when config is missing', () => {
371371
testSpanPointers({
372372
operation: (callback) => {
373-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = null
373+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = null
374374
dynamo.putItem({
375375
TableName: twoKeyTableName,
376376
Item: {
@@ -452,7 +452,7 @@ describe('Plugin', () => {
452452
'8a6f801cc4e7d1d5e0dd37e0904e6316'
453453
],
454454
operation: (callback) => {
455-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
455+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
456456
dynamo.transactWriteItems({
457457
TransactItems: [
458458
{
@@ -505,7 +505,7 @@ describe('Plugin', () => {
505505
'8a6f801cc4e7d1d5e0dd37e0904e6316'
506506
],
507507
operation: (callback) => {
508-
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
508+
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
509509
dynamo.batchWriteItem({
510510
RequestItems: {
511511
[twoKeyTableName]: [
@@ -560,7 +560,7 @@ describe('Plugin', () => {
560560

561561
it('should parse valid config with single table', () => {
562562
const configStr = '{"Table1": ["key1", "key2"]}'
563-
dynamoDbInstance._tracerConfig = { aws: { dynamoDb: { tablePrimaryKeys: configStr } } }
563+
dynamoDbInstance._tracerConfig = { trace: { dynamoDb: { tablePrimaryKeys: configStr } } }
564564

565565
const result = dynamoDbInstance.getPrimaryKeyConfig()
566566
expect(result).to.deep.equal({
@@ -570,7 +570,7 @@ describe('Plugin', () => {
570570

571571
it('should parse valid config with multiple tables', () => {
572572
const configStr = '{"Table1": ["key1"], "Table2": ["key2", "key3"]}'
573-
dynamoDbInstance._tracerConfig = { aws: { dynamoDb: { tablePrimaryKeys: configStr } } }
573+
dynamoDbInstance._tracerConfig = { trace: { dynamoDb: { tablePrimaryKeys: configStr } } }
574574

575575
const result = dynamoDbInstance.getPrimaryKeyConfig()
576576
expect(result).to.deep.equal({

packages/dd-trace/src/config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ class Config {
575575
this._setValue(defaults, 'url', undefined)
576576
this._setValue(defaults, 'version', pkg.version)
577577
this._setValue(defaults, 'instrumentation_config_id', undefined)
578-
this._setValue(defaults, 'aws.dynamoDb.tablePrimaryKeys', undefined)
578+
this._setValue(defaults, 'trace.aws.addSpanPointers', true)
579+
this._setValue(defaults, 'trace.dynamoDb.tablePrimaryKeys', undefined)
579580
}
580581

581582
_applyEnvironment () {
@@ -600,7 +601,6 @@ class Config {
600601
DD_APPSEC_RASP_ENABLED,
601602
DD_APPSEC_TRACE_RATE_LIMIT,
602603
DD_APPSEC_WAF_TIMEOUT,
603-
DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS,
604604
DD_CRASHTRACKING_ENABLED,
605605
DD_CODE_ORIGIN_FOR_SPANS_ENABLED,
606606
DD_DATA_STREAMS_ENABLED,
@@ -666,10 +666,12 @@ class Config {
666666
DD_TRACE_AGENT_HOSTNAME,
667667
DD_TRACE_AGENT_PORT,
668668
DD_TRACE_AGENT_PROTOCOL_VERSION,
669+
DD_TRACE_AWS_ADD_SPAN_POINTERS,
669670
DD_TRACE_BAGGAGE_MAX_BYTES,
670671
DD_TRACE_BAGGAGE_MAX_ITEMS,
671672
DD_TRACE_CLIENT_IP_ENABLED,
672673
DD_TRACE_CLIENT_IP_HEADER,
674+
DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS,
673675
DD_TRACE_ENABLED,
674676
DD_TRACE_EXPERIMENTAL_EXPORTER,
675677
DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED,
@@ -905,7 +907,8 @@ class Config {
905907
this._setBoolean(env, 'tracing', DD_TRACING_ENABLED)
906908
this._setString(env, 'version', DD_VERSION || tags.version)
907909
this._setBoolean(env, 'inferredProxyServicesEnabled', DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED)
908-
this._setString(env, 'aws.dynamoDb.tablePrimaryKeys', DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS)
910+
this._setBoolean(env, 'trace.aws.addSpanPointers', DD_TRACE_AWS_ADD_SPAN_POINTERS)
911+
this._setString(env, 'trace.dynamoDb.tablePrimaryKeys', DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS)
909912
this._setArray(env, 'graphqlErrorExtensions', DD_TRACE_GRAPHQL_ERROR_EXTENSIONS)
910913
}
911914

0 commit comments

Comments
 (0)