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

client: expose a method to create a trace client to replace the delegated tracer #4758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsternberg
Copy link
Collaborator

@jsternberg jsternberg commented Mar 13, 2024

This change removes the delegated tracer and replaces it with exposing
a method to create the trace client.

The primary benefit is it separates a client functionality from server
functionality. The delegation was only used by clients and it would
often happen automatically. If you initialized a client, it would
potentially report the same traces multiple times.

For the detect functionality, it was possible to turn off delegation on
the clients by enabling tracing or metrics from there. This prevents the
detect functionality from conflicting with the client delegation so it
always works properly now.

It also refactors the delegated span exporter a bit so its usage is not
tied to the detect.Exporter() method. It also only delegates to a
single span exporter which should help prevent accidentally sending
traces multiple times to the same client.

Clients are expected to use the new method and register a separate span
processor rather than use the tracer delegate.

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

PTAL CI errors.

The downside of this seems to be that it is missing the buffer. By the time TraceClient() gets called some traces have already been written.

…ated tracer

This change removes the delegated tracer and replaces it with exposing
a method to create the trace client.

The primary benefit is it separates a client functionality from server
functionality. The delegation was only used by clients and it would
often happen automatically. If you initialized a client, it would
potentially report the same traces multiple times.

For the detect functionality, it was possible to turn off delegation on
the clients by enabling tracing or metrics from there. This prevents the
detect functionality from conflicting with the client delegation so it
always works properly now.

It also refactors the delegated span exporter a bit so its usage is not
tied to the `detect.Exporter()` method. It also only delegates to a
single span exporter which should help prevent accidentally sending
traces multiple times to the same client.

Clients are expected to use the new method and register a separate span
processor rather than use the tracer delegate.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg
Copy link
Collaborator Author

I need to do a buildx companion PR for this before this gets merged, but I've updated this to the point where it now mostly works as I intended it to.

The delegated span exporter isn't gone, but it's been moved out of the detect package to become more explicit. My vision for the detect package is it is similar to autoexport. For the initialization of the tracer and meter providers, I think that should go in application code rather than be automatically done in detect.

So the delegated span exporter is there but with a few modifications. First, it's initialized and passed to the initialization of the OTEL tracer during initialization. Second, the span exporter only allows one delegated span exporter. This was done to avoid having situations where we send a trace multiple times due to an accident. It also prevents the span exporter from having to store the initial buffer of traces forever.

The resolve client then sets the span exporter directly on the delegated span exporter. It does not try to access the tracer.

I think this should end up making this code path a bit more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants