`B3PropagatorExtractorMultipleHeaders` allocates when headers are missing
メンテナーはふだん 3 日以内に返信
評価
調査の方向性
B3PropagatorExtractorMultipleHeadersを見つけ、トレースIDがない場合の処理をB3PropagatorExtractorSingleHeaderと比較してください。まず既存のextractorテストを見つけ、B3ヘッダーのないcarrierについて、FINEログが無効な状態で割り当てが発生しないことを確認するケースを追加または調整してください。ヘッダーがない場合に割り当てを行わずに戻り、無効なトレースIDのメッセージがFINEログ有効時にのみフォーマットされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
B3PropagatorExtractorMultipleHeaders builds a log message string on every extract() call where the X-B3-TraceId header is absent, even when FINE logging is disabled.
A missing X-B3-TraceId header goes through the "invalid trace ID" branch, which eagerly concatenates the (null) value into the message when calling logger.fine(...):
String traceId = getter.get(carrier, B3Propagator.TRACE_ID_HEADER);
if (!Common.isTraceIdValid(traceId)) {
logger.fine(
"Invalid TraceId in B3 header: " + traceId + "'. Returning INVALID span context.");
return Optional.empty();
}
A missing header is the common case for any request that isn't part of a trace. B3PropagatorExtractorSingleHeader already returns early without logging when its b3 header is absent. The multi-header extractor doesn't, so every untraced request allocates a string that is then discarded.
Steps to reproduce
Call B3Propagator.injectingMultiHeaders().extract(Context.root(), carrier, getter) (or injectingSingleHeader(), since both extract both formats) on a carrier with no B3 headers, and measure allocation.
private static final TextMapGetter<Map<String, String>> GETTER =
(carrier, key) -> carrier == null ? null : carrier.get(key);
@Test
void extractWithoutB3HeadersDoesNotAllocate() {
B3Propagator propagator = B3Propagator.injectingMultiHeaders();
Map<String, String> carrier = Collections.emptyMap();
ThreadMXBean threads = (ThreadMXBean) ManagementFactory.getThreadMXBean();
int iterations = 20_000;
// warm-up
for (int i = 0; i < iterations; i++) {
propagator.extract(Context.root(), carrier, GETTER);
}
long before = threads.getCurrentThreadAllocatedBytes();
for (int i = 0; i < iterations; i++) {
propagator.extract(Context.root(), carrier, GETTER);
}
long bytesPerExtract = (threads.getCurrentThreadAllocatedBytes() - before) / iterations;
assertThat(bytesPerExtract).isZero();
}
What did you expect to see?
No allocation when the B3 headers are absent (and FINE logging is disabled).
What did you see instead?
bytes allocated per extract() call with a carrier not containing the trace ID header.
What version and what artifacts are you using?
opentelemetry-extension-trace-propagators 1.68.0.
Suggested fix
Return early without logging when the trace ID header is absent (traceId is null), matching the single-header extractor, and use a parameterized log call (logger.log(Level.FINE, "... {0} ...", traceId)) for the remaining invalid-ID messages, so they are only formatted when FINE is enabled. The existing messages also contain a stray ' after the value, which should be dropped (with MessageFormat it would otherwise be interpreted as a quote). Alternatively, the log messages could be put in an if block that checks for logger.isLoggable(Level.FINE).
- 主要言語
- Java
- スター
- 2.5k
- フォーク
- 1.1k
- 平均マージ
- 5日 11時間
- マージ済み PR(30日)
- 41
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
open-telemetry/opentelemetry-java のほかの issue
-
[incubator] ComposableProbabilitySampler does not validate ratio range対応中かも @eminfikret が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
open-telemetry/opentelemetry-java#9046 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})対応中かも @rooks-ns が 19 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-java#9014 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Fix `otel.sdk.log.created` counting semantics対応中かも @anuraaga が 112 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
open-telemetry/opentelemetry-java#8688 ·
メンテナーはふだん 3 日以内に返信
-
SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is true対応中かも @Eliot5566 が今日担当しました。 オープンBug SDK
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
open-telemetry/opentelemetry-java#9062 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Feature Request
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
open-telemetry/opentelemetry-java#9061 ·
メンテナーはふだん 3 日以内に返信
open-telemetry/opentelemetry-java の issue をすべて見る
似ている issue
-
feature request needs triage
難易度 1/5 1時間未満 初心者へのやさしさ 66/100
TeamNewPipe/NewPipe#14083 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
PCL-Community/PCL-CE#3907 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 2 日以内に返信
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
stripe/stripe-java#2341 ·
メンテナーはふだん 3 日以内に返信