eclipse-vertx / vertx-tracing

Vertx integration with tracing libraries
Other
42 stars 34 forks source link

Allow Adding Custom Span Attributes Before `startSpan()` #63

Open tboonIV opened 1 year ago

tboonIV commented 1 year ago

Describe the feature

In order to use OpenTelemetry Head Sampling based on specific data information, I can extract the data upfront and set into Span Attribute before startSpan() for Head Sampling working with my custom Attribute.

tracer.spanBuilder("my.class")
      .setAttribute("custom", "123")
      .startSpan();

But in Vertx OpenTelemetry Tracing, there is no way for me to configure or intercept how to insert my own Attributes into Span before startSpan().

Using Span.current() is not working for me as the Span only initialize in Vertx low level implementation when request is received.

For what I observe, the TagExtractor used for Attributes building and it's fixed from Vert.x core. https://github.com/eclipse-vertx/vertx-tracing/blob/master/vertx-opentelemetry/src/main/java/io/vertx/tracing/opentelemetry/OpenTelemetryTracer.java#L148-L154 https://github.com/eclipse-vertx/vert.x/blob/3e9d5d151e0bb91825fb214d94e72f645c0d6e60/src/main/java/io/vertx/core/http/impl/HttpUtils.java#L69-L163

Will be greats if we can have some control the Span Attributes before it start, so Head Sampling can be much useful.

Use cases

We have the data before it sent out as request and wanted to use it to perform OpenTelemetry Trace filtering.

Contribution

I may try to contribute but need some insight which is best approach to implement this.

tsegismont commented 1 year ago

What kind of attributes do you need to add? Computed on startup or when a request/message is received?

tboonIV commented 1 year ago

What kind of attributes do you need to add? Computed on startup or when a request/message is received?

When a request/message is received. String value for now I want to insert into, which will use for head sampling.