Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove handling of promises + fix issues connecting unrelated traces #50

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions nodejs/packages/cx-wrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,7 @@ export const handler = (event: any, context: Context, callback: Callback) => {
diag.debug(`Instrumenting handler`);
const patchedHandler = lambdaInstrumentation.getPatchHandler(originalHandler) as any as Handler;
diag.debug(`Running CX handler and redirecting to ${process.env.CX_ORIGINAL_HANDLER}`)
const maybePromise = patchedHandler(event, context, callback);
if (typeof maybePromise?.then === 'function') {
maybePromise.then(
value => {
context.callbackWaitsForEmptyEventLoop = false;
callback(null, value);
},
(err: Error | string | null | undefined) => {
if (err === undefined || err === null) {
context.callbackWaitsForEmptyEventLoop = false;
callback('handled', null);
} else {
context.callbackWaitsForEmptyEventLoop = false;
callback(err, null);
}
}
);
}
patchedHandler(event, context, callback);
} catch (err: any) {
context.callbackWaitsForEmptyEventLoop = false;
callback(err, null);
Expand Down
12 changes: 6 additions & 6 deletions nodejs/packages/cx-wrapper/lambda-instrumentation-init.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
context as otelContext,
defaultTextMapGetter,
Context as OtelContext,
propagation,
trace,
diag
diag,
ROOT_CONTEXT
} from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { AwsLambdaInstrumentation, AwsLambdaInstrumentationConfig } from '@opentelemetry/instrumentation-aws-lambda';
Expand Down Expand Up @@ -35,7 +35,7 @@ export function makeLambdaInstrumentation(): AwsLambdaInstrumentation {
// try to extract propagation from http headers first
const httpHeaders = event?.headers || {};
const extractedHttpContext: OtelContext = propagation.extract(
otelContext.active(),
ROOT_CONTEXT,
httpHeaders,
defaultTextMapGetter
);
Expand All @@ -48,7 +48,7 @@ export function makeLambdaInstrumentation(): AwsLambdaInstrumentation {
try {
const extractedClientContextOtelContext: OtelContext =
propagation.extract(
otelContext.active(),
ROOT_CONTEXT,
context.clientContext.Custom,
defaultTextMapGetter
);
Expand All @@ -65,7 +65,7 @@ export function makeLambdaInstrumentation(): AwsLambdaInstrumentation {
try {
const extractedClientContextOtelContext: OtelContext =
propagation.extract(
otelContext.active(),
ROOT_CONTEXT,
(context.clientContext as any).custom,
defaultTextMapGetter
);
Expand All @@ -79,7 +79,7 @@ export function makeLambdaInstrumentation(): AwsLambdaInstrumentation {
);
}
}
return otelContext.active();
return ROOT_CONTEXT;
},
payloadSizeLimit: OTEL_PAYLOAD_SIZE_LIMIT,
};
Expand Down
Loading