File tree 3 files changed +39
-1
lines changed
3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -136,13 +136,15 @@ Each integration also has its own list of default tags. These tags get automatic
136
136
| http.url | The complete URL of the request. |
137
137
| http.method | The HTTP method of the request. |
138
138
| http.status_code | The HTTP status code of the response. |
139
+ | http.headers.* | A recorded HTTP header. |
139
140
140
141
<h5 id =" express-config " >Configuration Options</h5 >
141
142
142
143
| Option | Default | Description |
143
144
| ------------------| ---------------------------| ----------------------------------------|
144
145
| service | * Service name of the app* | The service name for this integration. |
145
146
| validateStatus | ` code => code < 500 ` | Callback function to determine if there was an error. It should take a status code as its only parameter and return ` true ` for success or ` false ` for errors. |
147
+ | recordHeaders | ` undefined ` | An array of headers to include in the span metadata. |
146
148
147
149
<h3 id =" graphql " >graphql</h3 >
148
150
Original file line number Diff line number Diff line change @@ -45,6 +45,16 @@ function createWrapMethod (tracer, config) {
45
45
if ( ! validateStatus ( res . statusCode ) ) {
46
46
span . setTag ( Tags . ERROR , true )
47
47
}
48
+
49
+ if ( config . recordHeaders ) {
50
+ config . recordHeaders . forEach ( key => {
51
+ key = key . toLowerCase ( )
52
+ const value = req . headers [ key ]
53
+ if ( value ) {
54
+ span . setTag ( `http.headers.${ key } ` , value )
55
+ }
56
+ } )
57
+ }
48
58
49
59
span . finish ( )
50
60
Original file line number Diff line number Diff line change @@ -546,7 +546,8 @@ describe('Plugin', () => {
546
546
beforeEach ( ( ) => {
547
547
config = {
548
548
service : 'custom' ,
549
- validateStatus : code => code < 400
549
+ validateStatus : code => code < 400 ,
550
+ recordHeaders : [ 'User-Agent' ]
550
551
}
551
552
552
553
return agent . load ( plugin , 'express' , config )
@@ -602,6 +603,31 @@ describe('Plugin', () => {
602
603
} )
603
604
} )
604
605
} )
606
+
607
+ it ( 'should include specified headers in metadata' , done => {
608
+ const app = express ( )
609
+
610
+ app . get ( '/user' , ( req , res ) => {
611
+ res . status ( 200 ) . send ( )
612
+ } )
613
+
614
+ getPort ( ) . then ( port => {
615
+ agent
616
+ . use ( traces => {
617
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'http.headers.user-agent' , 'test' )
618
+ } )
619
+ . then ( done )
620
+ . catch ( done )
621
+
622
+ appListener = app . listen ( port , 'localhost' , ( ) => {
623
+ axios
624
+ . get ( `http://localhost:${ port } /user` , {
625
+ headers : { 'User-Agent' : 'test' }
626
+ } )
627
+ . catch ( done )
628
+ } )
629
+ } )
630
+ } )
605
631
} )
606
632
} )
607
633
} )
You can’t perform that action at this time.
0 commit comments