firebase / firebase-functions

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

FEAT: Add logger compat module for v2 restoring fully v1 behavior when using standard console #1534

Open JonatanSalas opened 3 months ago

JonatanSalas commented 3 months ago

Description

In firebase-functions v1 when using the standard console you'd visualize logs under cloud run with a traceId.

In v2 that behavior has gone, there's a module to patch the console but that method only makes console work again by adjusting the way it logs the user inserted messages.

Screenshot 2024-03-04 at 14 30 04

If we want to have the trace attached to each log emitted by a function we need to use the firebase logger module which is provided by firebase functions.

Since the logger compat module doesn't restore the behavior under v1, I've made an adaptation to ensure it works as expected and keeps the traceId.

The code is a draft, I've added a v2 folder inside the logger folder which I think is wrong but I've done so we can start discussing if this adjustment is possible and where it should go.