Skip to content

Record OTEL status value on spans #3597

@jsumners-nr

Description

@jsumners-nr

Spec PR 766 clarifies that agents must record Open Telemetry's "status" value as agent attributes on recorded spans.

When the span ends, we must update the agent attributes:

let code
switch (span.status.code) {
  case 0: { code = 'unset'; break; }
  case 1: { code = 'ok'; break; }
  case 2: { code = 'error'; break; }
}
segment.addAttribute('status.code', code)
if (code === 'error') {
  segment.addAttribute('status.description', span.status.message)
}

onEnd(span) {
if (span[otelSynthesis] && span[otelSynthesis].segment) {
const { segment, transaction, rule } = span[otelSynthesis]
const { instrumentationScope } = span
// We always attach the instrumentation scope data as agent attributes
// if the OTEL span has them set.
// See https://opentelemetry.io/docs/specs/otel/common/mapping-to-non-otlp/#instrumentationscope
if (typeof instrumentationScope.name === 'string') {
segment.addAttribute('otel.scope.name', instrumentationScope.name)
segment.addAttribute('otel.library.name', instrumentationScope.name)
}
if (typeof instrumentationScope.version === 'string') {
segment.addAttribute('otel.scope.version', instrumentationScope.version)
segment.addAttribute('otel.library.version', instrumentationScope.version)
}
this.updateDuration(segment, span)
this.handleError({ segment, transaction, span })
this.reconcileAttributes({ segment, span, transaction, rule })
delete span[otelSynthesis]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Triage Needed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions