Skip to content

Commit

Permalink
remove check for aws signed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
wconti27 committed Dec 19, 2024
1 parent f6ff0b5 commit f427e9b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 97 deletions.
39 changes: 1 addition & 38 deletions packages/datadog-plugin-http/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class HttpClientPlugin extends ClientPlugin {
span._spanContext._trace.record = false
}

if (this.shouldInjectTraceHeaders(options, uri)) {
if (!this.config.propagationFilter(uri)) {
this.tracer.inject(span, HTTP_HEADERS, options.headers)
}

Expand All @@ -71,18 +71,6 @@ class HttpClientPlugin extends ClientPlugin {
return message.currentStore
}

shouldInjectTraceHeaders (options, uri) {
if (hasAmazonSignature(options) && !this.config.enablePropagationWithAmazonHeaders) {
return false
}

if (!this.config.propagationFilter(uri)) {
return false
}

return true
}

bindAsyncStart ({ parentStore }) {
return parentStore
}
Expand Down Expand Up @@ -212,31 +200,6 @@ function getHooks (config) {
return { request }
}

function hasAmazonSignature (options) {
if (!options) {
return false
}

if (options.headers) {
const headers = Object.keys(options.headers)
.reduce((prev, next) => Object.assign(prev, {
[next.toLowerCase()]: options.headers[next]
}), {})

if (headers['x-amz-signature']) {
return true
}

if ([].concat(headers.authorization).some(startsWith('AWS4-HMAC-SHA256'))) {
return true
}
}

const search = options.search || options.path

return search && search.toLowerCase().indexOf('x-amz-signature=') !== -1
}

function extractSessionDetails (options) {
if (typeof options === 'string') {
return new URL(options).host
Expand Down
43 changes: 0 additions & 43 deletions packages/datadog-plugin-http/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,49 +1093,6 @@ describe('Plugin', () => {
})
})

describe('with config enablePropagationWithAmazonHeaders enabled', () => {
let config

beforeEach(() => {
config = {
enablePropagationWithAmazonHeaders: true
}

return agent.load('http', config)
.then(() => {
http = require(pluginToBeLoaded)
express = require('express')
})
})

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

app.get('/', (req, res) => {
try {
expect(req.get('x-amzn-trace-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('with validateStatus configuration', () => {
let config

Expand Down
20 changes: 4 additions & 16 deletions packages/dd-trace/src/opentracing/propagation/text_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const xraySampledKey = 'sampled'
const xrayE2EStartTimeKey = 't0'
const xraySelfKey = 'self'
const xrayOriginKey = '_dd.origin'
const xrayDefaultE2EStartTime = '00000000'
const xrayMaxAdditionalBaggageBytes = 256

class TextMapPropagator {
Expand Down Expand Up @@ -306,7 +307,7 @@ class TextMapPropagator {
if (origin) {
this._addXrayBaggage(str, xrayOriginKey, origin, maxAdditionalCapacity)
}
if (e2eStart !== '00000000') {
if (e2eStart !== xrayDefaultStartTime) {

Check failure on line 310 in packages/dd-trace/src/opentracing/propagation/text_map.js

View workflow job for this annotation

GitHub Actions / lint

'xrayDefaultStartTime' is not defined
this._addXrayBaggage(str, xrayE2EStartTimeKey, e2eStart.toString(), maxAdditionalCapacity)
}

Expand All @@ -320,7 +321,7 @@ class TextMapPropagator {
}

_getEndToEndStartTime (start) {
if (!start) return '00000000'
if (!start) return xrayDefaultE2EStartTime

const e2eStart = start > 0 ? start : Date.now() / 1000
return e2eStart.toString().padStart(8, '0')
Expand Down Expand Up @@ -794,20 +795,7 @@ class TextMapPropagator {
let ddOrigin
const baggage = {}

if (!(
xrayRootKey in parsedHeader &&
// Regex check to ensure received header is in the same format as expected
// Format:
// 'Root=1-'
// 8 hexadecimal characters representing start time
// '-'
// 24 hexadecimal characters representing trace id
// ';'
// 'Parent='
// 16 hexadecimal characters representing parent span id
/^(?=.*Root=1-[0-9a-f]{8}-[0-9a-f]{24})(?=.*Parent=[0-9a-f]{16}).*$/i.test(carrier[xrayHeaderKey])
)) {
// header doesn't match formatting
if (!(xrayRootKey in parsedHeader)) {
return null
}

Expand Down

0 comments on commit f427e9b

Please sign in to comment.