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 OpenTracing compatibility section. #1101

Merged
Merged
Changes from 16 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1c9bc9d
Initial OpenTracing compatibility section.
carlosalberto Aug 10, 2020
bcdfb00
Fixes.
carlosalberto Aug 10, 2020
3195643
Fix typo.
carlosalberto Aug 10, 2020
92da36f
Apply feedback.
carlosalberto Aug 12, 2020
dd331ab
Fix typo.
carlosalberto Aug 12, 2020
b944a2c
Have the OT doc under a compatibility subdir.
carlosalberto Aug 14, 2020
c6027ba
Apply feedback.
carlosalberto Aug 17, 2020
272198e
Remove the read-only restriction for SpanContext values.
carlosalberto Aug 17, 2020
bf66d04
Update this PR.
carlosalberto Oct 14, 2020
36043f6
Do an improvement pass.
carlosalberto Oct 15, 2020
57ed80a
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Oct 15, 2020
d1ce668
Update the toplevel organization.
carlosalberto Oct 15, 2020
88fa597
Clarify returned values.
carlosalberto Oct 15, 2020
5c8bc99
Add a note on intention.
carlosalberto Oct 15, 2020
7ded0ce
Use Context as the container for Span/Baggage.
carlosalberto Oct 16, 2020
1567a97
Minor fixes.
carlosalberto Oct 16, 2020
155a286
Update specification/compatibility/opentracing.md
carlosalberto Dec 10, 2020
d92c209
Mention semantic conventions mapping.
carlosalberto Dec 10, 2020
597fff7
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Dec 11, 2020
e5deff1
Fix typo.
carlosalberto Dec 11, 2020
bb173ca
Improve the doc & clarify things.
carlosalberto Dec 11, 2020
a6fd708
BaggageManager is not needed anymore.
carlosalberto Dec 11, 2020
10d4ac4
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Dec 14, 2020
69d1424
More feedback.
carlosalberto Dec 16, 2020
1920d88
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Dec 16, 2020
b569ee9
Merge branch 'master' into add_ot_compatibility_new
yurishkuro Dec 27, 2020
0dff253
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Jan 6, 2021
439f484
Update specification/compatibility/opentracing.md
carlosalberto Jan 23, 2021
c18c10b
Update specification/compatibility/opentracing.md
carlosalberto Jan 23, 2021
ab02876
Merge branch 'master' into add_ot_compatibility_new
carlosalberto Jan 23, 2021
40b396c
Merge branch 'main' into add_ot_compatibility_new
carlosalberto Mar 4, 2021
d65fcdc
Merge branch 'main' into add_ot_compatibility_new
carlosalberto Mar 5, 2021
42a55e7
Add status.
carlosalberto Mar 5, 2021
c783567
Initial pass of feedback applied.
carlosalberto Mar 7, 2021
8547dc4
Automatically store Span Shim in the Context.
carlosalberto Mar 7, 2021
1fb02e6
Address Reiley's feedback.
carlosalberto Mar 7, 2021
350310f
Specify custom propagators to handle TextMap/HTTPHeaders.
carlosalberto Mar 7, 2021
1e842c7
Mention that Inject/Extract MAY indeed raise errors.
carlosalberto Mar 8, 2021
2a8dd16
Simplify the Span/SpanContext relationship explanation.
carlosalberto Mar 8, 2021
cfcb3d5
Clarify the Propagators used for Inject/Extract().
carlosalberto Mar 9, 2021
8c2d494
Fix links.
carlosalberto Mar 9, 2021
3c5f040
Merge branch 'main' into add_ot_compatibility_new
SergeyKanzhelev Mar 9, 2021
b1296a7
Merge branch 'main' into add_ot_compatibility_new
carlosalberto Mar 16, 2021
c340224
Merge branch 'main' into add_ot_compatibility_new
carlosalberto Mar 17, 2021
c2281fc
Update CHANGELOG.
carlosalberto Mar 17, 2021
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
273 changes: 273 additions & 0 deletions specification/compatibility/opentracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
# OpenTracing Compatibility

<details>
<summary>Table of Contents</summary>

carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
* [Abstract](#abstract)
* [Create an OpenTracing Tracer Shim](#create-an-opentracing-tracer-shim)
* [Tracer Shim](#tracer-shim)
* [Inject](#inject)
* [Extract](#extract)
* [Span Shim](#span-shim)
* [Get SpanContext Shim](#get-spancontext-shim-for-opentelemetry-span)
* [Set SpanContext Shim](#et-spancontext-shim-for-opentelemetry-span)
* [Get Context](#get-context)
* [Get Baggage Item](#get-baggage-item)
* [Set Baggage Item](#set-baggage-item)
* [Set Tag](#set-tag)
* [Log](#log)
* [Finish](#finish)
* [SpanContext Shim](#spancontext-shim)
* [Get Baggage Items](#get-baggage-items)
* [ScopeManager Shim](#scopemanager-shim)
* [Activate a Span](#activate-a-span)
* [Get the active Span](#get-the-active-span)

</details>

## Abstract

The OpenTelemetry project aims to provide backwards compatibility with the
[OpenTracing](https://opentracing.io) project in order to ease migration of
instrumented codebases.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

This functionality will be provided as a bridge layer implementing the
[OpenTracing API](https:/opentracing/specification) using the
OpenTelemetry API. This layer MUST NOT rely on implementation specific details
of any SDK.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

More specifically, the intention is to allow OpenTracing instrumentation to be
recorded using the OpenTelemetry API. This Shim Layer MUST NOT allow older
OpenTracing Tracing components to consume upstream OpenTelemetry functionality.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

This functionality MUST defined in its own OpenTracing Shim Layer, not in the
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
OpenTracing nor the OpenTelemetry API or SDK.

## Create an OpenTracing Tracer Shim

This operation is used to create a new OpenTracing `Tracer`:

This operation MUST accept the following parameters:

- An OpenTelemetry `Tracer`, used to create `Span`s.
- An OpenTelemetry `BaggageManager`, used to create OpenTelemetry `Baggage`
objects, required to implement the OpenTracing `Span` baggage notion.
- A set of OpenTelemetry `Propagator`s of the supported types, used to perform
context injection and extraction. Usually these are the global
`Composite Propagator`s.

The API MUST return an OpenTracing `Tracer`.

## Tracer Shim

### Inject

Parameters:

- A `SpanContext`.
- A `Format` descriptor.
- A carrier.

Inject the underlying OpenTelemetry `Span` and `Bagagge` using the registered
OpenTelemetry `Propagator`s:

- `TEXT_MAP` and `HTTP_HEADERS` formats MUST use the registered OpenTelemetry
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
`HTTPTextPropagator`, if any.

Errors MUST NOT be raised if the specified `Format` is `BINARY`.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

### Extract

Parameters:

- A `Format` descriptor.
- A carrier.

Extract OpenTelemetry `Span` and `Baggage` from a carrier using the registered
OpenTelemetry `Propagator`s:

- `TEXT_MAP` and `HTTP_HEADERS` formats MUST use the registered OpenTelemetry
`HTTPTextPropagator`, if any.

Returns a `SpanContext` Shim with the underlying extracted OpenTelemetry
`Span` and `Baggage`, or null if either the `Format` is `BINARY` or
no value could be extracted.

## Span Shim

The `Span` operations MUST be implemented using underlying OpenTelemetry `Span`
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
and `Baggage` values through a `SpanContext` Shim.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

In order to satisfy the OpenTracing `Span` requirements:
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

- The associated `SpanContext` Shim object will contain a `Context`, which
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
will contain the OpenTelemetry `Span` and `Baggage` values.
This `SpanContext` Shim MUST be immutable and MUST be replaced every time
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
baggage is updated through `SetBaggageItem`.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
- An underlying OpenTelemetry `Span` MUST be associated with only one
`SpanContext` Shim at a time for all execution units. This is done in order
to keep its baggage values consistent across all execution units at all
times.

This is a simple graphical representation of the mentioned objects:

```
Span Shim
+- OpenTelemetry Span
+- SpanContext Shim
+- OpenTelemetry Context
+- OpenTelemetry Span
+- OpenTelemetry Baggage
```

The OpenTelemetry `Span` is contained in `Span` Shim in order to easily
get and set its currently associated `SpanContext` Shim through
[Get Span Context Shim](#get-spancontext-shim-for-opentelemetry-span) and
[Set Span Context Shim](#set-spancontext-shim-for-opentelemetry-span).

The OpenTelemetry `Span` is also contained in the related OpenTelemetry
`Context` in order to simplify setting the active OpenTelemetry `Span` and
`Baggage` in a single step.

The `Log` operations MUST be implemented using the OpenTelemetry
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
`Span`'s `Add Events` operations.

The `Set Tag` operations MUST be implemented using the OpenTelemetry
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
`Span`'s `Set Attributes` operations.

### Get SpanContext Shim for OpenTelemetry Span
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

Gets the current `SpanContext` Shim for the associated OpenTelemetry `Span`.
It MUST be safe to call this operation from different execution units.

This is an INTERNAL helper operation, used by the Shim Layer only. It may
be implemented as part of `Span` Shim or as a global function.

Its implementation is language dependant. It can be implemented, for example,
as a global synchronized dictionary, or with the help of an additional attribute
in OpenTelemetry `Span` objects for dynamic languages.

### Set SpanContext Shim for OpenTelemetry Span

Parameters:

- A `SpanContext` Shim.

Sets the current `SpanContext` Shim for the associated OpenTelemetry `Span`.
It MUST be safe to call this operation from different execution units.

This is an INTERNAL helper operation, used by the Shim Layer only. It may
be implemented as part of `Span` Shim or as a global function.

Its implementation is language dependant. It can be implemented, for example,
as a global synchronized dictionary, or with the help of an additional attribute
in OpenTelemetry `Span` objects for dynamic languages.

### Get Context

Returns the current `SpanContext` Shim by calling
[Get SpanContext Shim](#get-spancontext-shim-for-opentelemetry-span).

### Get Baggage Item

Parameters:

- The baggage key, a string.

Returns a value for the specified key in the OpenTelemetry `Baggage` of the
associated `SpanContext` Shim or null if none exists.

This is accomplished by calling
[Get SpanContext Shim](#get-spancontext-shim-for-opentelemetry-span)
and do a lookup for the specified key in the associated
OpenTelemetry `Context`.

### Set Baggage Item

Parameters:

- The baggage key, a string.
- The baggage value, a string.

Creates a new `SpanContext` Shim with a new OpenTelemetry `Context` containing
the specified `Baggage` key/value pair. The resulting `SpanContext` Shim is then
passed to [Set SpanContext Shim](#set-spancontext-shim-for-opentelemetry-span).

carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
### Set Tag

Parameters:

- The tag key, a string.
- The tag value, which must be either a string, a boolean value, or a numeric type.

Calls `Set Attribute` on the underlying OpenTelemetry `Span` with the specified
key/value pair.

The value MUST be mapped to the respective OpenTelemetry `Attribute`,
or converted to a string if the value type is not supported.

If the type of the specified value is not supported, the value MUST be converted
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
to a string.

### Log

Parameters:

- A set of key/value pairs, where keys must be strings, and the values may have
any type.

Calls `Add Event` on the underlying OpenTelemetry `Span` with the specified
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
key/value pair set.

The `Add Event`'s `name` parameter MUST be the value with the `event` key in
the pair set, or else fallback to use the `log` literal string.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

The set of values MUST be mapped to the respective OpenTelemetry `Attribute`,
or converted to a string if the value type is not supported.

If an explicit timestamp is specified, a conversion MUST be done to match the
OpenTracing and OpenTelemetry units.

### Finish

Calls `End` on the underlying OpenTelemetry `Span`.

If an explicit timestamp is specified, a conversion MUST be done to match the
OpenTracing and OpenTelemetry units.

### SpanContext Shim
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

The `SpanContext` Shim MUST contain an OpenTelemetry `Context`, which will
contain the associated `Span` and `Baggage` values.

This object MUST be immutable.

#### Get Baggage Items

Returns a Shim object exposing the associated OpenTelemetry `Baggage` values.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

## ScopeManager Shim

For OpenTracing languages implementing the `ScopeManager` interface, its operations
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved
MUST be implemented using the OpenTelemetry Context Propagation API in order
to get and set active `Context` instances.

For every `Span` Shim there will be an associated `SpanContext`
Shim with an OpenTelemetry `Context`, containing the underlying OpenTelemetry
`Span` and `Bagagge` values. See [Span Shim](#span-shim) for details.

### Activate a Span

Parameters:

- A `Span`.

Gets the current `SpanContext` Shim for the specified `Span` by calling
[Get SpanContext Shim](#get-spancontext-shim-for-opentelemetry-span),
and sets its OpenTelemetry `Context` as the active instance.

### Get the active Span

Gets the active OpenTelemetry `Span` and returns a `Span` Shim wrapping it.
carlosalberto marked this conversation as resolved.
Show resolved Hide resolved

The API MUST return null if none exist.