Skip to content

Commit 2e106b8

Browse files
committed
chore(tracing): Use upstream semantic convention definitions
The proxy's tracing labels currently use hardcoded strings for semantic convention labels. This replaces those with the upstream ones defined by the OpenTelemetry libraries. Signed-off-by: Scott Fleener <[email protected]>
1 parent f4e7b83 commit 2e106b8

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

Cargo.lock

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ dependencies = [
380380
"serde_core",
381381
]
382382

383+
[[package]]
384+
name = "const_format"
385+
version = "0.2.35"
386+
source = "registry+https://github.com/rust-lang/crates.io-index"
387+
checksum = "7faa7469a93a566e9ccc1c73fe783b4a65c274c5ace346038dca9c39fe0030ad"
388+
dependencies = [
389+
"const_format_proc_macros",
390+
]
391+
392+
[[package]]
393+
name = "const_format_proc_macros"
394+
version = "0.2.34"
395+
source = "registry+https://github.com/rust-lang/crates.io-index"
396+
checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744"
397+
dependencies = [
398+
"proc-macro2",
399+
"quote",
400+
"unicode-xid",
401+
]
402+
383403
[[package]]
384404
name = "cpp_demangle"
385405
version = "0.4.5"
@@ -601,7 +621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
601621
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
602622
dependencies = [
603623
"libc",
604-
"windows-sys 0.52.0",
624+
"windows-sys 0.61.1",
605625
]
606626

607627
[[package]]
@@ -1225,7 +1245,7 @@ dependencies = [
12251245
"portable-atomic",
12261246
"portable-atomic-util",
12271247
"serde",
1228-
"windows-sys 0.52.0",
1248+
"windows-sys 0.59.0",
12291249
]
12301250

12311251
[[package]]
@@ -1325,7 +1345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
13251345
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
13261346
dependencies = [
13271347
"cfg-if",
1328-
"windows-targets 0.48.5",
1348+
"windows-targets 0.52.6",
13291349
]
13301350

13311351
[[package]]
@@ -2578,11 +2598,13 @@ version = "0.1.0"
25782598
dependencies = [
25792599
"base64",
25802600
"bytes",
2601+
"const_format",
25812602
"futures",
25822603
"hex",
25832604
"http",
25842605
"linkerd-error",
25852606
"linkerd-stack",
2607+
"opentelemetry-semantic-conventions",
25862608
"rand 0.9.2",
25872609
"thiserror",
25882610
"tower",
@@ -2831,7 +2853,7 @@ version = "0.50.3"
28312853
source = "registry+https://github.com/rust-lang/crates.io-index"
28322854
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
28332855
dependencies = [
2834-
"windows-sys 0.59.0",
2856+
"windows-sys 0.61.1",
28352857
]
28362858

28372859
[[package]]
@@ -2937,6 +2959,12 @@ dependencies = [
29372959
"tonic-prost",
29382960
]
29392961

2962+
[[package]]
2963+
name = "opentelemetry-semantic-conventions"
2964+
version = "0.31.0"
2965+
source = "registry+https://github.com/rust-lang/crates.io-index"
2966+
checksum = "e62e29dfe041afb8ed2a6c9737ab57db4907285d999ef8ad3a59092a36bdc846"
2967+
29402968
[[package]]
29412969
name = "opentelemetry_sdk"
29422970
version = "0.31.0"
@@ -3474,7 +3502,7 @@ dependencies = [
34743502
"errno",
34753503
"libc",
34763504
"linux-raw-sys 0.4.15",
3477-
"windows-sys 0.52.0",
3505+
"windows-sys 0.59.0",
34783506
]
34793507

34803508
[[package]]
@@ -3487,7 +3515,7 @@ dependencies = [
34873515
"errno",
34883516
"libc",
34893517
"linux-raw-sys 0.9.2",
3490-
"windows-sys 0.52.0",
3518+
"windows-sys 0.59.0",
34913519
]
34923520

34933521
[[package]]
@@ -3788,7 +3816,7 @@ dependencies = [
37883816
"getrandom 0.3.1",
37893817
"once_cell",
37903818
"rustix 1.0.2",
3791-
"windows-sys 0.52.0",
3819+
"windows-sys 0.61.1",
37923820
]
37933821

37943822
[[package]]
@@ -4209,6 +4237,12 @@ version = "1.0.19"
42094237
source = "registry+https://github.com/rust-lang/crates.io-index"
42104238
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
42114239

4240+
[[package]]
4241+
name = "unicode-xid"
4242+
version = "0.2.6"
4243+
source = "registry+https://github.com/rust-lang/crates.io-index"
4244+
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
4245+
42124246
[[package]]
42134247
name = "untrusted"
42144248
version = "0.9.0"

linkerd/trace-context/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ publish = { workspace = true }
99
[dependencies]
1010
base64 = "0.22"
1111
bytes = { workspace = true }
12+
const_format = "0.2"
1213
futures = { version = "0.3", default-features = false }
1314
hex = "0.4"
1415
http = { workspace = true }
1516
linkerd-error = { path = "../error" }
1617
linkerd-stack = { path = "../stack" }
18+
opentelemetry-semantic-conventions = { version = "0.31", default-features = false, features = ["semconv_experimental"] }
1719
rand = "0.9"
1820
thiserror = "2"
1921
tower = { workspace = true, default-features = false, features = ["util"] }

linkerd/trace-context/src/service.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{propagation, Span, SpanSink};
22
use futures::{future::Either, prelude::*};
33
use http::Uri;
44
use linkerd_stack::layer;
5+
use opentelemetry_semantic_conventions as semconv;
56
use std::{
67
collections::HashMap,
78
fmt::{Display, Formatter},
@@ -43,21 +44,24 @@ impl<K: Clone, S> TraceContext<K, S> {
4344
/// https://opentelemetry.io/docs/specs/semconv/http/http-spans/
4445
fn request_labels<B>(req: &http::Request<B>) -> HashMap<&'static str, String> {
4546
let mut labels = HashMap::with_capacity(13);
46-
labels.insert("http.request.method", format!("{}", req.method()));
47+
labels.insert(
48+
semconv::trace::HTTP_REQUEST_METHOD,
49+
format!("{}", req.method()),
50+
);
4751

4852
let url = req.uri();
4953
if let Some(scheme) = url.scheme_str() {
50-
labels.insert("url.scheme", scheme.to_string());
54+
labels.insert(semconv::trace::URL_SCHEME, scheme.to_string());
5155
}
52-
labels.insert("url.path", url.path().to_string());
56+
labels.insert(semconv::trace::URL_PATH, url.path().to_string());
5357
if let Some(query) = url.query() {
54-
labels.insert("url.query", query.to_string());
58+
labels.insert(semconv::trace::URL_QUERY, query.to_string());
5559
}
5660

57-
labels.insert("url.full", UrlLabel(url).to_string());
61+
labels.insert(semconv::trace::URL_FULL, UrlLabel(url).to_string());
5862

5963
// linkerd currently only proxies tcp-based connections
60-
labels.insert("network.transport", "tcp".to_string());
64+
labels.insert(semconv::trace::NETWORK_TRANSPORT, "tcp".to_string());
6165

6266
// This is the order of precedence for host headers,
6367
// see https://opentelemetry.io/docs/specs/semconv/http/http-spans/
@@ -71,10 +75,10 @@ impl<K: Clone, S> TraceContext<K, S> {
7175
if let Ok(host) = host.to_str() {
7276
if let Ok(uri) = host.parse::<Uri>() {
7377
if let Some(host) = uri.host() {
74-
labels.insert("server.address", host.to_string());
78+
labels.insert(semconv::trace::SERVER_ADDRESS, host.to_string());
7579
}
7680
if let Some(port) = uri.port() {
77-
labels.insert("server.port", port.to_string());
81+
labels.insert(semconv::trace::SERVER_PORT, port.to_string());
7882
}
7983
}
8084
}
@@ -96,11 +100,20 @@ impl<K: Clone, S> TraceContext<K, S> {
96100
req: &http::Request<B>,
97101
) {
98102
static HEADER_LABELS: &[(&str, &str)] = &[
99-
("user-agent", "user_agent.original"),
103+
("user-agent", semconv::trace::USER_AGENT_ORIGINAL),
100104
// http.request.body.size is available as a semantic convention, but is not stable.
101-
("content-length", "http.request.header.content-length"),
102-
("content-type", "http.request.header.content-type"),
103-
("l5d-orig-proto", "http.request.header.l5d-orig-proto"),
105+
(
106+
"content-length",
107+
const_format::concatcp!(semconv::trace::HTTP_REQUEST_HEADER, ".content-length"),
108+
),
109+
(
110+
"content-type",
111+
const_format::concatcp!(semconv::trace::HTTP_REQUEST_HEADER, ".content-type"),
112+
),
113+
(
114+
"l5d-orig-proto",
115+
const_format::concatcp!(semconv::trace::HTTP_REQUEST_HEADER, ".l5d-orig-proto"),
116+
),
104117
];
105118
for &(header, label) in HEADER_LABELS {
106119
if let Some(value) = req.headers().get(header) {
@@ -114,7 +127,7 @@ impl<K: Clone, S> TraceContext<K, S> {
114127
rsp: &http::Response<B>,
115128
) -> HashMap<&'static str, String> {
116129
labels.insert(
117-
"http.response.status_code",
130+
semconv::trace::HTTP_RESPONSE_STATUS_CODE,
118131
rsp.status().as_str().to_string(),
119132
);
120133
labels

0 commit comments

Comments
 (0)