@@ -19,6 +19,8 @@ const MetricPrefix = "metric."
1919// (after body parsing) began. This allows metrics to exclude body upload/parsing time.
2020const processingStartTimeKey = "metrics.processingStartTime"
2121
22+ const HTTPStatusCodeGranularKey = attribute .Key ("http.status_code_granular" )
23+
2224// SetProcessingStartTime stores the current time as the processing start time in the gin context.
2325func SetProcessingStartTime (c * gin.Context ) {
2426 c .Set (processingStartTimeKey , time .Now ())
@@ -73,17 +75,16 @@ func Middleware(meterProvider metric.MeterProvider, service string, options ...O
7375 reqAttributes ... ,
7476 )
7577
78+ code := ginCtx .Writer .Status ()
7679 if errors .Is (ctx .Err (), context .Canceled ) {
7780 // 499 is the nginx convention for "client closed request before server responded"
78- resAttributes = append (resAttributes , semconv .HTTPStatusCodeKey .Int (499 ))
79- resAttributes = append (resAttributes , attribute .Bool ("client.canceled" , true ))
80- } else if cfg .groupedStatus {
81- code := ginCtx .Writer .Status () / 100 * 100
82- resAttributes = append (resAttributes , semconv .HTTPStatusCodeKey .Int (code ))
83- } else {
84- resAttributes = append (resAttributes , semconv .HTTPAttributesFromHTTPStatusCode (ginCtx .Writer .Status ())... )
81+ code = 499
8582 }
8683
84+ groupedCode := code / 100 * 100
85+ resAttributes = append (resAttributes , semconv .HTTPStatusCodeKey .Int (groupedCode ))
86+ resAttributes = append (resAttributes , HTTPStatusCodeGranularKey .Int (code ))
87+
8788 // Append attributes from ginCtx
8889 resAttributes = append (resAttributes , attributesFromGinContext (ginCtx , MetricPrefix )... )
8990
0 commit comments