Skip to content

Intercept OTEL span links through .addLink #3601

@jsumners-nr

Description

@jsumners-nr

While implementing #3474, I missed that the Span object has an .addLink method to allow adding of links during the lifetime of the span. The implementation for #3474 handles the links present at creation of the span. While it is recommended to only add links at creation, the reality is that links can be added subsequent to creation and we need to account for those.

We need to update our span onStart method to intercept the .addLink method on the span to handle in-flight links. It will likely look something like:

onStart(span) {
  span[otelSynthesis] = this.synthesizer.synthesize(span)
  const { segment } = span[otelSynthesis]
  
  const addLink = span.addLink
  span.addLink = function nrAddLink(link) {
    const nrLink = new SpanLink({ link, context: span.spanContext(), timestamp: span.startTime })
    segment.addSpanLink(nrLink)
    addLink.call(span, link)
  }

  const addLinks = span.addLinks
  span.addLinks = function nrAddLinks(links) {
    for (const link of links) { span.addLink(link) }
  }
}

onStart(span) {
span[otelSynthesis] = this.synthesizer.synthesize(span)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    To do: In current sprint

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions