Skip to content

Using Exceptionless for nodejs causes problems with AWS Lambda functions #140

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

Closed
kareldonk opened this issue Oct 23, 2023 · 7 comments
Closed

Comments

@kareldonk
Copy link

I tried using the exceptionless client for nodejs @exceptionless/node version 3.0.4 as follows:

 await Exceptionless.startup(c => {
            c.apiKey = 'blah';
        });

When running the program as an AWS Lambda function, it throws the following error:

{
    "errorType": "Error",
    "errorMessage": "ENOENT: no such file or directory, mkdir '/var/task/.exceptionless'",
    "code": "ENOENT",
    "errno": -2,
    "syscall": "mkdir",
    "path": "/var/task/.exceptionless",
    "stack": [
        "Error: ENOENT: no such file or directory, mkdir '/var/task/.exceptionless'",
        "    at Object.mkdirSync (node:fs:1398:3)",
        "    at LocalStorage._init (/var/task/node_modules/node-localstorage/LocalStorage.js:174:16)",
        "    at new LocalStorage (/var/task/node_modules/node-localstorage/LocalStorage.js:114:14)",
        "    at NodeExceptionlessClient.startup (file:///var/task/node_modules/@exceptionless/node/dist/NodeExceptionlessClient.js:13:57)",
        "    at ExceptionlessService.startup (file:///var/task/dist/services/exceptionless.service.js:27:29)",
        "    at AppModule.getAppContext (file:///var/task/dist/app.module.js:34:40)",
        "    at async AppModule.getAppService (file:///var/task/dist/app.module.js:40:25)",
        "    at async handle (file:///var/task/dist/index.js:17:24)",
        "    at async Runtime.handler (file:///var/task/dist/index.js:6:5)",
        "    at async Runtime.handleOnceStreaming (file:///var/runtime/index.mjs:1206:26)"
    ]
}

This is caused by the NodeExceptionlessClient class using the LocalStoragePolyfill.
It's not possible to write to the partition where the script runs on AWS Lambda as far as I know. I couldn't find a way to override the usage of the LocalStoragePolyfill to use memory storage either. Am I overlooking something or is this an issue that needs to be addressed?

@ejsmith
Copy link
Member

ejsmith commented Oct 23, 2023

https://github.com/exceptionless/Exceptionless.JavaScript/blob/main/packages/node/src/NodeExceptionlessClient.ts

That is setting up localstorage, there is also an InMemoryStorage implementation.

I believe you can do something like:

await Exceptionless.startup(c => {
    c.apiKey = 'blah';
    c.services.storage = new InMemoryStorage();
});

@kareldonk
Copy link
Author

@ejsmith I tried that but get the same issue. It seems that the localstorage on line 22 gets initialized before the chance to override which happens after line 35.

@ejsmith
Copy link
Member

ejsmith commented Oct 23, 2023

Hmm... that stinks. Guess we should put this line in a try catch and fallback to using InMemoryStorage if it fails. Could you create a PR for that?

@niemyjski
Copy link
Member

Should just need to try catch it. If it fails then it will default to in memory out of the box

@kareldonk
Copy link
Author

If I try/catch it, the Node* plugins being added on the following lines after line 22 won't have been added. I'm assuming that they are important and that I want to use them of course.
It would be better if I could somehow communicate to the NodeExceptionlessClient that it should not use the localstorage but leave the memorystorage as is.
Or, delay initialization of the localstorage, allowing for override to happen during startup.

@niemyjski
Copy link
Member

@kareldonk This has been fixed in https://github.com/exceptionless/Exceptionless.JavaScript/releases/tag/v3.0.5 Please let us know if you have any questions.

@kareldonk
Copy link
Author

Thanks, that was quick. I already deployed it and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants