Skip to content

Commit

Permalink
add inject method
Browse files Browse the repository at this point in the history
  • Loading branch information
wconti27 committed Dec 13, 2024
1 parent 03008e6 commit f7a542f
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion 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 XRAY_MAX_ADDITIONAL_BYTES = 256;

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

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

class TextMapPropagator {
constructor (config) {
Expand Down Expand Up @@ -261,6 +262,55 @@ class TextMapPropagator {
carrier.tracestate = ts.toString()
}

_injectAwsXrayHeader (spanContext, carrier) {
const e2eStart = spanContext.start_ms;

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

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

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

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
let str = (
ROOT_PREFIX +

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

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8

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

View workflow job for this annotation

GitHub Actions / lint

'ROOT_PREFIX' is not defined
String(NANOSECONDS.toSeconds(e2eStart && e2eStart > 0 ? e2eStart : Date.now() / 1000)) +

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

View workflow job for this annotation

GitHub Actions / lint

'NANOSECONDS' is not defined
TRACE_ID_PADDING +

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

View workflow job for this annotation

GitHub Actions / lint

'TRACE_ID_PADDING' is not defined
context._traceId.toString(16).padStart(16, '0') +
';' + PARENT_PREFIX +

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

View workflow job for this annotation

GitHub Actions / lint

'PARENT_PREFIX' is not defined

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

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
context._spanId.toString(16).padStart(8, '0')
)

if (context.lockSamplingPriority()) {
str += ';' + SAMPLED_PREFIX + convertSamplingPriority(context._sampling);

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

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
}

const maxCapacity = str.length + XRAY_MAX_ADDITIONAL_BYTES;

const origin = context._trace.origin;
if (origin) {
additionalPart(str, ORIGIN_KEY, origin, maxCapacity);
}
if (e2eStart > 0) {
additionalPart(str, E2E_START_KEY, e2eStart.toString(), maxCapacity);
}

for (const [key, value] of context._baggageItems) {
if (!isReserved(key)) {
additionalPart(str, key, value, maxCapacity);
}
}

carrier['X-Amzn-Trace-Id'] = str;
}

_isReserved(key) {
return [ROOT_PREFIX, PARENT_PREFIX, SAMPLED_PREFIX].includes(key);
}

_convertSamplingPriority(samplingPriority) {
return samplingPriority > 0 ? '1' : '0';
}

_additionalPart(str, key, value, maxCapacity) {
if (str.length + key.length + value.length + 2 <= maxCapacity) {
str += `;${key}=${value}`;
}
}

_hasPropagationStyle (mode, name) {
return this._config.tracePropagationStyle[mode].includes(name)
}
Expand Down Expand Up @@ -743,7 +793,7 @@ class TextMapPropagator {
// self is added by load balancers and should be ignored
continue
} else if (key === xrayE2EStartTimeKey) {
// startTime = parseInt(value)
baggage[endToEndStartTime] = parseInt(value)
} else {
baggage[key] = value
}
Expand Down

0 comments on commit f7a542f

Please sign in to comment.