Skip to content

Commit 25d640d

Browse files
songy23SergeyKanzhelev
authored andcommitted
Add specs on Propagator API. (#147)
* Add specs on Propagator API. Fixes #72. * Fix a bracket. * Update TOC.
1 parent e9340d7 commit 25d640d

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

specification/propagators-api.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Propagators API
2+
3+
<details>
4+
<summary>
5+
Table of Content
6+
</summary>
7+
8+
- [Binary Format](#binary-format)
9+
- [ToBytes](#tobytes)
10+
- [FromBytes](#frombytes)
11+
- [HTTP Text Format](#http-text-format)
12+
- [Fields](#fields)
13+
- [Inject](#inject)
14+
- [Setter](#setter)
15+
- [Put](#put)
16+
- [Extract](#extract)
17+
- [Getter](#getter)
18+
- [Get](#get)
19+
20+
</details>
21+
22+
Propagators API consists of two main formats:
23+
- `BinaryFormat` is used to serialize and deserialize a value into a binary representation.
24+
- `HTTPTextFormat` is used to inject and extract a value as text into carriers that travel
25+
in-band across process boundaries.
26+
27+
## Binary Format
28+
29+
`BinaryFormat` is a formatter to serialize and deserialize a value into a binary format.
30+
31+
`BinaryFormat` MUST expose the APIs that serializes values into bytes,
32+
and deserializes values from bytes.
33+
34+
### ToBytes
35+
36+
Serializes the given value into the on-the-wire representation.
37+
38+
Required arguments:
39+
- the value to serialize, can be `SpanContext` or `DistributedContext`.
40+
41+
Returns the on-the-wire byte representation of the value.
42+
43+
### FromBytes
44+
45+
Creates a value from the given on-the-wire encoded representation.
46+
47+
If the value could not be parsed, the underlying implementation SHOULD decide to return ether
48+
an empty value, an invalid value, or a valid value.
49+
50+
Required arguments:
51+
- on-the-wire byte representation of the value.
52+
53+
Returns a value deserialized from bytes.
54+
55+
## HTTP Text Format
56+
57+
`HTTPTextFormat` is a formatter that injects and extracts a value as text into carriers that
58+
travel in-band across process boundaries.
59+
60+
Encoding is expected to conform to the HTTP Header Field semantics. Values are often encoded as
61+
RPC/HTTP request headers.
62+
63+
The carrier of propagated data on both the client (injector) and server (extractor) side is
64+
usually an http request. Propagation is usually implemented via library-specific request
65+
interceptors, where the client-side injects values and the server-side extracts them.
66+
67+
`HTTPTextFormat` MUST expose the APIs that injects values into carriers,
68+
and extracts values from carriers.
69+
70+
### Fields
71+
72+
The propagation fields defined. If your carrier is reused, you should delete the fields here
73+
before calling [inject](#inject).
74+
75+
For example, if the carrier is a single-use or immutable request object, you don't need to
76+
clear fields as they couldn't have been set before. If it is a mutable, retryable object,
77+
successive calls should clear these fields first.
78+
79+
The use cases of this are:
80+
- allow pre-allocation of fields, especially in systems like gRPC Metadata
81+
- allow a single-pass over an iterator
82+
83+
Returns list of fields that will be used by this formatter.
84+
85+
### Inject
86+
87+
Injects the value downstream. For example, as http headers.
88+
89+
Required arguments:
90+
- the value to be injected, can be `SpanContext` or `DistributedContext`.
91+
- the carrier that holds propagation fields. For example, an outgoing message or http request.
92+
- the setter invoked for each propagation key to add or remove.
93+
94+
### Setter
95+
96+
`Setter` allows a `HTTPTextFormat` to set propagated fields into a carrier.
97+
98+
`Setter` MUST be stateless and allowed to be saved as a constant to avoid runtime allocations.
99+
100+
#### Put
101+
102+
Replaces a propagated field with the given value.
103+
104+
Required arguments:
105+
- the carrier holds propagation fields. For example, an outgoing message or http request.
106+
- the key of the field.
107+
- the value of the field.
108+
109+
### Extract
110+
111+
Extracts the value from upstream. For example, as http headers.
112+
113+
If the value could not be parsed, the underlying implementation will decide to return an
114+
object representing either an empty value, an invalid value, or a valid value. Implementation
115+
MUST not return null.
116+
117+
Required arguments:
118+
- the carrier holds propagation fields. For example, an outgoing message or http request.
119+
- the getter invoked for each propagation key to get.
120+
121+
Returns the non-null extracted value.
122+
123+
### Getter
124+
125+
`Getter` allows a `HttpTextFormat` to read propagated fields from a carrier.
126+
127+
`Getter` MUST be stateless and allowed to be saved as a constant to avoid runtime allocations.
128+
129+
#### Get
130+
131+
Returns the first value of the given propagation key or returns null if the key doesn't exist.
132+
133+
Required arguments:
134+
- the carrier of propagation fields, such as an http request.
135+
- the key of the field.
136+
137+
Returns the first value of the given propagation key or returns null if the key doesn't exist.

terminology.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ for an example.
227227
**TODO**: Better describe the difference between the resource and a Node
228228
https://github.com/open-telemetry/opentelemetry-proto/issues/17
229229

230+
## Propagators
231+
232+
OpenTelemetry uses `Propagators` to serialize and deserialize `SpanContext` and `DistributedContext`
233+
into a binary or text format. Currently there are two types of propagators:
234+
235+
- `BinaryFormat` which is used to serialize and deserialize a value into a binary representation.
236+
- `HTTPTextFormat` which is used to inject and extract a value as text into carriers that travel
237+
in-band across process boundaries.
238+
230239
## Agent/Collector
231240

232241
The OpenTelemetry service is a set of components that can collect traces,

0 commit comments

Comments
 (0)