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

event.locals & event.platform for universal load when running in SSR #13343

Open
ktarmyshov opened this issue Jan 18, 2025 · 3 comments
Open

Comments

@ktarmyshov
Copy link

Describe the problem

Hi, I recently ran into a problem with using static web apps azure adapter.

Each request to azure function (backend of the app) is accompanied with an invocation context, which holds methods (v3) or object (v4) to log. Adapter puts it to the event.platform, which is fine and expected.

With the .server.ts it's all pretty clear, the event.locals would hold the logger, which is bound to event.platform. But in the universal function during the SSR there is no way to access that logger (except singletons)

So if an error happens in the universal function in SSR mode, there is no way to report it (beside sentry, for example), console.log methods are ignored by the azure functions.

It would be nice to have the locals and platform available (as optionals) to the universal load in the SSR mode, if that makes sense.

Thank you very much in advance!

Describe the proposed solution

Optionals event.locals & event.platform when SSR is running.

Alternatives considered

TLDR: pain & singletons

hooks.server.ts

...
event.locals.logger = new Logger(...)
setSSRRequestLogger(requestId, logger); // These are flushed and deleted periodically e.g. each 5 secs
...

root +layout.server.ts

...
return {
 requestId,
correlationId,
}

root +layout.ts

if (browser) {
 return {
  some data
 }
} else {
 return {
  somedata,
  requestId: event.data.requestId,
  correlationId: event.data.correlationId
 }
}

child +layout.ts

if (browser) {
 create local logger/console
} else {
 await parentData()
 logger = singleton.getLogger(parentData.requestId)
 .... catch(error) {
   logger.report(error)
 }
}

Importance

would make my life easier

Additional Information

No response

@eltigerchino
Copy link
Member

Have you tried using the handleError hook?
https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError

@ktarmyshov
Copy link
Author

This is only for unexpected/unhandled errors right? Or can I change the returned status code here?

@eltigerchino
Copy link
Member

This is only for unexpected/unhandled errors right?

Yes, only uncaught errors.

Or can I change the returned status code here?

No, I don't think so.

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

No branches or pull requests

2 participants