Skip to content

Commit 944361e

Browse files
yurishkurocarlosalberto
authored andcommitted
Provide guidelines for low-cardinality span names (open-telemetry#416)
1 parent 48ced7b commit 944361e

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

specification/api-tracing.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ sub-operations.
200200

201201
`Span`s encapsulate:
202202

203-
- The operation name
203+
- The span name
204204
- An immutable [`SpanContext`](#spancontext) that uniquely identifies the
205205
`Span`
206206
- A parent span in the form of a [`Span`](#span), [`SpanContext`](#spancontext),
@@ -212,6 +212,24 @@ sub-operations.
212212
- A list of timestamped [`Event`s](#add-events)
213213
- A [`Status`](#set-status).
214214

215+
The _span name_ is a human-readable string which concisely identifies the work
216+
represented by the Span, for example, an RPC method name, a function name,
217+
or the name of a subtask or stage within a larger computation. The span name
218+
should be the most general string that identifies a (statistically) interesting
219+
_class of Spans_, rather than individual Span instances. That is, "get_user" is
220+
a reasonable name, while "get_user/314159", where "314159" is a user ID, is not
221+
a good name due to its high cardinality.
222+
223+
For example, here are potential span names for an endpoint that gets a
224+
hypothetical account information:
225+
226+
| Span Name | Guidance |
227+
| ----------------- | ------------ |
228+
| `get` | Too general |
229+
| `get_account/42` | Too specific |
230+
| `get_account` | Good, and account_id=42 would make a nice Span attribute |
231+
| `get_account/{accountId}` | Also good (using the "HTTP route") |
232+
215233
The `Span`'s start and end timestamps reflect the elapsed real time of the
216234
operation. A `Span`'s start time SHOULD be set to the current time on [span
217235
creation](#span-creation). After the `Span` is created, it SHOULD be possible to
@@ -238,7 +256,7 @@ as a separate operation.
238256

239257
The API MUST accept the following parameters:
240258

241-
- The operation name. This is a required parameter.
259+
- The span name. This is a required parameter.
242260
- The parent Span or parent Span context, and whether the new `Span` should be a
243261
root `Span`. API MAY also have an option for implicit parent context
244262
extraction from the current context as a default behavior.
@@ -428,7 +446,7 @@ started with the explicit timestamp from the past at the moment where the final
428446

429447
Required parameters:
430448

431-
- The new **operation name**, which supersedes whatever was passed in when the
449+
- The new **span name**, which supersedes whatever was passed in when the
432450
`Span` was started
433451

434452
#### End

specification/data-http.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ and various HTTP versions like 1.1, 2 and SPDY.
2121

2222
## Name
2323

24-
Given an [RFC 3986](https://tools.ietf.org/html/rfc3986) compliant URI of the form `scheme:[//host[:port]]path[?query][#fragment]`,
25-
the span name of the span SHOULD be set to the URI path value,
26-
unless another value that represents the identity of the request and has a lower cardinality can be identified
27-
(e.g. the route for server spans; see below).
24+
HTTP spans MUST follow the overall [guidelines for span names](./api-tracing.md#span).
25+
Many REST APIs encode parameters into URI path, e.g. `/api/users/123` where `123`
26+
is a user id, which creates high cardinality value space not suitable for span
27+
names. In case of HTTP servers, these endpoints are often mapped by the server
28+
frameworks to more concise _HTTP routes_, e.g. `/api/users/{user_id}`, which are
29+
recommended as the low cardinality span names. However, the same approach usually
30+
does not work for HTTP client spans, especially when instrumentation is provided
31+
by a lower-level middleware that is not aware of the specifics of how the URIs
32+
are formed. Therefore, HTTP client spans SHOULD be using conservative, low
33+
cardinality names formed from the available parameters of an HTTP request,
34+
such as `"HTTP {METHOD_NAME}"`. Instrumentation MUST NOT default to using URI
35+
path as span name, but MAY provide hooks to allow custom logic to override the
36+
default span name.
2837

2938
## Status
3039

0 commit comments

Comments
 (0)