open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.99k stars 2.32k forks source link

Feature request: `event_index` in `ottlspanevent` TransformContext #35778

Open michaelsafyan opened 4 hours ago

michaelsafyan commented 4 hours ago

Component(s)

pkg/ottl

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

I'd like to be able to use the event index in OTTL expressions.

To provide some more background, I'm trying to reuse OTTL for deriving target URIs for uploading data to blob storage (GCS, S3, Azure Blob, or elsewhere). See blobuploadconnector prototype and related issue https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33737

You can see here that I need some hackery to support event_index:

func (tracesImpl *tracesToTracesImpl) interpolateSpanEvent(
    ctx context.Context,
    pattern string,
    se *spanEventReference) (string, error) {
  // TODO: eliminate this rewriting when OTTL context for span event supports all of the required fields.
  updatedPattern := strings.ReplaceAll(pattern, "${event_index}", fmt.Sprintf("%v", se.index))
  return tracesImpl.interpolateSpanEventWithOttl(ctx, updatedPattern, se)
}

https://github.com/michaelsafyan/open-telemetry.opentelemetry-collector-contrib/blob/534d8a5dac1618001d3d3c25210fda3a03a39eff/connector/blobuploadconnector/traces.go#L379

The reason that an event index is needed is that there can be more than one event with the same name inside of a given trace span, and so the event index (in combination of the trace ID + span ID) is needed to derive a truly unique URI.

There may be other ways to derive a unique URI (like using the OTTL UUID function). However, being able to substitute in the event_index would be handy for being able to derive a more stable, predictable destination URI.

Describe the solution you'd like

Ideally, the Span Event context would know its index in the containing span and provide an event_index path.

Describe alternatives you've considered

Use functions like UUID to generate unique URIs. This, however, will lead to less predictable URIs as well as make for a less testable solution.

Additional context

No response

github-actions[bot] commented 4 hours ago

Pinging code owners: