File tree Expand file tree Collapse file tree
datadog-instrumentations/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict'
22
33const shimmer = require ( '../../datadog-shimmer' )
4- const { tracingChannel } = require ( 'dc-polyfill' )
4+ const { channel , tracingChannel } = require ( 'dc-polyfill' )
55const { createWrapFetch } = require ( './helpers/fetch' )
66
77if ( globalThis . fetch ) {
88 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+ } )
1012
1113 globalThis . fetch = shimmer . wrapFunction ( fetch , fetch => wrapFetch ( fetch ) )
1214}
Original file line number Diff line number Diff line change 11'use strict'
22
3- exports . createWrapFetch = function createWrapFetch ( Request , ch ) {
3+ exports . createWrapFetch = function createWrapFetch ( Request , ch , onLoad ) {
44 return function wrapFetch ( fetch ) {
55 if ( typeof fetch !== 'function' ) return fetch
66
77 return function ( input , init ) {
8+ if ( onLoad ) {
9+ onLoad ( )
10+ onLoad = undefined
11+ }
12+
813 if ( ! ch . start . hasSubscribers ) return fetch . apply ( this , arguments )
914
1015 if ( input instanceof Request ) {
Original file line number Diff line number Diff line change @@ -28,9 +28,6 @@ loadChannel.subscribe(({ name }) => {
2828 maybeEnable ( plugins [ name ] )
2929} )
3030
31- // Globals
32- maybeEnable ( require ( '../../datadog-plugin-fetch/src' ) )
33-
3431// Always enabled
3532maybeEnable ( require ( '../../datadog-plugin-dd-trace-api/src' ) )
3633
@@ -106,6 +103,10 @@ module.exports = class PluginManager {
106103 this . _tracerConfig = config
107104 this . _tracer . _nomenclature . configure ( config )
108105
106+ if ( ! config . _isInServerlessEnvironment ?. ( ) ) {
107+ maybeEnable ( require ( '../../datadog-plugin-fetch/src' ) )
108+ }
109+
109110 for ( const name in pluginClasses ) {
110111 this . loadPlugin ( name )
111112 }
You can’t perform that action at this time.
0 commit comments