Skip to content

Spec adding a span links API#620

Merged
trentm merged 5 commits intomainfrom
trentm/span-links-api
May 3, 2022
Merged

Spec adding a span links API#620
trentm merged 5 commits intomainfrom
trentm/span-links-api

Conversation

@trentm
Copy link
Copy Markdown
Member

@trentm trentm commented Mar 23, 2022

Refs: #594

Notes for reviewers

Checklist

  • May the instrumentation collect sensitive information, such as secrets or PII (ex. in headers)?
    • Yes
      • Add a section to the spec how agents should apply sanitization (such as sanitize_field_names)
    • No
      • Why? Span links only include trace and span IDs.
    • n/a
  • Link to meta issue: Spec adding a span links API #594
  • Create PR as draft
  • Approval by at least one other agent
  • Mark as Ready for Review (automatically requests reviews from all agents and PM via CODEOWNERS)
    • Remove PM from reviewers if impact on product is negligible
    • Remove agents from reviewers if the change is not relevant for them
  • Approved by at least 2 agents + PM (if relevant)
  • Merge after 7 days passed without objections
  • Create implementation issues through the meta issue template (this will automate issue creation for individual agents)

@trentm trentm self-assigned this Mar 23, 2022
@ghost
Copy link
Copy Markdown

ghost commented Mar 23, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-02T04:32:00.078+0000

  • Duration: 3 min 48 sec

@trentm
Copy link
Copy Markdown
Member Author

trentm commented Mar 23, 2022

The following are some comments/notes on how each of the APM agent APIs could add span links support, if it is decided that is worthwhile for each language agent. Do not take these as requirements at all -- you all know the various APM agents better than I.

Node.js APM agent

Here is the OTel API:

The addition to the Node.js APM agent public API could be:

  // Link, Attributes, and `links` are intended to be compatible with OTel's
  // equivalent APIs in "opentelemetry-js-api/src/trace/link.ts", with the
  // exception that attributes are not yet accepted.
  export interface Link {
    /** A traceparent-format string, Transaction, or Span. */
    context: Transaction | Span | string; // This is a SpanContext in OTel.
  }

  export interface TransactionOptions {
    startTime?: number;
    childOf?: Transaction | Span | string;
    links?: Link[];
  }

  export interface SpanOptions {
    startTime?: number;
    childOf?: Transaction | Span | string;
    links?: Link[];
    exitSpan?: boolean;
  }

The context here mirrors the existing childOf option to startSpan(...)
that encapsulates the needed link data. OTel has a SpanContext object that
encapsulates this data.

Usage in JS code would look something like:

const span = apm.startSpan("my-span-name", {
  links: [{ context: record.messageAttributes.traceparent }]
})

The following was considered and rejected: Minimally the API could be reduced to the following. However, that means supporting two different calling forms if/when attributes are supported, which is unnecessarily complexity for a rarely used option.

const span = apm.startSpan("my-span-name", {
  links: [record.messageAttributes.traceparent]
})

@trentm
Copy link
Copy Markdown
Member Author

trentm commented Mar 23, 2022

Python APM agent

In opentelemetry-python/../src/opentelemetry/trace/__init__.py the start span API is:

    @abstractmethod
    def start_span(
        self,
        name: str,
        context: Optional[Context] = None,
        links: _Links = None,
        ...
    ) -> "Span":

    @contextmanager
    @abstractmethod
    def start_as_current_span(
        self,
        name: str,
        context: Optional[Context] = None,
        links: _Links = None,
        ...
    ) -> Iterator["Span"]:

# where `_Links` is basically (modulo some typings) a list of:

class Link:
    def __init__(self, context, attributes):
        # ...

The Python APM agent could perhaps add a similar links argument to elasticapm.capture_span and elasticapm.async_capture_span. Also to Client.begin_transaction()?

@trentm
Copy link
Copy Markdown
Member Author

trentm commented Mar 23, 2022

Go APM agent

Presumably a links could be added to SpanOptions (and TransactionOptions?) similar to OTel's SpanConfig, though the Link struct would differ.

type SpanOptions struct {
  // ...
  links      []Link
}

Comment thread specs/agents/tracing-api-otel.md
Comment thread specs/agents/span-links-tmp.md Outdated
Comment thread specs/agents/span-links-tmp.md Outdated
that the APM agent does not or cannot instrument. (For some agents it would be
a burden to internally support span links and *not* expose the API publicly.)

TODO: For the .NET APM agent is there much value in providing a public API to add span links? Perhaps usage of the Activity API and the OTel Bridge dominates?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not say that the Activity API dominates... it gets adaption, but it's far from being widely used.

I see the other command regarding Java - our .NET API is similar in a sense that long term we expect Activity being the primary API for manual instrumentation. We haven't discussed span links specifically for .NET yet.

It's not a huge effort to add this to the public API, so at this point I'd lean towards adding it to our public API in .NET.

Comment thread specs/agents/span-links-tmp.md Outdated
@@ -0,0 +1,18 @@
TODO: this content will be appended to "span-links.md" when that file is added in https://github.com/elastic/apm/pull/600
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEW NOTE: This will be done after #600 goes in.

@trentm trentm marked this pull request as ready for review April 5, 2022 21:29
@trentm trentm requested review from a team as code owners April 5, 2022 21:29
@trentm trentm removed request for a team April 5, 2022 21:29
@felixbarny felixbarny linked an issue Apr 21, 2022 that may be closed by this pull request
@trentm trentm merged commit ccb2e0e into main May 3, 2022
@trentm trentm deleted the trentm/span-links-api branch May 3, 2022 19:02
@trentm trentm mentioned this pull request May 3, 2022
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spec adding a span links API

6 participants