@@ -56,11 +56,6 @@ export class Undici implements Integration {
56
56
*/
57
57
public name : string = Undici . id ;
58
58
59
- // Have to hold all built channels in memory otherwise they get garbage collected
60
- // See: https://github.com/nodejs/node/pull/42714
61
- // This has been fixed in Node 19+
62
- private _channels = new Set < DiagnosticsChannel . Channel > ( ) ;
63
-
64
59
private readonly _options : UndiciOptions ;
65
60
66
61
public constructor ( _options : Partial < UndiciOptions > = { } ) {
@@ -82,13 +77,12 @@ export class Undici implements Integration {
82
77
// no-op
83
78
}
84
79
85
- if ( ! ds ) {
80
+ if ( ! ds || ! ds . subscribe ) {
86
81
return ;
87
82
}
88
83
89
84
// https://github.com/nodejs/undici/blob/e6fc80f809d1217814c044f52ed40ef13f21e43c/docs/api/DiagnosticsChannel.md
90
- const requestCreateChannel = this . _setupChannel ( ds , ChannelName . RequestCreate ) ;
91
- requestCreateChannel . subscribe ( message => {
85
+ ds . subscribe ( ChannelName . RequestCreate , message => {
92
86
const { request } = message as RequestCreateMessage ;
93
87
94
88
const url = new URL ( request . path , request . origin ) ;
@@ -105,12 +99,12 @@ export class Undici implements Integration {
105
99
const activeSpan = scope . getSpan ( ) ;
106
100
107
101
if ( activeSpan && client ) {
108
- const options = client . getOptions ( ) ;
102
+ const clientOptions = client . getOptions ( ) ;
109
103
110
104
// eslint-disable-next-line deprecation/deprecation
111
- const shouldCreateSpan = options . shouldCreateSpanForRequest
105
+ const shouldCreateSpan = clientOptions . shouldCreateSpanForRequest
112
106
? // eslint-disable-next-line deprecation/deprecation
113
- options . shouldCreateSpanForRequest ( stringUrl )
107
+ clientOptions . shouldCreateSpanForRequest ( stringUrl )
114
108
: true ;
115
109
116
110
if ( shouldCreateSpan ) {
@@ -131,9 +125,9 @@ export class Undici implements Integration {
131
125
request . __sentry__ = span ;
132
126
133
127
// eslint-disable-next-line deprecation/deprecation
134
- const shouldPropagate = options . tracePropagationTargets
128
+ const shouldPropagate = clientOptions . tracePropagationTargets
135
129
? // eslint-disable-next-line deprecation/deprecation
136
- stringMatchesSomePattern ( stringUrl , options . tracePropagationTargets )
130
+ stringMatchesSomePattern ( stringUrl , clientOptions . tracePropagationTargets )
137
131
: true ;
138
132
139
133
if ( shouldPropagate ) {
@@ -151,8 +145,7 @@ export class Undici implements Integration {
151
145
}
152
146
} ) ;
153
147
154
- const requestEndChannel = this . _setupChannel ( ds , ChannelName . RequestEnd ) ;
155
- requestEndChannel . subscribe ( message => {
148
+ ds . subscribe ( ChannelName . RequestEnd , message => {
156
149
const { request, response } = message as RequestEndMessage ;
157
150
158
151
const url = new URL ( request . path , request . origin ) ;
@@ -188,8 +181,7 @@ export class Undici implements Integration {
188
181
}
189
182
} ) ;
190
183
191
- const requestErrorChannel = this . _setupChannel ( ds , ChannelName . RequestError ) ;
192
- requestErrorChannel . subscribe ( message => {
184
+ ds . subscribe ( ChannelName . RequestError , message => {
193
185
const { request } = message as RequestErrorMessage ;
194
186
195
187
const url = new URL ( request . path , request . origin ) ;
@@ -224,14 +216,4 @@ export class Undici implements Integration {
224
216
}
225
217
} ) ;
226
218
}
227
-
228
- /** */
229
- private _setupChannel (
230
- ds : typeof DiagnosticsChannel ,
231
- name : Parameters < typeof DiagnosticsChannel . channel > [ 0 ] ,
232
- ) : DiagnosticsChannel . Channel {
233
- const channel = ds . channel ( name ) ;
234
- this . _channels . add ( channel ) ;
235
- return channel ;
236
- }
237
219
}
0 commit comments