@@ -2,6 +2,7 @@ use crate::{propagation, Span, SpanSink};
22use futures:: { future:: Either , prelude:: * } ;
33use http:: Uri ;
44use linkerd_stack:: layer;
5+ use opentelemetry_semantic_conventions as semconv;
56use 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