opentelemetry-ruby icon indicating copy to clipboard operation
opentelemetry-ruby copied to clipboard

SpanKind immutable to SpanProcessors

Open 0robustus1 opened this issue 3 months ago • 5 comments

The SpanKind (span.kind) is inherently considered immutable and only to be set on Span creation. However a SpanProcessor should be able to essentially perform any kind of change to Spans (especially on the on_start and on_finishing methods).

Currently there is no way to adjust the kind within a Span processor without resulting to unsafe Ruby core functionality (e.g. span.instance_variable_set(:@kind, ::OpenTelemetry::Trace::SpanKind::CONSUMER)). It would be better if there were a dedicated way for a SpanProcessor to adjust the kind.

0robustus1 avatar Oct 09 '25 06:10 0robustus1

This would be an API change that would IMHO need to be described in the specification first.

dmathieu avatar Oct 09 '25 07:10 dmathieu

I found this in the spec:

A Span’s start time SHOULD be set to the current time on span creation. After the Span is created, it SHOULD be possible to change its name, set its Attributes, add Events, and set the Status. These MUST NOT be changed after the Span’s end time has been set. From: https://opentelemetry.io/docs/specs/otel/trace/api/#span

It doesn't seem to state anything about SpanKind after initialization. One could take this to mean that it is immutable (because it isn't explicitly stated to be changeable). One could also take this to mean that it just plainly isn't specified. I couldn't find another section of the Spec that mentions it. Do you by chance have a reference link?

0robustus1 avatar Oct 09 '25 09:10 0robustus1

It's not described in Span Operations: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#span-operations

dmathieu avatar Oct 09 '25 09:10 dmathieu

@0robustus1, can you share more about the situation(s) you're seeing in which the span.kind is not known at span start?

robbkidd avatar Oct 15 '25 12:10 robbkidd

👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this issue will be closed eventually by the stale bot.

github-actions[bot] avatar Nov 15 '25 02:11 github-actions[bot]