Skip to content

How to stamp a "tenant id" attribute on all spans? #3456

@trask

Description

@trask

Is your feature request related to a problem? Please describe.

I want to stamp a "tenant id" attribute on all spans.

Describe the solution you'd like

Open to suggestions.

One option that I think would work well is to build a SpanProcessor, and onStart(), copy the "tenant id" attribute from the parent span down to the new span.

Then the application can stamp the "tenant id" on the SERVER span in a servlet filter, and it will get propagated down to all spans, including auto-instrumentation spans (if you register the SpanProcessor via new javaagent extension mechanism).

Currently though this would require calling toSpanData() on the active parent span which is expensive, so if going this route I'd like to see if it's ok to add a getAttribute(AttributeKey) method to ReadableSpan.

Describe alternatives you've considered

Another option is to put the "tenant id" into the Context, and have a SpanProcessor that copies the "tenant id" into the new span.

The main problem with this approach is that it doesn't work great with the javaagent because the ContextKey can't easily be shared between the application that is putting the "tenant id" into the Context and the SpanProcessor that lives in the javaagent (extension).

A possible mitigation to this problem is to put the "tenant id" context key into the bootstrap class loader, which is possible now via extensions, but this starts to feel like a pretty complex solution to a simple-ish use case.

Yet another option is to put the "tenant id" into baggage, which would not have the javaagent problem that custom context keys have. But there are no controls on baggage propagation over the wire (except to disable it completely), which makes me hesitant to recommend this as a general solution to this use case.

Additional context

I believe this is similar use case to open-telemetry/opentelemetry-specification#1337

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestSuggest an idea for this project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions