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 Jan 17, 2023
1 parent 5127371 commit e6b1df5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* perf(propagator-jaeger): improve deserializeSpanContext performance [#3541](https://github.com/open-telemetry/opentelemetry-js/pull/3541) @doochik

### :bug: (Bug Fix)

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

const validHexRe = /^[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 = validHexRe.test(flags) ? parseInt(flags, 16) & 1 : 1;

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

0 comments on commit e6b1df5

Please sign in to comment.