`B3PropagatorExtractorMultipleHeaders` allocates when headers are missing
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Tìm B3PropagatorExtractorMultipleHeaders và so sánh cách xử lý khi thiếu trace ID với B3PropagatorExtractorSingleHeader. Bắt đầu bằng cách tìm các bài kiểm tra extractor hiện có và thêm hoặc điều chỉnh một trường hợp cho carrier không có header B3, xác minh không có cấp phát nào khi ghi log FINE bị tắt. Hoàn tất khi thiếu header thì hàm trả về mà không cấp phát, và các thông báo về trace ID không hợp lệ chỉ được định dạng khi ghi log FINE được bật.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Java
- Star
- 2.5k
- Fork
- 1.1k
- Merge trung bình
- 5 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 41
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của open-telemetry/opentelemetry-java
-
[incubator] ComposableProbabilitySampler does not validate ratio rangeCó thể đã có người làm @eminfikret đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
open-telemetry/opentelemetry-java#9046 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})Có thể đã có người làm @rooks-ns đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
open-telemetry/opentelemetry-java#9014 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Fix `otel.sdk.log.created` counting semanticsCó thể đã có người làm @anuraaga đã nhận 112 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
open-telemetry/opentelemetry-java#8688 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is trueCó thể đã có người làm @Eliot5566 đã nhận hôm nay. Đang mởBug SDK
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
open-telemetry/opentelemetry-java#9062 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Feature Request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
open-telemetry/opentelemetry-java#9061 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của open-telemetry/opentelemetry-java
Issue tương tự
-
feature request needs triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 66/100
TeamNewPipe/NewPipe#14083 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
NeoForge 安装任务的子任务描述有误Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
PCL-Community/PCL-CE#3907 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 2 ngày
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
stripe/stripe-java#2341 ·
Maintainer thường phản hồi trong vòng 3 ngày