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

Generic mechanism for preventing multiple Server/Client spans #465

Closed
iNikem opened this issue Jun 1, 2020 · 21 comments · Fixed by #971
Closed

Generic mechanism for preventing multiple Server/Client spans #465

iNikem opened this issue Jun 1, 2020 · 21 comments · Fixed by #971

Comments

@iNikem
Copy link
Contributor

iNikem commented Jun 1, 2020

Otel spec says the following about SERVER and CLIENT spans:

  • SERVER [...] span is the child of a remote CLIENT
  • CLIENT [...] span is the parent of a remote SERVER

Together with the remaining section this brings me to the conclusion, that spec demands having at most 1 span of kind SERVER while a trace passes single JVM. The same for CLIENT. Partially this requirement is already encoded into instrumentations. E.g. incoming HTTP instrumentations attach entry-point span to a request and avoid creating new spans if they find one already attached to a request. But I propose to make this requirement more explicit.

Let us do the following:

  1. Whenever SERVER or CLIENT span is created, associate it with the current Context under the corresponding key
  2. Before attempting to create new SERVER or CLIENT span instrumentations should check if one is already present in the current context. If yes, then no new span should be created.
  3. Until we have semantic tracers, these methods can leave in BaseDecorator.
  4. Explicitly document that instrumentation may augment already existing SERVER or CLIENT span with additional information. E.g. to change span name or to add transport level attributes.

This will directly address #440 as well.

@trask
Copy link
Member

trask commented Jun 1, 2020

Yes! This sounds great to me. Thanks @anuraaga for bringing attention to this, and thanks @iNikem for this proposal. I very much like the idea of using the context to track both the current SERVER and CLIENT spans.

Tracking the SERVER span like this will allow us to finally resolve the last item in #50:

JAX-RS instrumentation was not commented out, but there was potentially some loss during the transition, as it previously used getLocalRootSpan() and now just uses the parent span, which makes all the same tests pass, but may have some impact in the real world.

@iNikem
Copy link
Contributor Author

iNikem commented Jun 2, 2020

@tylerbenson I would love to hear your opinion here :)

@trask
Copy link
Member

trask commented Jun 17, 2020

I think #507 is likely a prerequisite for this issue

@tylerbenson
Copy link
Member

@iNikem it sounds sensible to me, but do we have generic access to the context?

@iNikem
Copy link
Contributor Author

iNikem commented Jun 17, 2020

wdym? Context.current is always available, no?

@tylerbenson
Copy link
Member

I thought we were trying to avoid direct access to the grpc context like that... isn't it more of an implementation detail?

@trask
Copy link
Member

trask commented Jun 18, 2020

context used to be an implementation detail, but got promoted in OTEP 66

@trask
Copy link
Member

trask commented Aug 6, 2020

I think this applies to PRODUCER/CONSUMER spans too (so all except INTERNAL)

@trask
Copy link
Member

trask commented Aug 6, 2020

marking p2 because another p2 depends on this

@trask
Copy link
Member

trask commented Aug 19, 2020

I closed this too soon, we haven't implemented duplicate check generically for SERVER spans yet at HttpServerTracer level

@pavolloffay
Copy link
Member

When does this problem happen?

For instance does it happen in a situation where mutiple multiple server side instrumentations create spans e.g. servlet filter and then jax-rs? Or was this just a proposal to enforce single client, server span situation?

@trask
Copy link
Member

trask commented Aug 28, 2020

hey @pavolloffay!

I don't think any of the instrumentation currently creates duplicate SERVER spans, so this proposal is mostly preventative for SERVER spans, and will replace some existing logic that already existed to prevent duplicate SERVER spans.

This mechanism was a bit more needed for CLIENT spans, e.g. #440

@pavolloffay
Copy link
Member

thanks for the pointer @trask.

We had similar issues OT for server spans when people used multiple layer instrumentation for incomming requests. We ended up checking for parent span when the context was extracted. If there was active parent span it was used and just added lables e.g. @Path to enrich the data.

For the client spans the situation might be similar the lower layers can check if the parent is client and act accordingly e.g. add labels that are unique or event if the timing for that layer is important (it sometimes is).

@trask
Copy link
Member

trask commented Sep 23, 2020

Just adding a note to remember about database CLIENT spans that make http (CLIENT) calls

@jkwatson
Copy link
Contributor

It seems like there are 3 options, really.

  • suppress entirely (what we do today)
  • allow willy-nillly wild west span creation
  • suppress span creation, but enable amending attributes in the suppressed child.

Should we add a config option for these 3 options, defaulting to the current behavior?

@trask
Copy link
Member

trask commented Jan 28, 2021

We may only need one of option 3 / option 1 (I think either one of those would likely be acceptable for vendors that expect/prefer no nested client spans).

I'm not sure what to do in option 3 if a database client span makes 2 http requests?

@jkwatson
Copy link
Contributor

urgh. good point.
Maybe option 4:

  • sub spans get turned into events, with their attributes intact. We only would lose the duration of the sub-span, in that case (or maybe we introduce a semantic convention for the duration of a span event?)

@iNikem
Copy link
Contributor Author

iNikem commented Jan 29, 2021

Make it two events: starts and finish. But I quite like the idea of event duration as well

@trask
Copy link
Member

trask commented Apr 3, 2021

adding a note here that there are now generic tests for suppression of nested http client spans (#2646)

@iNikem
Copy link
Contributor Author

iNikem commented Sep 20, 2021

@open-telemetry/java-approvers Did https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/suppressing-instrumentation.md#enable-instrumentation-suppression-by-type solve this issue? Can we close it now?

@trask
Copy link
Member

trask commented Sep 21, 2021

👍 additional proposals/discussions can be opened as new issues

@trask trask closed this as completed Sep 21, 2021
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

Successfully merging a pull request may close this issue.

6 participants