From e6b1df5de3ba853b187c738039b57f9b3372b758 Mon Sep 17 00:00:00 2001 From: Aleksei Androsov Date: Tue, 17 Jan 2023 18:21:48 +0300 Subject: [PATCH] perf(propagator-jaeger): improve deserializeSpanContext performance --- CHANGELOG.md | 2 ++ .../opentelemetry-propagator-jaeger/src/JaegerPropagator.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6385594f3f..c2968bfeca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index b4421e395b7..f6e2e8fc083 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts @@ -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. @@ -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 }; }