File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
datadog-instrumentations/src Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const shimmer = require ( '../../datadog-shimmer' )
4
- const { tracingChannel } = require ( 'dc-polyfill' )
4
+ const { channel , tracingChannel } = require ( 'dc-polyfill' )
5
5
const { createWrapFetch } = require ( './helpers/fetch' )
6
6
7
7
if ( globalThis . fetch ) {
8
8
const ch = tracingChannel ( 'apm:fetch:request' )
9
- const wrapFetch = createWrapFetch ( globalThis . Request , ch )
9
+ const wrapFetch = createWrapFetch ( globalThis . Request , ch , ( ) => {
10
+ channel ( 'dd-trace:instrumentation:load' ) . publish ( { name : 'fetch' } )
11
+ } )
10
12
11
13
globalThis . fetch = shimmer . wrapFunction ( fetch , fetch => wrapFetch ( fetch ) )
12
14
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- exports . createWrapFetch = function createWrapFetch ( Request , ch ) {
3
+ exports . createWrapFetch = function createWrapFetch ( Request , ch , onLoad ) {
4
4
return function wrapFetch ( fetch ) {
5
5
if ( typeof fetch !== 'function' ) return fetch
6
6
7
7
return function ( input , init ) {
8
+ if ( onLoad ) {
9
+ onLoad ( )
10
+ onLoad = undefined
11
+ }
12
+
8
13
if ( ! ch . start . hasSubscribers ) return fetch . apply ( this , arguments )
9
14
10
15
if ( input instanceof Request ) {
Original file line number Diff line number Diff line change @@ -28,9 +28,6 @@ loadChannel.subscribe(({ name }) => {
28
28
maybeEnable ( plugins [ name ] )
29
29
} )
30
30
31
- // Globals
32
- maybeEnable ( require ( '../../datadog-plugin-fetch/src' ) )
33
-
34
31
// Always enabled
35
32
maybeEnable ( require ( '../../datadog-plugin-dd-trace-api/src' ) )
36
33
@@ -106,6 +103,10 @@ module.exports = class PluginManager {
106
103
this . _tracerConfig = config
107
104
this . _tracer . _nomenclature . configure ( config )
108
105
106
+ if ( ! config . _isInServerlessEnvironment ?. ( ) ) {
107
+ maybeEnable ( require ( '../../datadog-plugin-fetch/src' ) )
108
+ }
109
+
109
110
for ( const name in pluginClasses ) {
110
111
this . loadPlugin ( name )
111
112
}
You can’t perform that action at this time.
0 commit comments