1
- use super :: DEFAULT_MESSAGE_LEVEL ;
1
+ use super :: { Latency , DEFAULT_MESSAGE_LEVEL } ;
2
2
use crate :: { classify:: grpc_errors_as_failures:: ParsedGrpcStatus , LatencyUnit } ;
3
3
use http:: header:: HeaderMap ;
4
4
use std:: time:: Duration ;
@@ -83,88 +83,12 @@ impl DefaultOnEos {
83
83
}
84
84
}
85
85
86
- // Repeating this pattern match for each case is tedious. So we do it with a quick and
87
- // dirty macro.
88
- //
89
- // Tracing requires all these parts to be declared statically. You cannot easily build
90
- // events dynamically.
91
- #[ allow( unused_macros) ]
92
- macro_rules! log_pattern_match {
93
- (
94
- $this: expr, $stream_duration: expr, $status: expr, [ $( $level: ident) ,* ]
95
- ) => {
96
- match ( $this. level, $this. latency_unit, $status) {
97
- $(
98
- ( Level :: $level, LatencyUnit :: Seconds , None ) => {
99
- tracing:: event!(
100
- Level :: $level,
101
- stream_duration = format_args!( "{} s" , $stream_duration. as_secs_f64( ) ) ,
102
- "end of stream"
103
- ) ;
104
- }
105
- ( Level :: $level, LatencyUnit :: Seconds , Some ( status) ) => {
106
- tracing:: event!(
107
- Level :: $level,
108
- stream_duration = format_args!( "{} s" , $stream_duration. as_secs_f64( ) ) ,
109
- status = status,
110
- "end of stream"
111
- ) ;
112
- }
113
-
114
- ( Level :: $level, LatencyUnit :: Millis , None ) => {
115
- tracing:: event!(
116
- Level :: $level,
117
- stream_duration = format_args!( "{} ms" , $stream_duration. as_millis( ) ) ,
118
- "end of stream"
119
- ) ;
120
- }
121
- ( Level :: $level, LatencyUnit :: Millis , Some ( status) ) => {
122
- tracing:: event!(
123
- Level :: $level,
124
- stream_duration = format_args!( "{} ms" , $stream_duration. as_millis( ) ) ,
125
- status = status,
126
- "end of stream"
127
- ) ;
128
- }
129
-
130
- ( Level :: $level, LatencyUnit :: Micros , None ) => {
131
- tracing:: event!(
132
- Level :: $level,
133
- stream_duration = format_args!( "{} μs" , $stream_duration. as_micros( ) ) ,
134
- "end of stream"
135
- ) ;
136
- }
137
- ( Level :: $level, LatencyUnit :: Micros , Some ( status) ) => {
138
- tracing:: event!(
139
- Level :: $level,
140
- stream_duration = format_args!( "{} μs" , $stream_duration. as_micros( ) ) ,
141
- status = status,
142
- "end of stream"
143
- ) ;
144
- }
145
-
146
- ( Level :: $level, LatencyUnit :: Nanos , None ) => {
147
- tracing:: event!(
148
- Level :: $level,
149
- stream_duration = format_args!( "{} ns" , $stream_duration. as_nanos( ) ) ,
150
- "end of stream"
151
- ) ;
152
- }
153
- ( Level :: $level, LatencyUnit :: Nanos , Some ( status) ) => {
154
- tracing:: event!(
155
- Level :: $level,
156
- stream_duration = format_args!( "{} ns" , $stream_duration. as_nanos( ) ) ,
157
- status = status,
158
- "end of stream"
159
- ) ;
160
- }
161
- ) *
162
- }
163
- } ;
164
- }
165
-
166
86
impl OnEos for DefaultOnEos {
167
87
fn on_eos ( self , trailers : Option < & HeaderMap > , stream_duration : Duration , _span : & Span ) {
88
+ let stream_duration = Latency {
89
+ unit : self . latency_unit ,
90
+ duration : stream_duration,
91
+ } ;
168
92
let status = trailers. and_then ( |trailers| {
169
93
match crate :: classify:: grpc_errors_as_failures:: classify_grpc_metadata (
170
94
trailers,
@@ -178,11 +102,6 @@ impl OnEos for DefaultOnEos {
178
102
}
179
103
} ) ;
180
104
181
- log_pattern_match ! (
182
- self ,
183
- stream_duration,
184
- status,
185
- [ ERROR , WARN , INFO , DEBUG , TRACE ]
186
- ) ;
105
+ event_dynamic_lvl ! ( self . level, %stream_duration, status, "end of stream" ) ;
187
106
}
188
107
}
0 commit comments