Skip to content

Commit 0e143ca

Browse files
committed
[tracing] Extract parent OpenTelemetry span safely
Turns out the `fields` method returns the names of fields, but it's not mandatory that those fields are present. To cope with this, we blindly assume that extracting the span's parent will work, and catch the exception in the case where the parent is missing. See: open-telemetry/opentelemetry-java#767
1 parent f9ab927 commit 0e143ca

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

java/client/src/org/openqa/selenium/remote/tracing/HttpTracing.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ private static SpanContext extract(Tracer tracer, HttpRequest request) {
4646
Objects.requireNonNull(tracer, "Tracer to use must be set.");
4747
Objects.requireNonNull(request, "Request must be set.");
4848

49-
if (tracer.getHttpTextFormat().fields().stream()
50-
.map(field -> request.getHeader(field) != null)
51-
.reduce(false, Boolean::logicalAnd)) {
49+
try {
5250
return tracer.getHttpTextFormat().extract(request, (req, key) -> req.getHeader(key));
51+
} catch (IllegalArgumentException ignored) {
52+
// See: https://github.com/open-telemetry/opentelemetry-java/issues/767
53+
// Fall through
5354
}
5455
return NO_OP_CONTEXT;
5556
}

0 commit comments

Comments
 (0)