Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpTraceContext::extract() fails on traceparent == null #767

Closed
prydin opened this issue Jan 17, 2020 · 11 comments
Closed

HttpTraceContext::extract() fails on traceparent == null #767

prydin opened this issue Jan 17, 2020 · 11 comments
Assignees

Comments

@prydin
Copy link
Contributor

prydin commented Jan 17, 2020

io.opentelemetry.trace.propagation.HttpTraceContext::extract() can be used to construct a SpanContext from HTTP headers/request attributes. This is very useful when instrumenting servlets, for example.

However, this method fails on an IllegalArgumentException when the traceparent attribute can't be located. I don't think this exception should be called, since root spans should not have this attribute set. I believe the correct behavior should just be to copy the null to the constructed SpanContext.

@prydin
Copy link
Contributor Author

prydin commented Jan 17, 2020

Also, catching the exception and trying to manually set the parent to null through Span.Builder::setParent() doesn't work either, since it doesn't accept null parameters.

EDIT: My bad. There's setNoParent()

@carlosalberto
Copy link
Contributor

I agree on this, and I think we should try to not throw exceptions for non-fatal cases.

@DotSpy
Copy link
Member

DotSpy commented Jan 21, 2020

I will try fix it, please assign me

@DotSpy
Copy link
Member

DotSpy commented Jan 21, 2020

@pavolloffay how do u think should we return null here (

throw new IllegalArgumentException("Traceparent not present");
) or SpanContext.INVALID ?
Also i think that it's kinda heavy method, should i also refactor it?

@jkwatson
Copy link
Contributor

I'd love to see some refactoring in there, @DotSpy !

@carlosalberto
Copy link
Contributor

My advise is to keep different PRs for any refactoring (given it's not only about code style, but actual improved readability) and for the null-handling cases.

@DotSpy
Copy link
Member

DotSpy commented Jan 22, 2020

@jkwatson @carlosalberto how do u think what should i return instead of throwing:
null - but here in Java Doc it said


or SpanContext.INVALID

@jkwatson
Copy link
Contributor

I'm not a Tracing expert, but I think INVALID seems like a great answer.

@carlosalberto
Copy link
Contributor

SpanContext.INVALID definitely.

DotSpy added a commit to DotSpy/opentelemetry-java that referenced this issue Jan 22, 2020
DotSpy added a commit to DotSpy/opentelemetry-java that referenced this issue Jan 22, 2020
DotSpy added a commit to DotSpy/opentelemetry-java that referenced this issue Jan 22, 2020
bogdandrutu pushed a commit that referenced this issue Jan 29, 2020
…l cases (#782)

* fix: HttpTraceContext::extract() fails on traceparent == null (#767)

* fix: HttpTraceContext::extract() fails on traceparent == null (#767)

* fix: HttpTraceContext::extract() fails on traceparent == null (#767)

* docs: add an

* refactor: use invalid span context from HttpTraceContext

* style: apply google code style

Co-authored-by: Uladzislau Kiva <[email protected]>
@DotSpy
Copy link
Member

DotSpy commented Jan 30, 2020

I think we can close this one because it's merged

@jkwatson
Copy link
Contributor

Resolved by #782

shs96c added a commit to SeleniumHQ/selenium that referenced this issue Feb 5, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants