Skip to content

Commit faac9b6

Browse files
fix
1 parent d403ea6 commit faac9b6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/instrumentation-patch.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,20 @@ function patchAwsSdkCredentialExtraction(instrumentation: Instrumentation): void
417417
const originalHandler = originalPatch.call(this, moduleVersion, original);
418418

419419
return function (this: any, _handler: any, awsExecutionContext: HandlerExecutionContext) {
420-
const resolvedHandler = originalHandler.call(this, _handler, awsExecutionContext);
420+
const origPatchedHandler = originalHandler.call(this, _handler, awsExecutionContext);
421421

422-
return function (this: any, command: any): Promise<any> {
423-
// Suppress tracing **before** resolving credentials to avoid recursive send() triggering our instrumentation again
424-
return otelContext.with(suppressTracing(otelContext.active()), async () => {
422+
return async function (this: any, command: any): Promise<any> {
423+
const clientConfig = command[V3_CLIENT_CONFIG_KEY];
424+
const originalPromise = origPatchedHandler.call(this, command);
425+
426+
await otelContext.with(suppressTracing(otelContext.active()), async () => {
425427
try {
426-
const clientConfig = command[V3_CLIENT_CONFIG_KEY];
427428
const [credentials, region] = await Promise.all([
428429
clientConfig?.credentials?.(),
429430
clientConfig?.region?.(),
430431
]);
431432

432-
const activeContext = otelContext.active();
433-
const span = trace.getSpan(activeContext);
433+
const span = trace.getActiveSpan();
434434
if (span) {
435435
if (credentials?.accessKeyId) {
436436
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_AUTH_ACCOUNT_ACCESS_KEY, credentials.accessKeyId);
@@ -442,10 +442,8 @@ function patchAwsSdkCredentialExtraction(instrumentation: Instrumentation): void
442442
} catch (e) {
443443
// Don't crash or log unless debugging
444444
}
445-
446-
// Now proceed with the handler (unsuppressed, so actual span can record API call)
447-
return resolvedHandler.call(this, command);
448445
});
446+
return originalPromise;
449447
};
450448
};
451449
};

0 commit comments

Comments
 (0)