@@ -24,19 +24,20 @@ import (
24
24
// TODO: http.route
25
25
26
26
type HttpCommonAttrsExtractor [REQUEST any , RESPONSE any , GETTER1 HttpCommonAttrsGetter [REQUEST , RESPONSE ], GETTER2 net.NetworkAttrsGetter [REQUEST , RESPONSE ]] struct {
27
- HttpGetter GETTER1
28
- NetGetter GETTER2
27
+ HttpGetter GETTER1
28
+ NetGetter GETTER2
29
+ AttributesFilter func (attrs []attribute.KeyValue ) []attribute.KeyValue
29
30
}
30
31
31
- func (h * HttpCommonAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) []attribute.KeyValue {
32
+ func (h * HttpCommonAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) ( []attribute.KeyValue , context. Context ) {
32
33
attributes = append (attributes , attribute.KeyValue {
33
34
Key : semconv .HTTPRequestMethodKey ,
34
35
Value : attribute .StringValue (h .HttpGetter .GetRequestMethod (request )),
35
36
})
36
- return attributes
37
+ return attributes , parentContext
37
38
}
38
39
39
- func (h * HttpCommonAttrsExtractor [REQUEST , RESPONSE , GETTER , GETTER2 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) []attribute.KeyValue {
40
+ func (h * HttpCommonAttrsExtractor [REQUEST , RESPONSE , GETTER , GETTER2 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) ( []attribute.KeyValue , context. Context ) {
40
41
statusCode := h .HttpGetter .GetHttpResponseStatusCode (request , response , err )
41
42
protocolName := h .NetGetter .GetNetworkProtocolName (request , response )
42
43
protocolVersion := h .NetGetter .GetNetworkProtocolVersion (request , response )
@@ -50,17 +51,17 @@ func (h *HttpCommonAttrsExtractor[REQUEST, RESPONSE, GETTER, GETTER2]) OnEnd(att
50
51
Key : semconv .NetworkProtocolVersionKey ,
51
52
Value : attribute .StringValue (protocolVersion ),
52
53
})
53
- return attributes
54
+ return attributes , context
54
55
}
55
56
56
57
type HttpClientAttrsExtractor [REQUEST any , RESPONSE any , GETTER1 HttpClientAttrsGetter [REQUEST , RESPONSE ], GETTER2 net.NetworkAttrsGetter [REQUEST , RESPONSE ]] struct {
57
58
Base HttpCommonAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]
58
59
NetworkExtractor net.NetworkAttrsExtractor [REQUEST , RESPONSE , GETTER2 ]
59
60
}
60
61
61
- func (h * HttpClientAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) []attribute.KeyValue {
62
- attributes = h .Base .OnStart (attributes , parentContext , request )
63
- attributes = h .NetworkExtractor .OnStart (attributes , parentContext , request )
62
+ func (h * HttpClientAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) ( []attribute.KeyValue , context. Context ) {
63
+ attributes , parentContext = h .Base .OnStart (attributes , parentContext , request )
64
+ attributes , parentContext = h .NetworkExtractor .OnStart (attributes , parentContext , request )
64
65
fullUrl := h .Base .HttpGetter .GetUrlFull (request )
65
66
// TODO: add resend count
66
67
attributes = append (attributes , attribute.KeyValue {
@@ -73,13 +74,19 @@ func (h *HttpClientAttrsExtractor[REQUEST, RESPONSE, GETTER1, GETTER2]) OnStart(
73
74
Key : semconv .ServerPortKey ,
74
75
Value : attribute .IntValue (h .Base .HttpGetter .GetServerPort (request )),
75
76
})
76
- return attributes
77
+ if h .Base .AttributesFilter != nil {
78
+ attributes = h .Base .AttributesFilter (attributes )
79
+ }
80
+ return attributes , parentContext
77
81
}
78
82
79
- func (h * HttpClientAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) []attribute.KeyValue {
80
- attributes = h .Base .OnEnd (attributes , context , request , response , err )
81
- attributes = h .NetworkExtractor .OnEnd (attributes , context , request , response , err )
82
- return attributes
83
+ func (h * HttpClientAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) ([]attribute.KeyValue , context.Context ) {
84
+ attributes , context = h .Base .OnEnd (attributes , context , request , response , err )
85
+ attributes , context = h .NetworkExtractor .OnEnd (attributes , context , request , response , err )
86
+ if h .Base .AttributesFilter != nil {
87
+ attributes = h .Base .AttributesFilter (attributes )
88
+ }
89
+ return attributes , context
83
90
}
84
91
85
92
type HttpServerAttrsExtractor [REQUEST any , RESPONSE any , GETTER1 HttpServerAttrsGetter [REQUEST , RESPONSE ], GETTER2 net.NetworkAttrsGetter [REQUEST , RESPONSE ], GETTER3 net.UrlAttrsGetter [REQUEST ]] struct {
@@ -88,9 +95,9 @@ type HttpServerAttrsExtractor[REQUEST any, RESPONSE any, GETTER1 HttpServerAttrs
88
95
UrlExtractor net.UrlAttrsExtractor [REQUEST , RESPONSE , GETTER3 ]
89
96
}
90
97
91
- func (h * HttpServerAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 , GETTER3 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) []attribute.KeyValue {
92
- attributes = h .Base .OnStart (attributes , parentContext , request )
93
- attributes = h .UrlExtractor .OnStart (attributes , parentContext , request )
98
+ func (h * HttpServerAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 , GETTER3 ]) OnStart (attributes []attribute.KeyValue , parentContext context.Context , request REQUEST ) ( []attribute.KeyValue , context. Context ) {
99
+ attributes , parentContext = h .Base .OnStart (attributes , parentContext , request )
100
+ attributes , parentContext = h .UrlExtractor .OnStart (attributes , parentContext , request )
94
101
userAgent := h .Base .HttpGetter .GetHttpRequestHeader (request , "User-Agent" )
95
102
var firstUserAgent string
96
103
if len (userAgent ) > 0 {
@@ -104,12 +111,18 @@ func (h *HttpServerAttrsExtractor[REQUEST, RESPONSE, GETTER1, GETTER2, GETTER3])
104
111
Key : semconv .UserAgentOriginalKey ,
105
112
Value : attribute .StringValue (firstUserAgent ),
106
113
})
107
- return attributes
114
+ if h .Base .AttributesFilter != nil {
115
+ attributes = h .Base .AttributesFilter (attributes )
116
+ }
117
+ return attributes , parentContext
108
118
}
109
119
110
- func (h * HttpServerAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 , GETTER3 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) []attribute.KeyValue {
111
- attributes = h .Base .OnEnd (attributes , context , request , response , err )
112
- attributes = h .UrlExtractor .OnEnd (attributes , context , request , response , err )
113
- attributes = h .NetworkExtractor .OnEnd (attributes , context , request , response , err )
114
- return attributes
120
+ func (h * HttpServerAttrsExtractor [REQUEST , RESPONSE , GETTER1 , GETTER2 , GETTER3 ]) OnEnd (attributes []attribute.KeyValue , context context.Context , request REQUEST , response RESPONSE , err error ) ([]attribute.KeyValue , context.Context ) {
121
+ attributes , context = h .Base .OnEnd (attributes , context , request , response , err )
122
+ attributes , context = h .UrlExtractor .OnEnd (attributes , context , request , response , err )
123
+ attributes , context = h .NetworkExtractor .OnEnd (attributes , context , request , response , err )
124
+ if h .Base .AttributesFilter != nil {
125
+ attributes = h .Base .AttributesFilter (attributes )
126
+ }
127
+ return attributes , context
115
128
}
0 commit comments