Skip to content

Commit 3a1dde9

Browse files
Add a new AddLink() operation to Span. (#3678)
Fixes #454 Related to #3337 As the Messaging SIG merged its last OTEP 222, we will be adding operations that require Links after Span creation, taking a direct route with `AddLink()`, albeit without any of the new members suggested in #3337, e.g. `timestamp` (to be discussed in a separate issue). ``` AddLink(spanContext, attributes /* optional */) ```
1 parent c517f62 commit 3a1dde9

File tree

6 files changed

+55
-27
lines changed

6 files changed

+55
-27
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ release.
1111

1212
### Traces
1313

14+
- Add a new AddLink() operation to Span (experimental).
15+
([#3678](https://github.com/open-telemetry/opentelemetry-specification/pull/3678))
16+
1417
### Metrics
1518

1619
### Logs

spec-compliance-matrix.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ formats is required. Implementing more than one format is optional.
6767
| Unicode support for keys and string values | | + | + | + | + | + | + | + | + | + | + | + |
6868
| [Span linking](specification/trace/api.md#specifying-links) | Optional | Go | Java | JS | Python | Ruby | Erlang | PHP | Rust | C++ | .NET | Swift |
6969
| Links can be recorded on span creation | | + | + | | + | + | + | + | + | + | + | |
70+
| Links can be recorded after span creation | | | | | | | | | | | | |
7071
| Links order is preserved | | + | + | | + | + | + | + | + | + | + | |
7172
| [Span events](specification/trace/api.md#add-events) | | | | | | | | | | | | |
7273
| AddEvent | | + | + | + | + | + | + | + | + | + | + | + |

specification/common/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ at this time, as discussed in
123123
[data points](../metrics/data-model.md#metric-points),
124124
[Spans](../trace/api.md#set-attributes), Span
125125
[Events](../trace/api.md#add-events), Span
126-
[Links](../trace/api.md#specifying-links) and
126+
[Links](../trace/api.md#link) and
127127
[Log Records](../logs/data-model.md) may contain a collection of attributes. The
128128
keys in each such collection are unique, i.e. there MUST NOT exist more than one
129129
key-value pair with the same key. The enforcement of uniqueness may be performed

specification/compatibility/opencensus.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ using the OpenCensus <-> OpenTelemetry bridge.
180180
This leads to some issues with OpenCensus APIs that allowed flexible
181181
specification of parent spans post-initialization.
182182
2. Links added to spans after the spans are created. This is [not supported in
183-
OpenTelemetry](../trace/api.md#specifying-links), therefore OpenCensus spans
183+
OpenTelemetry](../trace/api.md#link), therefore OpenCensus spans
184184
that have links added to them after creation will be mapped to OpenTelemetry
185185
spans without the links.
186186
3. OpenTelemetry specifies that samplers are

specification/compatibility/opentracing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ OpenTracing defines two types of references:
544544

545545
OpenTelemetry does not define strict equivalent semantics for these
546546
references. These reference types must not be confused with the
547-
[Link](../trace/api.md#specifying-links) functionality. This information
547+
[Link](../trace/api.md#link) functionality. This information
548548
is however preserved as the `opentracing.ref_type` attribute.
549549

550550
## In process Propagation exceptions

specification/trace/api.md

+48-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ linkTitle: API
44

55
# Tracing API
66

7-
**Status**: [Stable, Feature-freeze](../document-status.md)
7+
**Status**: [Stable, Feature-freeze](../document-status.md), except where otherwise specified
88

99
<details>
1010
<summary>Table of Contents</summary>
@@ -35,13 +35,15 @@ linkTitle: API
3535
+ [IsRecording](#isrecording)
3636
+ [Set Attributes](#set-attributes)
3737
+ [Add Events](#add-events)
38+
+ [Add Link](#add-link)
3839
+ [Set Status](#set-status)
3940
+ [UpdateName](#updatename)
4041
+ [End](#end)
4142
+ [Record Exception](#record-exception)
4243
* [Span lifetime](#span-lifetime)
4344
* [Wrapping a SpanContext in a Span](#wrapping-a-spancontext-in-a-span)
4445
- [SpanKind](#spankind)
46+
- [Link](#link)
4547
- [Concurrency](#concurrency)
4648
- [Included Propagators](#included-propagators)
4749
- [Behavior of the API in the absence of an installed SDK](#behavior-of-the-api-in-the-absence-of-an-installed-sdk)
@@ -300,7 +302,7 @@ the entire operation and, optionally, one or more sub-spans for its sub-operatio
300302
- A start timestamp
301303
- An end timestamp
302304
- [`Attributes`](../common/README.md#attribute)
303-
- A list of [`Link`s](#specifying-links) to other `Span`s
305+
- A list of [`Link`s](#link) to other `Span`s
304306
- A list of timestamped [`Event`s](#add-events)
305307
- A [`Status`](#set-status).
306308

@@ -386,7 +388,7 @@ The API MUST accept the following parameters:
386388
to calling `SetAttribute` later, as samplers can only consider information
387389
already present during span creation.
388390

389-
- `Link`s - an ordered sequence of Links, see API definition [here](#specifying-links).
391+
- `Link`s - an ordered sequence of Links, see [API definition](#link).
390392
- `Start timestamp`, default to current time. This argument SHOULD only be set
391393
when span creation time has already passed. If API is called at a moment of
392394
a Span logical start, API user MUST NOT explicitly set this argument.
@@ -423,27 +425,10 @@ For example, a `Propagator` performing context extraction may need this.
423425

424426
#### Specifying links
425427

426-
During `Span` creation, a user MUST have the ability to record links to other
427-
`Span`s. Linked `Span`s can be from the same or a different trace -- see [Links
428-
between spans](../overview.md#links-between-spans). `Link`s cannot be added after
429-
Span creation.
430-
431-
A `Link` is structurally defined by the following properties:
432-
433-
- `SpanContext` of the `Span` to link to.
434-
- Zero or more [`Attributes`](../common/README.md#attribute) further describing
435-
the link.
436-
437-
The Span creation API MUST provide:
438-
439-
- An API to record a single `Link` where the `Link` properties are passed as
440-
arguments. This MAY be called `AddLink`. This API takes the `SpanContext` of
441-
the `Span` to link to and optional `Attributes`, either as individual
442-
parameters or as an immutable object encapsulating them, whichever is most
443-
appropriate for the language. Implementations MAY ignore links with an
444-
[invalid](#isvalid) `SpanContext`.
445-
446-
Links SHOULD preserve the order in which they're set.
428+
During `Span` creation, a user MUST have the ability to record links to other `Span`s.
429+
Linked `Span`s can be from the same or a different trace -- see [links](#link).
430+
`Link`s added at `Span` creation may be considered by [Samplers](sdk.md#sampler)
431+
to make a sampling decision.
447432

448433
### Span operations
449434

@@ -556,6 +541,13 @@ keys"](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/REA
556541
Note that [`RecordException`](#record-exception) is a specialized variant of
557542
`AddEvent` for recording exception events.
558543

544+
#### Add Link
545+
546+
**Status**: [Experimental](../document-status.md)
547+
548+
A `Span` MUST have the ability to add `Link`s associated with it after its creation - see [Links](#link).
549+
`Link`s added after `Span` creation may not be considered by [Samplers](sdk.md#sampler).
550+
559551
#### Set Status
560552

561553
Sets the `Status` of the `Span`. If used, this will override the default `Span`
@@ -797,6 +789,38 @@ To summarize the interpretation of these kinds:
797789
| `CONSUMER` | | yes | maybe | |
798790
| `INTERNAL` | | | | |
799791

792+
## Link
793+
794+
A user MUST have the ability to record links to other `SpanContext`s.
795+
Linked `SpanContext`s can be from the same or a different trace -- see [Links
796+
between spans](../overview.md#links-between-spans).
797+
798+
A `Link` is structurally defined by the following properties:
799+
800+
- `SpanContext` of the `Span` to link to.
801+
- Zero or more [`Attributes`](../common/README.md#attribute) further describing
802+
the link.
803+
804+
The API MUST provide:
805+
806+
- An API to record a single `Link` where the `Link` properties are passed as
807+
arguments. This MAY be called `AddLink`. This API takes the `SpanContext` of
808+
the `Span` to link to and optional `Attributes`, either as individual
809+
parameters or as an immutable object encapsulating them, whichever is most
810+
appropriate for the language. Implementations MAY ignore links with an
811+
[invalid](#isvalid) `SpanContext`.
812+
813+
The Span interface MAY provide:
814+
815+
- An API to add multiple `Link`s at once, where the `Link`s are passed in a
816+
single method call.
817+
818+
Span SHOULD preserve the order in which `Link`s are set.
819+
820+
The API documentation MUST state that adding links at span creation is preferred
821+
to calling `AddLink` later, for contexts that are available during span creation,
822+
because head sampling decisions can only consider information present during span creation.
823+
800824
## Concurrency
801825

802826
For languages which support concurrent execution the Tracing APIs provide

0 commit comments

Comments
 (0)