@@ -5,7 +5,7 @@ import { patchHttp, unpatchHttp } from "./patch-http";
55import { extractTriggerTags , extractHTTPStatusCodeTag , parseEventSource } from "./trigger" ;
66import { ColdStartTracerConfig , ColdStartTracer } from "./cold-start-tracer" ;
77import { logDebug , tagObject } from "../utils" ;
8- import { didFunctionColdStart , isProactiveInitialization } from "../utils/cold-start" ;
8+ import { didFunctionColdStart , isProactiveInitialization , isManagedInstancesMode } from "../utils/cold-start" ;
99import { datadogLambdaVersion } from "../constants" ;
1010import { ddtraceVersion , parentSpanFinishTimeHeader , DD_SERVICE_ENV_VAR } from "./constants" ;
1111import { patchConsole } from "./patch-console" ;
@@ -179,20 +179,27 @@ export class TraceListener {
179179 }
180180 const coldStartNodes = getTraceTree ( ) ;
181181 if ( coldStartNodes . length > 0 ) {
182- const coldStartConfig : ColdStartTracerConfig = {
183- tracerWrapper : this . tracerWrapper ,
184- parentSpan :
185- didFunctionColdStart ( ) || isProactiveInitialization ( )
186- ? this . inferredSpan || this . wrappedCurrentSpan
187- : this . wrappedCurrentSpan ,
188- lambdaFunctionName : this . context ?. functionName ,
189- currentSpanStartTime : this . wrappedCurrentSpan ?. startTime ( ) ,
190- minDuration : this . config . minColdStartTraceDuration ,
191- ignoreLibs : this . config . coldStartTraceSkipLib ,
192- isColdStart : didFunctionColdStart ( ) || isProactiveInitialization ( ) ,
193- } ;
194- const coldStartTracer = new ColdStartTracer ( coldStartConfig ) ;
195- coldStartTracer . trace ( coldStartNodes ) ;
182+ // Skip creating cold start spans in managed instances mode
183+ // since the gap between the sandbox init and the function
184+ // invocation might be too large to provide a useful trace and
185+ // experience
186+ if ( ! isManagedInstancesMode ( ) ) {
187+ const coldStartConfig : ColdStartTracerConfig = {
188+ tracerWrapper : this . tracerWrapper ,
189+ parentSpan :
190+ didFunctionColdStart ( ) || isProactiveInitialization ( )
191+ ? this . inferredSpan || this . wrappedCurrentSpan
192+ : this . wrappedCurrentSpan ,
193+ lambdaFunctionName : this . context ?. functionName ,
194+ currentSpanStartTime : this . wrappedCurrentSpan ?. startTime ( ) ,
195+ minDuration : this . config . minColdStartTraceDuration ,
196+ ignoreLibs : this . config . coldStartTraceSkipLib ,
197+ isColdStart : didFunctionColdStart ( ) || isProactiveInitialization ( ) ,
198+ } ;
199+ const coldStartTracer = new ColdStartTracer ( coldStartConfig ) ;
200+ coldStartTracer . trace ( coldStartNodes ) ;
201+ }
202+ // Always clear the tree to prevent memory leaks, even if we skip span creation
196203 clearTraceTree ( ) ;
197204 }
198205 if ( this . triggerTags ) {
0 commit comments