5
5
"net/http"
6
6
7
7
"go.opentelemetry.io/otel/attribute"
8
- "go.opentelemetry.io/otel/semconv/v1.21.0"
9
8
10
9
"github.com/luraproject/lura/v2/config"
11
10
transport "github.com/luraproject/lura/v2/transport/http/client"
@@ -21,16 +20,14 @@ var defaultOpts = otelconfig.BackendOpts{
21
20
RoundTrip : true ,
22
21
ReadPayload : true ,
23
22
DetailedConnection : true ,
24
- // TODO: THIS IS NOT BEING USED !!
25
- StaticAttributes : make (otelconfig.Attributes , 0 ),
23
+ StaticAttributes : make (otelconfig.Attributes , 0 ),
26
24
},
27
25
Traces : & otelconfig.BackendTraceOpts {
28
26
DisableStage : false ,
29
27
RoundTrip : true ,
30
28
ReadPayload : true ,
31
29
DetailedConnection : true ,
32
- // TODO: THIS IS NOT BEING USED !!
33
- StaticAttributes : make (otelconfig.Attributes , 0 ),
30
+ StaticAttributes : make (otelconfig.Attributes , 0 ),
34
31
},
35
32
}
36
33
@@ -86,38 +83,39 @@ func InstrumentedHTTPClientFactory(clientFactory transport.HTTPClientFactory,
86
83
// - backend: includes all middlewares and processing that is done for
87
84
// a given backend.
88
85
// - backend-request: when reporting the request to the backends
89
- attrs := []attribute.KeyValue {
90
- semconv .HTTPRequestMethodOriginal (cfg .Method ),
91
- semconv .URLPath (urlPattern ), // <- for traces we can use URLFull to not have the matched path
92
- attribute .String ("krakend.stage" , "backend-request" ),
93
- }
86
+ attrs := backendConfigAttributes (cfg , "backend-request" )
94
87
95
- if len (cfg .Host ) > 0 {
96
- attrs = append (attrs , semconv .ServerAddress (cfg .Host [0 ]))
88
+ metricAttrs := attrs
89
+ if len (opts .Metrics .StaticAttributes ) > 0 {
90
+ for _ , kv := range opts .Metrics .StaticAttributes {
91
+ metricAttrs = append (metricAttrs , attribute .String (kv .Key , kv .Value ))
92
+ }
93
+ }
94
+ traceAttrs := attrs
95
+ if len (opts .Traces .StaticAttributes ) > 0 {
96
+ for _ , kv := range opts .Metrics .StaticAttributes {
97
+ traceAttrs = append (traceAttrs , attribute .String (kv .Key , kv .Value ))
98
+ }
97
99
}
98
-
99
- // TODO: check how we want to deal with this "clientName"
100
- clientName := cfg .ParentEndpoint + "." + urlPattern
101
-
102
100
t := clienthttp.TransportOptions {
103
101
MetricsOpts : clienthttp.TransportMetricsOptions {
104
102
RoundTrip : opts .Metrics .RoundTrip ,
105
103
ReadPayload : opts .Metrics .ReadPayload ,
106
104
DetailedConnection : opts .Metrics .DetailedConnection ,
107
- FixedAttributes : attrs ,
105
+ FixedAttributes : metricAttrs ,
108
106
},
109
107
TracesOpts : clienthttp.TransportTracesOptions {
110
108
RoundTrip : opts .Traces .RoundTrip ,
111
109
ReadPayload : opts .Traces .ReadPayload ,
112
110
DetailedConnection : opts .Traces .DetailedConnection ,
113
- FixedAttributes : attrs ,
111
+ FixedAttributes : traceAttrs ,
114
112
},
115
113
OTELInstance : getState ,
116
114
}
117
115
118
116
return func (ctx context.Context ) * http.Client {
119
117
// TODO: this can be optimized, because inside InstrumentedHTTPClient we
120
118
// are creating a RoundTripper that could be "prebuilt" and reused
121
- return clienthttp .InstrumentedHTTPClient (clientFactory (ctx ), & t , clientName )
119
+ return clienthttp .InstrumentedHTTPClient (clientFactory (ctx ), & t , urlPattern )
122
120
}
123
121
}
0 commit comments