Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update span pointer env vars #5266

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion packages/datadog-plugin-aws-sdk/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ class BaseAwsSdkPlugin extends ClientPlugin {
this.responseExtractDSMContext(operation, params, response.data ?? response, span)
}
this.addResponseTags(span, response)
this.addSpanPointers(span, response)

if (this._tracerConfig?.trace?.aws?.addSpanPointers) {
this.addSpanPointers(span, response)
}

this.finish(span, response, response.error)
})
}
Expand Down
16 changes: 8 additions & 8 deletions packages/datadog-plugin-aws-sdk/src/services/dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
}

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

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

this.dynamoPrimaryKeyConfig = config
return config
} catch (err) {
log.warn('Failed to parse DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
log.warn('Failed to parse DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
}
}

Expand All @@ -154,7 +154,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
* @param {string} tableName - Name of the DynamoDB table.
* @param {Object} item - Complete PutItem item parameter to be put.
* @param {Object.<string, Set<string>>} primaryKeyConfig - Mapping of table names to Sets of primary key names
* loaded from DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS.
* loaded from DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS.
* @returns {string|undefined} Hash combining table name and primary key/value pairs, or undefined if unable.
*/
static calculatePutItemHash (tableName, item, primaryKeyConfig) {
Expand All @@ -163,14 +163,14 @@ class DynamoDb extends BaseAwsSdkPlugin {
return
}
if (!primaryKeyConfig) {
log.warn('Missing DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
log.warn('Missing DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
return
}
const primaryKeySet = primaryKeyConfig[tableName]
if (!primaryKeySet || !(primaryKeySet instanceof Set) || primaryKeySet.size === 0 || primaryKeySet.size > 2) {
log.warn(
`span pointers: failed to extract PutItem span pointer: table ${tableName} ` +
'not found in primary key names or the DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
'not found in primary key names or the DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
'Please update the env var.'
)
return
Expand Down
26 changes: 13 additions & 13 deletions packages/datadog-plugin-aws-sdk/test/dynamodb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Plugin', () => {
describe('span pointers', () => {
beforeEach(() => {
DynamoDb.dynamoPrimaryKeyConfig = null
delete process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS
delete process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS
})

function testSpanPointers ({ expectedHashes, operation }) {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('Plugin', () => {
testSpanPointers({
expectedHashes: '27f424c8202ab35efbf8b0b444b1928f',
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS =
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS =
'{"OneKeyTable": ["name"]}'
dynamo.putItem({
TableName: oneKeyTableName,
Expand All @@ -194,7 +194,7 @@ describe('Plugin', () => {
it('should not add links or error for putItem when config is invalid', () => {
testSpanPointers({
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
dynamo.putItem({
TableName: oneKeyTableName,
Item: {
Expand All @@ -209,7 +209,7 @@ describe('Plugin', () => {
it('should not add links or error for putItem when config is missing', () => {
testSpanPointers({
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = null
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = null
dynamo.putItem({
TableName: oneKeyTableName,
Item: {
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Plugin', () => {
'9682c132f1900106a792f166d0619e0b'
],
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
dynamo.transactWriteItems({
TransactItems: [
{
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('Plugin', () => {
'9682c132f1900106a792f166d0619e0b'
],
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"OneKeyTable": ["name"]}'
dynamo.batchWriteItem({
RequestItems: {
[oneKeyTableName]: [
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('Plugin', () => {
testSpanPointers({
expectedHashes: 'cc32f0e49ee05d3f2820ccc999bfe306',
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
dynamo.putItem({
TableName: twoKeyTableName,
Item: {
Expand All @@ -355,7 +355,7 @@ describe('Plugin', () => {
it('should not add links or error for putItem when config is invalid', () => {
testSpanPointers({
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"DifferentTable": ["test"]}'
dynamo.putItem({
TableName: twoKeyTableName,
Item: {
Expand All @@ -370,7 +370,7 @@ describe('Plugin', () => {
it('should not add links or error for putItem when config is missing', () => {
testSpanPointers({
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = null
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = null
dynamo.putItem({
TableName: twoKeyTableName,
Item: {
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('Plugin', () => {
'8a6f801cc4e7d1d5e0dd37e0904e6316'
],
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
dynamo.transactWriteItems({
TransactItems: [
{
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('Plugin', () => {
'8a6f801cc4e7d1d5e0dd37e0904e6316'
],
operation: (callback) => {
process.env.DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS = '{"TwoKeyTable": ["id", "binary"]}'
dynamo.batchWriteItem({
RequestItems: {
[twoKeyTableName]: [
Expand Down Expand Up @@ -560,7 +560,7 @@ describe('Plugin', () => {

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

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

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

const result = dynamoDbInstance.getPrimaryKeyConfig()
expect(result).to.deep.equal({
Expand Down
9 changes: 6 additions & 3 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ class Config {
this._setValue(defaults, 'url', undefined)
this._setValue(defaults, 'version', pkg.version)
this._setValue(defaults, 'instrumentation_config_id', undefined)
this._setValue(defaults, 'aws.dynamoDb.tablePrimaryKeys', undefined)
this._setValue(defaults, 'trace.aws.addSpanPointers', true)
this._setValue(defaults, 'trace.dynamoDb.tablePrimaryKeys', undefined)
}

_applyEnvironment () {
Expand All @@ -600,7 +601,6 @@ class Config {
DD_APPSEC_RASP_ENABLED,
DD_APPSEC_TRACE_RATE_LIMIT,
DD_APPSEC_WAF_TIMEOUT,
DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS,
DD_CRASHTRACKING_ENABLED,
DD_CODE_ORIGIN_FOR_SPANS_ENABLED,
DD_DATA_STREAMS_ENABLED,
Expand Down Expand Up @@ -666,10 +666,12 @@ class Config {
DD_TRACE_AGENT_HOSTNAME,
DD_TRACE_AGENT_PORT,
DD_TRACE_AGENT_PROTOCOL_VERSION,
DD_TRACE_AWS_ADD_SPAN_POINTERS,
DD_TRACE_BAGGAGE_MAX_BYTES,
DD_TRACE_BAGGAGE_MAX_ITEMS,
DD_TRACE_CLIENT_IP_ENABLED,
DD_TRACE_CLIENT_IP_HEADER,
DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS,
DD_TRACE_ENABLED,
DD_TRACE_EXPERIMENTAL_EXPORTER,
DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED,
Expand Down Expand Up @@ -905,7 +907,8 @@ class Config {
this._setBoolean(env, 'tracing', DD_TRACING_ENABLED)
this._setString(env, 'version', DD_VERSION || tags.version)
this._setBoolean(env, 'inferredProxyServicesEnabled', DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED)
this._setString(env, 'aws.dynamoDb.tablePrimaryKeys', DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS)
this._setBoolean(env, 'trace.aws.addSpanPointers', DD_TRACE_AWS_ADD_SPAN_POINTERS)
this._setString(env, 'trace.dynamoDb.tablePrimaryKeys', DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS)
this._setArray(env, 'graphqlErrorExtensions', DD_TRACE_GRAPHQL_ERROR_EXTENSIONS)
}

Expand Down
Loading