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

Make AWS layer work with ESM #8140

Closed
sl0thentr0py opened this issue May 16, 2023 · 4 comments
Closed

Make AWS layer work with ESM #8140

sl0thentr0py opened this issue May 16, 2023 · 4 comments
Assignees
Labels
Package: aws-serverless Issues related to the Sentry AWS Serverless SDK Package: serverless Issues related to the Sentry Serverless SDK Type: Improvement
Milestone

Comments

@sl0thentr0py
Copy link
Member

Problem Statement

make a new lambda function with

// index.mjs - doesn't work
export const handler = (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    

    throw new Error("test error");  
    return response;
};

Solution Brainstorm

need to make this work with esm

function tryRequire<T>(taskRoot: string, subdir: string, mod: string): T {
const lambdaStylePath = resolve(taskRoot, subdir, mod);
if (existsSync(lambdaStylePath) || existsSync(`${lambdaStylePath}.js`)) {
// Lambda-style path
return require(lambdaStylePath);
}
// Node-style path
return require(require.resolve(mod, { paths: [taskRoot, subdir] }));
}

@sl0thentr0py sl0thentr0py added Type: Improvement Package: serverless Issues related to the Sentry Serverless SDK Status: Backlog labels May 16, 2023
@sl0thentr0py sl0thentr0py self-assigned this May 16, 2023
@stefandarius
Copy link

stefandarius commented Jul 5, 2023

Hi! I am trying to instrument a lambda function written with ESM. Any updates on this improvement?

@floriangosse
Copy link
Contributor

I think the best solution would be to ship an ESM version next to the CJS version. Otherwise we would have to modify the package.json and remove the module property so that Node.js, even when imported from a ESM, would load the CJS version.

@AbhiPrasad
Copy link
Member

Fixed with 8.0.0-beta.4: https://github.com/getsentry/sentry-javascript/releases/tag/8.0.0-beta.4

addOpenTelemetryInstrumentation(
new AwsLambdaInstrumentation({
requestHook(span) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws-lambda');
},
}),
);

@AbhiPrasad AbhiPrasad added the Package: aws-serverless Issues related to the Sentry AWS Serverless SDK label Apr 24, 2024
@AbhiPrasad AbhiPrasad added this to the 8.0.0 milestone Apr 24, 2024
@AbhiPrasad
Copy link
Member

superceded by #12409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: aws-serverless Issues related to the Sentry AWS Serverless SDK Package: serverless Issues related to the Sentry Serverless SDK Type: Improvement
Projects
Archived in project
Development

No branches or pull requests

7 participants