|
| 1 | +# Baggage API |
| 2 | + |
| 3 | +<details> |
| 4 | +<summary> |
| 5 | +Table of Contents |
| 6 | +</summary> |
| 7 | + |
| 8 | +- [Overview](#overview) |
| 9 | + - [Baggage](#baggage) |
| 10 | + - [Get baggages](#get-all) |
| 11 | + - [Get baggage](#get-baggage) |
| 12 | + - [Set baggage](#set-baggage) |
| 13 | + - [Remove baggage](#remove-baggage) |
| 14 | + - [Clear](#clear) |
| 15 | +- [Baggage Propagation](#baggage-propagation) |
| 16 | + - [Serialization](#serialization) |
| 17 | +- [Conflict Resolution](#conflict-resolution) |
| 18 | + |
| 19 | +</details> |
| 20 | + |
| 21 | +## Overview |
| 22 | + |
| 23 | +The Baggage API consists of: |
| 24 | + |
| 25 | +- the `Baggage` |
| 26 | +- functions to interact with the `Baggage` in a `Context` |
| 27 | + |
| 28 | +### Baggage |
| 29 | + |
| 30 | +`Baggage` is used to annotate telemetry, adding context and information to metrics, traces, and logs. |
| 31 | +It is an abstract data type represented by a set of name/value pairs describing user-defined properties. |
| 32 | +Each name in `Baggage` MUST be associated with exactly one value. |
| 33 | + |
| 34 | +### Get all |
| 35 | + |
| 36 | +Returns the name/value pairs in the `Baggage`. The order of name/value pairs MUST NOT be |
| 37 | +significant. Based on the language specification, the returned value can be |
| 38 | +either an immutable collection or an immutable iterator to the collection of |
| 39 | +name/value pairs in the `Baggage`. |
| 40 | + |
| 41 | +OPTIONAL parameters: |
| 42 | + |
| 43 | +`Context` the context containing the `Baggage` from which to get the baggages. |
| 44 | + |
| 45 | +### Get baggage |
| 46 | + |
| 47 | +To access the value for a name/value pair by a prior event, the Baggage API |
| 48 | +SHALL provide a function that takes a context and a name as input, and returns a |
| 49 | +value. Returns the value associated with the given name, or null |
| 50 | +if the given name is not present. |
| 51 | + |
| 52 | +REQUIRED parameters: |
| 53 | + |
| 54 | +`Name` the name to return the value for. |
| 55 | + |
| 56 | +OPTIONAL parameters: |
| 57 | + |
| 58 | +`Context` the context containing the `Baggage` from which to get the baggage entry. |
| 59 | + |
| 60 | +### Set baggage |
| 61 | + |
| 62 | +To record the value for a name/value pair, the Baggage API SHALL provide a function which |
| 63 | +takes a context, a name, and a value as input. Returns a new `Context` which |
| 64 | +contains a `Baggage` with the new value. |
| 65 | + |
| 66 | +REQUIRED parameters: |
| 67 | + |
| 68 | +`Name` the name for which to set the value. |
| 69 | + |
| 70 | +`Value` the value to set. |
| 71 | + |
| 72 | +OPTIONAL parameters: |
| 73 | + |
| 74 | +`Context` the context containing the `Baggage` in which to set the baggage entry. |
| 75 | + |
| 76 | +### Remove baggage |
| 77 | + |
| 78 | +To delete a name/value pair, the Baggage API SHALL provide a function which takes a context |
| 79 | +and a name as input. Returns a new `Context` which no longer contains the selected name. |
| 80 | + |
| 81 | +REQUIRED parameters: |
| 82 | + |
| 83 | +`Name` the name to remove. |
| 84 | + |
| 85 | +OPTIONAL parameters: |
| 86 | + |
| 87 | +`Context` the context containing the `Baggage` from which to remove the baggage entry. |
| 88 | + |
| 89 | +### Clear |
| 90 | + |
| 91 | +To avoid sending any name/value pairs to an untrusted process, the Baggage API SHALL provide |
| 92 | +a function to remove all baggage entries from a context. Returns a new `Context` |
| 93 | +with no `Baggage`. |
| 94 | + |
| 95 | +OPTIONAL parameters: |
| 96 | + |
| 97 | +`Context` the context containing the `Baggage` from which to remove all baggage entries. |
| 98 | + |
| 99 | +## Baggage Propagation |
| 100 | + |
| 101 | +`Baggage` MAY be propagated across process boundaries or across any arbitrary boundaries |
| 102 | +(process, $OTHER_BOUNDARY1, $OTHER_BOUNDARY2, etc) for various reasons. |
| 103 | + |
| 104 | +### Serialization |
| 105 | + |
| 106 | +Until the [W3C Baggage](https://w3c.github.io/baggage/) specification is recommended for use, OpenTelemetry `Baggage` implementations MUST be serialized according to the [editor's draft of W3C Correlation Context as of March 27, 2020](https://github.com/w3c/correlation-context/blob/c974664b9ab4d33af6355f1f7f03a2d52c89a99e/correlation_context/HTTP_HEADER_FORMAT.md) using a vendor-specific header name to avoid collisions with the W3C Baggage specification should it change in the future. |
| 107 | + |
| 108 | +#### Header Name |
| 109 | + |
| 110 | +`Baggage` implementations MUST use the header name `otcorrelations`. |
| 111 | + |
| 112 | +#### Header Value |
| 113 | + |
| 114 | +`Baggage` MUST be serialized according to the [editor's draft of W3C Correlation Context as of March 27, 2020](https://github.com/w3c/correlation-context/blob/c974664b9ab4d33af6355f1f7f03a2d52c89a99e/correlation_context/HTTP_HEADER_FORMAT.md). |
| 115 | + |
| 116 | +`Baggage` values MUST be serialized as Percent-Encoded UTF-8 strings according to [RFC 3986 Section 2.1](https://tools.ietf.org/html/rfc3986#section-2.1). |
| 117 | + |
| 118 | +#### Example |
| 119 | + |
| 120 | +Baggage: |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "user": "foo@example.com", |
| 125 | + "name": "Example Name" |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +Header: |
| 130 | + |
| 131 | +``` |
| 132 | +otbaggages: user=foo%40example.com,name=Example%20Name |
| 133 | +``` |
| 134 | + |
| 135 | +## Conflict Resolution |
| 136 | + |
| 137 | +If a new name/value pair is added and its name is the same as an existing name, than the new pair MUST take precedence. The value |
| 138 | +is replaced with the added value (regardless if it is locally generated or received from a remote peer). |
0 commit comments