Skip to content

fix(aws-lambda): reduced cold start duration#2321

Open
aryamohanan wants to merge 20 commits intomainfrom
fix-cold-start
Open

fix(aws-lambda): reduced cold start duration#2321
aryamohanan wants to merge 20 commits intomainfrom
fix-cold-start

Conversation

@aryamohanan
Copy link
Contributor

@aryamohanan aryamohanan commented Feb 2, 2026

This PR avoids lazy loading OpenTelemetry instrumentations in the AWS Lambda environment.

In AWS Lambda, lazy loading causes OpenTelemetry instrumentations to be initialized during the first invocation, which adds 1900–2100 ms of latency to cold starts and increases billable execution time.

To address this, instrumentations are preloaded during the Lambda initialization step instead of being loaded lazily at runtime.

With this change, cold start overhead is significantly reduced, bringing initialization time down from approximately 1900 ms to 500 ms, resulting in faster executions and lower costs in AWS Lambda environments.

Ref: https://ibm.ent.box.com/notes/2107188531951
https://jsw.ibm.com/browse/INSTA-74767

@aryamohanan aryamohanan changed the title Fix cold start fix: preload OpenTelemetry instrumentations in AWS Lambda Feb 2, 2026
@aryamohanan aryamohanan changed the title fix: preload OpenTelemetry instrumentations in AWS Lambda fix: preloaded otel instrumentations in AWS Lambda Feb 2, 2026
const { AsyncHooksContextManager } = require('@opentelemetry/context-async-hooks');
const { W3CTraceContextPropagator, hrTimeDuration, hrTimeToMilliseconds } = require('@opentelemetry/core');
const api = require('@opentelemetry/api');
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');
Copy link
Contributor

@kirrg001 kirrg001 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracing/index.js

exports.preinit
   otelIntegration.preInit()

wrap.js

exports.preInit(config)
  if (config.preloadOpentelemetry)
     AsyncHooksContextManager = require(@opentelemetry/context-async-hooks)
     ...
     
     instrumentations.forEach
       instrumentation.preInit()
     
    

exports.init
   ....

  AsyncHooksContextManager = AsyncHooksContextManager || require(@opentelemetry/context-async-hooks)

fs.js

exports.preInit
   fs = require(@opentelemetry/instrumentation-fs)

The goal should be that the instrumentation owns the name. IMO the instrumentation.js file is not needed rn.

@aryamohanan aryamohanan requested a review from kirrg001 February 3, 2026 16:47
Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit suggestion:

fix(aws-lambda): reduced cold start duration

@aryamohanan aryamohanan changed the title fix: preloaded otel instrumentations in AWS Lambda fix(aws-lambda): reduced cold start duration Feb 4, 2026
@aryamohanan aryamohanan marked this pull request as ready for review February 4, 2026 12:16
@aryamohanan aryamohanan requested a review from a team as a code owner February 4, 2026 12:16
Comment on lines 78 to 83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we reuse initInstrumentations?

@instana instana deleted a comment from sonarqubecloud bot Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants