Skip to content

Commit

Permalink
perf(propagator-jaeger): improve deserializeSpanContext performance (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
doochik committed Feb 10, 2023
1 parent d1aa906 commit 326fd55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

* feat (api-logs): separate Events API into its own package [3550](https://github.com/open-telemetry/opentelemetry-js/pull/3550) @martinkuba
* feat(sdk-metrics): apply binary search in histogram recording [#3539](https://github.com/open-telemetry/opentelemetry-js/pull/3539) @legendecas
* perf(propagator-jaeger): improve deserializeSpanContext performance [#3541](https://github.com/open-telemetry/opentelemetry-js/pull/3541) @doochik
* feat: support TraceState in SamplingResult [#3530](https://github.com/open-telemetry/opentelemetry-js/pull/3530) @raphael-theriault-swi

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export class JaegerPropagator implements TextMapPropagator {
}
}

const VALID_HEX_RE = /^[0-9a-f]{1,2}$/i;

/**
* @param {string} serializedString - a serialized span context.
* @return {SpanContext} - returns a span context represented by the serializedString.
Expand All @@ -148,9 +150,7 @@ function deserializeSpanContext(serializedString: string): SpanContext | null {

const traceId = _traceId.padStart(32, '0');
const spanId = _spanId.padStart(16, '0');
const traceFlags = flags.match(/^[0-9a-f]{1,2}$/i)
? parseInt(flags, 16) & 1
: 1;
const traceFlags = VALID_HEX_RE.test(flags) ? parseInt(flags, 16) & 1 : 1;

return { traceId, spanId, isRemote: true, traceFlags };
}

0 comments on commit 326fd55

Please sign in to comment.