Skip to content

Support OTEL span links #3474

@jsumners-nr

Description

@jsumners-nr

https://newrelic.atlassian.net/wiki/spaces/INST/pages/4667998813/Agent+Support+for+Span+Links+and+Events

Open Telemetry defines the concept of "span links." Span links are metadata that tie a message entity to the span that generated them. Consider a message queuing system like Amazon SQS. In such a system, an application can post one or many messages at once. This posting will occur in one or multiple transactions. Another, or the same, application may then retrieve messages from this queue, typically as a batch of messages. The order in which the messages are retrieved is not guaranteed; which is to say, one retrieval may include messages that were generated from multiple different transactions. These messages will include metadata that details the transaction identifiers. This metadata should then be used to "link" the messages back to their original transaction just as a baseline distributed trace between synchronous services does.

We need to update our OTEL support to recognize spans that have been tagged with span link data, and replicate it through our standard New Relic system through attribute mapping.

We map OTEL spans to NR spans in:

switch (rule.type) {
case 'consumer': {
return createConsumerSegment(this.agent, otelSpan, rule)
}
case 'db': {
return createDbSegment(this.agent, otelSpan, rule)
}
case 'external': {
return createHttpExternalSegment(this.agent, otelSpan, rule, this.logger)
}
case 'internal': {
return createInternalSegment(this.agent, otelSpan, rule)
}
case 'producer': {
return createProducerSegment(this.agent, otelSpan, rule)
}
case 'server': {
return createServerSegment(this.agent, otelSpan, rule)
}
default: {
this.logger.debug('Found type: %s, no synthesis rule currently built', rule.type)
}
}

OTEL spans that have link data have a .links property set to an array of links. See:

  1. https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-node.node.ReadableSpan.html
  2. https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-node._opentelemetry_api.Link.html

Utilizing that information, we will update the NR span with the following attributes:

  • type (string): must be set to SpanLink.
  • timestamp (number): milliseconds epoch relative. Given that the interface for a Link does not specify a timestamp field being available, this must be derived from the startTime of the containing Span.
  • id (string): the identifier of the containing Span (span.context.spanId).
  • trace.id (string): the trace identifier of the containing Span (span.context.traceId).
  • linkedSpanId (string): the linked span identifier of the upstream span (e.g. span.links[0].context.spanId).
  • linkedTraceId (string): the linked span trace identifier of the upstream span (e.g. span.links[0].context.traceId).

Any attributes defined on the link may be added as custom attributes, e.g. span.links[0].attributes.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In progress: Issues being worked on

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions