firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.01k stars 202 forks source link

Structured logging error context not being serialized #1556

Closed kdawgwilk closed 1 month ago

kdawgwilk commented 2 months ago

Related issues

[REQUIRED] Version info

node:

v18.19.1

firebase-functions:

4.9.0

firebase-tools:

13.3.1

firebase-admin:

12.1.0

[REQUIRED] Test case

index.ts

export const testErrorContext = onRequest((req, res) => {
  try {
    throw new Error('Some Random Error')
  } catch (err) {
    error('Error running some code', {
      error: err,
      tenantId: myInternalContext.tenantId,
    });
  }
  res.status(200).send('Function ran!')
});

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

The jsonPayload.error field would have the serialized error info

[REQUIRED] Actual behavior

The jsonPayload.error field comes through as image

Were you able to successfully deploy your functions?

Yes

google-oss-bot commented 2 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

kdawgwilk commented 2 months ago

It looks like this might be because the firebase-functions/logger has special case handling for errors passed as the context object but how do i add my own context to that?

kdawgwilk commented 1 month ago

I ended up using the serialize-error library and handling the serialization myself