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

Add span processing function from application code #6191

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Jun 20, 2022

Some users wish to add extra attributes or update the name of http client spans. This can be troublesome because there isn't an obvious place where you could stick Span.current() and add the attributes. This pr introduces an api for adding a span processing function to context and a span processor that applies that function when the span is created.

@laurit laurit requested a review from a team June 20, 2022 11:14
Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to keep new public API here in a separate incubator artifact if needing to merge this soon. As there isn't any instrumentation-specific issue here, at a glance it seems that the SDK is a better place for this, though as usual I generally wouldn't stop active avoidance of the spec process if that's the main motivation :)

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some users wish to add extra attributes or update the name of http client spans. This can be troublesome because there isn't an obvious place where you could stick Span.current() and add the attributes.

If not using the Javaagent, would registering a SpanProcessor solve this use case?

And if so, what do you think about providing a javaagent-only hook to register/bridge SpanProcessor, instead of introducing new concept?

@anuraaga
Copy link
Contributor

Realized also that attributesextractor also should be able to hook this and maybe is simpler than span processor.

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@laurit
Copy link
Contributor Author

laurit commented Jun 23, 2022

If not using the Javaagent, would registering a SpanProcessor solve this use case?

I believe so. It should be possible to implement a SpanProcessor that reads the actual processing function from context like in this pr, or use some other way to communicate what needs to be done to the SpanProcessor. It should be something that users can implement on their own if they need this.
With java agent doing the same is a lot harder because of the need to bridge.

And if so, what do you think about providing a javaagent-only hook to register/bridge SpanProcessor, instead of introducing new concept?

You mean using SpanProcessor instead of BiConsumer? I did consider it and chose to go with BiConsumer because SpanProcessor.onEnd doesn't have access to Context so I couldn't look up the actual function to call. Also SpanProcessor.onEnd shouldn't change the span anyway.

* will be applied to all spans create while the context is active. Processing function is called
* synchronously on the execution thread, it should not throw or block the execution thread.
*/
public interface ContextSpanProcessor extends ImplicitContextKeyed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this class to instrumentation-api-semconv? (I guess it's probably the best place for incubating code?) As we want to release stable instrumentation-api soon, we shouldn't add new experimental utils there.

Also, there are other angles that we might want to consider in the future:

  • making it possible to load SPI implementations directly from the application code; you could add a SpanProcessor without an extension this way;
  • or going through spec with this -- there's an OTEP about Context-scoped attributes (Propose Context-scoped attributes. oteps#207) that looks really similar to this.
    If any of these get implemented at some point we'll want to deprecate and remove the ContextSpanProcessor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting I hadn't made the connection with the context-scoped attributes OTEP 👍

laurit and others added 2 commits June 27, 2022 19:36
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we comfortable dropping backwards compatibility for this in future Javaagent versions (e.g. if open-telemetry/oteps#207 gets implemented)?

I don't mean without a deprecation cycle, but rather as opposed to ServerSpan which we continue to preserve backwards compatibility for in the Javaagent to avoid breaking users of older instrumentation-api.

@laurit
Copy link
Contributor Author

laurit commented Jul 12, 2022

@trask I added a note to the javadoc that marks this as experimental. We'll sooner or later wish to introduce experimental APIs, we might as well start with this one and see how it plays out. By clearly stating that this API can be removed we should absolve ourselves of the consequences of removing it. Not that something particularly bad would happen, the way it is built when agent drops support for it there will just be a loss of functionality not exceptions flying around.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

might be nice to get rename suggested into same release to avoid breaking/dealing with deprecation right away #6310 (comment)

@trask
Copy link
Member

trask commented Jul 19, 2022

let's hold this until after 1.16.0, so we can sort out #6310 first

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 this pull request may close these issues.

4 participants