@@ -127,76 +127,24 @@ macro_rules! reqwest_otel_span {
127
127
let header_default = & :: http:: HeaderValue :: from_static( "" ) ;
128
128
let user_agent = format!( "{:?}" , $request. headers( ) . get( "user-agent" ) . unwrap_or( header_default) ) . replace( '"' , "" ) ;
129
129
130
- #[ cfg( not( feature = "deprecated_attributes" ) ) ]
131
- macro_rules! request_span {
132
- ( $lvl: expr) => {
133
- $crate:: reqwest_otel_span_macro:: private:: span!(
134
- $lvl,
135
- "HTTP request" ,
136
- http. request. method = %method,
137
- url. scheme = %scheme,
138
- server. address = %host,
139
- server. port = %host_port,
140
- user_agent. original = %user_agent,
141
- otel. kind = "client" ,
142
- otel. name = %otel_name,
143
- otel. status_code = tracing:: field:: Empty ,
144
- http. response. status_code = tracing:: field:: Empty ,
145
- error. message = tracing:: field:: Empty ,
146
- error. cause_chain = tracing:: field:: Empty ,
147
- $( $field) *
148
- )
149
- }
150
- }
151
-
152
- // With the deprecated attributes flag enabled, we publish both the old and new attributes.
153
- #[ cfg( feature = "deprecated_attributes" ) ]
154
- macro_rules! request_span {
155
- ( $lvl: expr) => {
156
- $crate:: reqwest_otel_span_macro:: private:: span!(
157
- $lvl,
158
- "HTTP request" ,
159
- http. request. method = %method,
160
- url. scheme = %scheme,
161
- server. address = %host,
162
- server. port = %host_port,
163
- user_agent. original = %user_agent,
164
- otel. kind = "client" ,
165
- otel. name = %otel_name,
166
- otel. status_code = tracing:: field:: Empty ,
167
- http. response. status_code = tracing:: field:: Empty ,
168
- error. message = tracing:: field:: Empty ,
169
- error. cause_chain = tracing:: field:: Empty ,
170
- // old attributes
171
- http. method = %method,
172
- http. scheme = %scheme,
173
- http. host = %host,
174
- net. host. port = %host_port,
175
- http. user_agent = tracing:: field:: Empty ,
176
- http. status_code = tracing:: field:: Empty ,
177
- $( $field) *
178
- )
179
- }
180
- }
181
-
182
- let span = match $level {
130
+ // The match here is necessary, because tracing expects the level to be static.
131
+ match $level {
183
132
$crate:: reqwest_otel_span_macro:: private:: Level :: TRACE => {
184
- request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: TRACE )
133
+ $crate :: request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: TRACE , method , scheme , host , host_port , user_agent , otel_name , $ ( $field ) * )
185
134
} ,
186
135
$crate:: reqwest_otel_span_macro:: private:: Level :: DEBUG => {
187
- request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: DEBUG )
136
+ $crate :: request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: DEBUG , method , scheme , host , host_port , user_agent , otel_name , $ ( $field ) * )
188
137
} ,
189
138
$crate:: reqwest_otel_span_macro:: private:: Level :: INFO => {
190
- request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: INFO )
139
+ $crate :: request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: INFO , method , scheme , host , host_port , user_agent , otel_name , $ ( $field ) * )
191
140
} ,
192
141
$crate:: reqwest_otel_span_macro:: private:: Level :: WARN => {
193
- request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: WARN )
142
+ $crate :: request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: WARN , method , scheme , host , host_port , user_agent , otel_name , $ ( $field ) * )
194
143
} ,
195
144
$crate:: reqwest_otel_span_macro:: private:: Level :: ERROR => {
196
- request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: ERROR )
145
+ $crate :: request_span!( $crate:: reqwest_otel_span_macro:: private:: Level :: ERROR , method , scheme , host , host_port , user_agent , otel_name , $ ( $field ) * )
197
146
} ,
198
- } ;
199
- span
147
+ }
200
148
}
201
149
}
202
150
}
@@ -205,4 +153,60 @@ macro_rules! reqwest_otel_span {
205
153
pub mod private {
206
154
#[ doc( hidden) ]
207
155
pub use tracing:: { span, Level } ;
156
+
157
+ #[ cfg( not( feature = "deprecated_attributes" ) ) ]
158
+ #[ doc( hidden) ]
159
+ #[ macro_export]
160
+ macro_rules! request_span {
161
+ ( $level: expr, $method: expr, $scheme: expr, $host: expr, $host_port: expr, $user_agent: expr, $otel_name: expr, $( $field: tt) * ) => {
162
+ $crate:: reqwest_otel_span_macro:: private:: span!(
163
+ $level,
164
+ "HTTP request" ,
165
+ http. request. method = %$method,
166
+ url. scheme = %$scheme,
167
+ server. address = %$host,
168
+ server. port = %$host_port,
169
+ user_agent. original = %$user_agent,
170
+ otel. kind = "client" ,
171
+ otel. name = %$otel_name,
172
+ otel. status_code = tracing:: field:: Empty ,
173
+ http. response. status_code = tracing:: field:: Empty ,
174
+ error. message = tracing:: field:: Empty ,
175
+ error. cause_chain = tracing:: field:: Empty ,
176
+ $( $field) *
177
+ )
178
+ }
179
+ }
180
+
181
+ // With the deprecated attributes flag enabled, we publish both the old and new attributes.
182
+ #[ cfg( feature = "deprecated_attributes" ) ]
183
+ #[ doc( hidden) ]
184
+ #[ macro_export]
185
+ macro_rules! request_span {
186
+ ( $level: expr, $method: expr, $scheme: expr, $host: expr, $host_port: expr, $user_agent: expr, $otel_name: expr, $( $field: tt) * ) => {
187
+ $crate:: reqwest_otel_span_macro:: private:: span!(
188
+ $level,
189
+ "HTTP request" ,
190
+ http. request. method = %$method,
191
+ url. scheme = %$scheme,
192
+ server. address = %$host,
193
+ server. port = %$host_port,
194
+ user_agent. original = %$user_agent,
195
+ otel. kind = "client" ,
196
+ otel. name = %$otel_name,
197
+ otel. status_code = tracing:: field:: Empty ,
198
+ http. response. status_code = tracing:: field:: Empty ,
199
+ error. message = tracing:: field:: Empty ,
200
+ error. cause_chain = tracing:: field:: Empty ,
201
+ // old attributes
202
+ http. method = %$method,
203
+ http. scheme = %$scheme,
204
+ http. host = %$host,
205
+ net. host. port = %$host_port,
206
+ http. user_agent = tracing:: field:: Empty ,
207
+ http. status_code = tracing:: field:: Empty ,
208
+ $( $field) *
209
+ )
210
+ }
211
+ }
208
212
}
0 commit comments