Skip to content

Commit

Permalink
[tracing] Extract parent OpenTelemetry span safely
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shs96c committed Feb 4, 2020
1 parent f9ab927 commit 0e143ca
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ private static SpanContext extract(Tracer tracer, HttpRequest request) {
Objects.requireNonNull(tracer, "Tracer to use must be set.");
Objects.requireNonNull(request, "Request must be set.");

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

0 comments on commit 0e143ca

Please sign in to comment.