Skip to content

Optionally add baggage to span attributes#8023

Closed
adamleantech wants to merge 3 commits into
open-telemetry:mainfrom
adamleantech:add-baggage-to-spans
Closed

Optionally add baggage to span attributes#8023
adamleantech wants to merge 3 commits into
open-telemetry:mainfrom
adamleantech:add-baggage-to-spans

Conversation

@adamleantech

@adamleantech adamleantech commented Mar 10, 2023

Copy link
Copy Markdown
Contributor

resolves #4520

@adamleantech adamleantech marked this pull request as ready for review March 10, 2023 13:08
@adamleantech adamleantech requested a review from a team March 10, 2023 13:08
@laurit

laurit commented Mar 10, 2023

Copy link
Copy Markdown
Contributor

Did you consider using a SpanProcessor for this?

@adamleantech

Copy link
Copy Markdown
Contributor Author

@laurit good suggestion, I wasn't aware of that

@adamleantech adamleantech force-pushed the add-baggage-to-spans branch from 064765a to 6443b85 Compare March 16, 2023 11:39
@adamleantech adamleantech force-pushed the add-baggage-to-spans branch from 6443b85 to 4afc902 Compare March 16, 2023 12:04
@adamleantech

Copy link
Copy Markdown
Contributor Author

@laurit updated PR as per your suggestion. I've realised that there is probably an issue with my previous PR for logback MDC in that the "baggage." prefix should be on the key not the value

@laurit

laurit commented Mar 16, 2023

Copy link
Copy Markdown
Contributor

@adamleantech thanks for reporting, I'll fix it

@AutoService(AutoConfigurationCustomizerProvider.class)
public class AgentTracerProviderConfigurer implements AutoConfigurationCustomizerProvider {
private static final String ADD_THREAD_DETAILS = "otel.javaagent.add-thread-details";
private static final String ADD_BAGGAGE = "otel.javaagent.span.add-baggage";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this would correspond with, e.g. otel.traces.exporter, otel.metrics.exporter, otel.logs.exporter

Suggested change
private static final String ADD_BAGGAGE = "otel.javaagent.span.add-baggage";
private static final String ADD_BAGGAGE = "otel.javaagent.traces.add-baggage";

@trask trask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if otel.javaagent.span.add-baggage should take a list of baggage to add (or * for all), this would match otel.instrumentation.logback-appender.experimental.capture-mdc-attributes

@trask

trask commented Apr 13, 2023

Copy link
Copy Markdown
Member

I wonder if otel.javaagent.span.add-baggage should take a list of baggage to add (or * for all), this would match otel.instrumentation.logback-appender.experimental.capture-mdc-attributes

and maybe we should do the same for otel.instrumentation.logback-mdc.add-baggage?

@evantorrie

Copy link
Copy Markdown
Contributor

I'm interested in this same functionality but for use as an AutoConfigureSpi addition to a manually instrumented program (which uses the AutoConfigure SDK extension).

Is there anything which ties AgentTracerProviderConfigurer to the java agent (other than the name?).

Not for this PR obviously, but I wonder if this and AddThreadDetailsSpanProcessor could be relocated into the https://github.com/open-telemetry/opentelemetry-java repo as some sort of sdk-extension-customizer artifact?

@breedx-splk

breedx-splk commented Jul 10, 2023

Copy link
Copy Markdown
Contributor

Is there anything which ties AgentTracerProviderConfigurer to the java agent (other than the name?).

Yeah, this configurer is coupled to the agent through the AgentConfig as well...but I think there's room for that to be a separate responsibility (separate PR).

Not for this PR obviously, but I wonder if this and AddThreadDetailsSpanProcessor could be relocated into the https://github.com/open-telemetry/opentelemetry-java repo as some sort of sdk-extension-customizer artifact?

I am liking this idea. @jack-berg and @jkwatson what do you think? Is there room for add-on processors like this in the core repo, or would you prefer to see it as a contrib addition, or something else?

@jack-berg

Copy link
Copy Markdown
Member

Contrib is the appropriate place for this. If such a processor were to occur in the spec, we could promote that component the core repo.

@galbash

galbash commented Nov 19, 2023

Copy link
Copy Markdown

Has this been contributed to the contrib repo / exists on the java agent?

@trask

trask commented Nov 28, 2023

Copy link
Copy Markdown
Member

Has this been contributed to the contrib repo / exists on the java agent?

not yet

span.setAttribute(
// add prefix to key to not override existing attributes
"baggage." + key,
value.getValue()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Given the lack of spec around this topic, it would be good to keep the attribute naming flexible and have the baggage namespace prefix come in through the constructor as an optional parameter. The suggested whitelisting of baggage keys to attach would provide the necessary security to prevent unwanted overrides.

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.

Automatically append baggage entries to span attributes

8 participants