[Feature]: Move SpanLimits
to opentelemetry
and use the limits in SpanBuilder
#1533
Labels
SpanLimits
to opentelemetry
and use the limits in SpanBuilder
#1533
Related Problems?
The
tracing-opentelemetry
library usesSpanBuilder
to create spans and puts events in there, but if there are more than the configured limit, these are kept around, ignored byTracer
when a span is actually built and then discarded.This can be an issue especially for long-running spans with much larger number of events than the limit as they are effectively just leaking memory.
Describe the solution you'd like:
SpanBuilder
can already take the limits into account. It is built by aTracer
which holds the limits internally so it can configured the builder.Considered Alternatives
A provided method could also be added to the
Tracer
trait to expose the limits, such asfn span_limits(&self) -> Option<SpanLimits> { None }
where implementations can override that with their actual limits, if they implement them. Then a library such astracing-opentelemetry
can discard the events as they come.I think it would be better for to keep the filtering inside
opentelemetry-rust
itself. But if there is a desire to keepSpanBuilder
as simple as possible, or breaking changes to it would be undesirable, this could also be an option.Additional Context
Breaking Changes
Part of this would be moving
SpanLimits
intoopentelemetry
, which could be done in non-breaking way with a reexport fromopentelemetry-sdk
.Changing the internals of
SpanBuilder
would be a breaking change since all its fields are publicly available.Adding a method with a default implementation to the trait should be non-breaking, if the name does not clash with other methods on implementing types or traits they implement.
Runtime Changes to
SpanLimits
According to the spec, the span limits configuration must be owned by the provider and the sdk may proivde a way to change them during runtime, where the change is visible in all tracers including those created before the change.
However, I have not found any information about when the limits should be applied, i.e. if the change should also be visible in already created spans or if limiting in helper structures such as the
SpanBuilder
is even permitted. This proposal would use the limits present at the time ofSpanBuilder
creation and also at the time of building the span, effectively taking the lower of the two. Currently, only the latter is applied.Note that
opentelemetry-rust
does not allow chaning the limits after aTracerProvider
is built, so this section is here only so that this proposed change does not prevent future improvements.API vs SDK
SpanLimits
SpanLimits
are defined in OpenTelemetry trace SDK, not API, so exposing it might be a no-go based on that and considerations of #1042The text was updated successfully, but these errors were encountered: