Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RecordLink for Span. #3240

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions semantic_conventions/trace/link.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
groups:
- id: trace-link
type: event
prefix: link
brief: >
This document defines the shared attributes used to
report a soft link associated with a span.
attributes:
- id: traceid
type: string
brief: >
The lowercase hex encoded trace id, as
[retrieved](../api.md#retrieving-the-traceid-and-spanid)
by `SpanContext`.
examples: 'af9d5aa4-a685-4c5f-a22b-444f80b3cc28'
- id: spanid
type: string
brief: >
The lowercase hex encoded span id, as
[retrieved](../api.md#retrieving-the-traceid-and-spanid)
by `SpanContext`.
examples: 'af9d5aa4-a685-4c5f-a22b-444f80b3cc28'
- id: tracestate
Copy link
Contributor

Choose a reason for hiding this comment

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

trace-flags? otherwise we don't know if it was recorded on the other service

Copy link
Member

Choose a reason for hiding this comment

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

Sounds useful, although I think you could make the same argument for our normal parent-child relationships (maybe we should actually add a parent_flags to the OTLP span?)

type: string
brief: >
The trace state, as specified in the
[API](../api.md#tracestate).
examples: 'congo=t61rcWkgMzE'

21 changes: 21 additions & 0 deletions specification/trace/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
+ [UpdateName](#updatename)
+ [End](#end)
+ [Record Exception](#record-exception)
+ [Record Link](#record-link)
* [Span lifetime](#span-lifetime)
* [Wrapping a SpanContext in a Span](#wrapping-a-spancontext-in-a-span)
- [SpanKind](#spankind)
Expand Down Expand Up @@ -691,6 +692,26 @@ Note: `RecordException` may be seen as a variant of `AddEvent` with
additional exception-specific parameters and all other parameters being optional
(because they have defaults from the exception semantic convention).

#### Record Link
Copy link
Member

Choose a reason for hiding this comment

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

Probably too early to spark a naming discussion but I think span.RecordLink(ctx, attrs) would be very misleading and should rather be called RecordLinkAs(Span)Event or the like, since the outcome will not be a Span Link as one might expect from the name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we go down the path of recording links as events after span starts, we'd eventually replace original links with events too. If that happens, we'd regret naming it as RecordLinkAs(Span)Event.


To facilitate registering `Link` relationships after a `Span` has been already
created, languages SHOULD provide an `RecordLink` method. This is a specialized
variant of [`AddEvent`](#add-events), so for anything not specified here, the same
requirements as for `AddEvent` apply.

The method MUST record a `Link` as an `Event` with the conventions outlined in
the [link semantic conventions](semantic_conventions/links.md) document.
The minimum required argument SHOULD be no more than only a `SpanContext`.

If `RecordLink` is provided, the method MUST accept an optional parameter
to provide any additional event attributes
(this SHOULD be done in the same way as for the `AddEvent` method).
If attributes with the same name would be generated by the method already,
the additional attributes take precedence.

Note: `RecordLink` may be seen as a variant of `AddEvent` with
additional link-specific parameters.

### Span lifetime

Span lifetime represents the process of recording the start and the end
Expand Down
45 changes: 45 additions & 0 deletions specification/trace/semantic_conventions/links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Semantic Conventions for Links
Copy link
Member

Choose a reason for hiding this comment

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

Please add this new file to the TOC in README.md


**Status**: [Experimental](../../document-status.md)

This document defines semantic conventions for recording soft
links.

<!-- toc -->

- [Recording a Link](#recording-a-link)
- [Attributes](#attributes)

<!-- tocstop -->

## Recording a Link

A `Link` SHOULD be recorded as an `Event` on the span during which it occurred.
The name of the event MUST be `"link"`.

A typical template for an instrumentation implementing this semantic convention
using an [API-provided `recordLink` method](../api.md#record-link)
could look like this (pseudo-Java):

```java
Span span = myTracer.startSpan(/*...*/);
// Code that does actual work which the Span represents.

SpanContext producerSpanContext = getProducerSpanContext();
span.recordLink(producerSpanContext, Attributes.of("messaging.source.kind", "queue"));
```

## Attributes

The table below indicates which attributes should be added to the `Event` and
their types.

<!-- semconv trace-link -->
The event name MUST be `link`.

| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| `link.traceid` | string | The lowercase hex encoded trace id, as [retrieved](../api.md#retrieving-the-traceid-and-spanid) by `SpanContext`. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | Recommended |
| `link.spanid` | string | The lowercase hex encoded span id, as [retrieved](../api.md#retrieving-the-traceid-and-spanid) by `SpanContext`. | `af9d5aa4-a685-4c5f-a22b-444f80b3cc28` | Recommended |
| `link.tracestate` | string | The trace state, as specified in the [API](../api.md#tracestate). | `congo=t61rcWkgMzE` | Recommended |
<!-- endsemconv -->