Skip to content

Commit

Permalink
aws: add DD_TRACE_FORCE_AWS_PROPAGATION env var
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Dec 13, 2024
1 parent baf22d9 commit 2e79bf4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/datadog-plugin-http/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ function normalizeClientConfig (config) {
const propagationFilter = getFilter({ blocklist: config.propagationBlocklist })
const headers = getHeaders(config)
const hooks = getHooks(config)
const enablePropagationWithAmazonHeaders = config.enablePropagationWithAmazonHeaders ||
process.env.DD_TRACE_FORCE_AWS_PROPAGATION === 'true'

return Object.assign({}, config, {
validateStatus,
filter,
propagationFilter,
headers,
hooks
hooks,
enablePropagationWithAmazonHeaders
})
}

Expand Down
88 changes: 88 additions & 0 deletions packages/datadog-plugin-http/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,94 @@ describe('Plugin', () => {
})
})

describe('with DD_TRACE_FORCE_AWS_PROPAGATION=true', () => {
describe('set to true', () => {
beforeEach(() => {
process.env.DD_TRACE_FORCE_AWS_PROPAGATION = 'true'
return agent.load('http', {})
.then(() => {
http = require(pluginToBeLoaded)
express = require('express')
})
})

afterEach(() => {
delete process.env.DD_TRACE_FORCE_AWS_PROPAGATION
})

it('should inject tracing header into AWS signed request', done => {
const app = express()

app.get('/', (req, res) => {
try {
expect(req.get('x-datadog-trace-id')).to.be.a('string')
expect(req.get('x-datadog-parent-id')).to.be.a('string')

res.status(200).send()

done()
} catch (e) {
done(e)
}
})

appListener = server(app, port => {
const req = http.request({
port,
headers: {
Authorization: 'AWS4-HMAC-SHA256 ...'
}
})

req.end()
})
})
})

describe('set to false', () => {
beforeEach(() => {
process.env.DD_TRACE_FORCE_AWS_PROPAGATION = 'false'
return agent.load('http', {})
.then(() => {
http = require(pluginToBeLoaded)
express = require('express')
})
})

afterEach(() => {
delete process.env.DD_TRACE_FORCE_AWS_PROPAGATION
})

it('should not inject tracing header into AWS signed request', done => {
const app = express()

app.get('/', (req, res) => {
try {
expect(req.get('x-datadog-trace-id')).to.be.undefined
expect(req.get('x-datadog-parent-id')).to.be.undefined

res.status(200).send()

done()
} catch (e) {
done(e)
}
})

appListener = server(app, port => {
const req = http.request({
port,
headers: {
Authorization: 'AWS4-HMAC-SHA256 ...'
}
})

req.end()
})
})
})
})

describe('with validateStatus configuration', () => {
let config

Expand Down

0 comments on commit 2e79bf4

Please sign in to comment.