@@ -23,10 +23,12 @@ const beforeRequest: FetchComponentConfig['beforeRequest'] = async (options) =>
23
23
const {
24
24
id,
25
25
ctx,
26
- enableTraceLoggingReqBody,
27
- traceLoggingReqHeaders,
28
26
opts,
29
27
} = options
28
+ const {
29
+ enableTraceLoggingReqBody,
30
+ traceLoggingReqHeaders,
31
+ } = options . config
30
32
31
33
const time = genISO8601String ( )
32
34
const mem = humanMemoryUsage ( )
@@ -55,12 +57,14 @@ const beforeRequest: FetchComponentConfig['beforeRequest'] = async (options) =>
55
57
tags [ TracerTag . reqQuery ] = 'Not logged'
56
58
}
57
59
58
- traceLoggingReqHeaders . forEach ( ( name ) => {
59
- const val = retrieveHeadersItem ( opts . headers , name )
60
- if ( val ) {
61
- tags [ `http.${ name } ` ] = val
62
- }
63
- } )
60
+ if ( Array . isArray ( traceLoggingReqHeaders ) ) {
61
+ traceLoggingReqHeaders . forEach ( ( name ) => {
62
+ const val = retrieveHeadersItem ( opts . headers , name )
63
+ if ( typeof val !== 'undefined' ) {
64
+ tags [ `http.${ name } ` ] = val
65
+ }
66
+ } )
67
+ }
64
68
65
69
span . addTags ( tags )
66
70
@@ -74,7 +78,17 @@ const beforeRequest: FetchComponentConfig['beforeRequest'] = async (options) =>
74
78
}
75
79
76
80
const afterResponse : FetchComponentConfig [ 'afterResponse' ] = async ( options ) => {
77
- const { id, ctx, enableTraceLoggingRespData, opts, resultData } = options
81
+ const {
82
+ id,
83
+ ctx,
84
+ opts,
85
+ resultData,
86
+ } = options
87
+ const {
88
+ enableTraceLoggingRespData,
89
+ traceLoggingRespHeaders,
90
+ } = options . config
91
+
78
92
const time = genISO8601String ( )
79
93
const mem = humanMemoryUsage ( )
80
94
const parentInput : SpanLogInput = {
@@ -101,6 +115,15 @@ const afterResponse: FetchComponentConfig['afterResponse'] = async (options) =>
101
115
tags [ TracerTag . respBody ] = 'Not logged'
102
116
}
103
117
118
+ if ( Array . isArray ( traceLoggingRespHeaders ) ) {
119
+ traceLoggingRespHeaders . forEach ( ( name ) => {
120
+ const val = retrieveHeadersItem ( opts . headers , name )
121
+ if ( typeof val !== 'undefined' ) {
122
+ tags [ `http.${ name } ` ] = val
123
+ }
124
+ } )
125
+ }
126
+
104
127
Object . keys ( tags ) . length && span . addTags ( tags )
105
128
106
129
const input : SpanLogInput = {
@@ -115,7 +138,10 @@ const afterResponse: FetchComponentConfig['afterResponse'] = async (options) =>
115
138
}
116
139
117
140
export const processEx : FetchComponentConfig [ 'processEx' ] = ( options ) => {
118
- const { id, ctx, exception } = options
141
+ const { id, ctx, opts, exception } = options
142
+ const {
143
+ traceLoggingRespHeaders,
144
+ } = options . config
119
145
const time = genISO8601String ( )
120
146
const mem = humanMemoryUsage ( )
121
147
@@ -135,6 +161,16 @@ export const processEx: FetchComponentConfig['processEx'] = (options) => {
135
161
[ TracerTag . logLevel ] : 'error' ,
136
162
[ TracerTag . svcException ] : exception ,
137
163
}
164
+
165
+ if ( Array . isArray ( traceLoggingRespHeaders ) ) {
166
+ traceLoggingRespHeaders . forEach ( ( name ) => {
167
+ const val = retrieveHeadersItem ( opts . headers , name )
168
+ if ( typeof val !== 'undefined' ) {
169
+ tags [ `http.${ name } ` ] = val
170
+ }
171
+ } )
172
+ }
173
+
138
174
span . addTags ( tags )
139
175
140
176
const input : SpanLogInput = {
0 commit comments