Skip to content

Firestore Cloud functions V2 are missing a trace in logs #1439

Closed
@milo-

Description

@milo-
Contributor

Firestore Cloud functions V2 are missing traces in logs, which makes debugging very painful.

[REQUIRED] Version info

node: 18

firebase-functions: 4.4.1

firebase-tools: 12.4.3

firebase-admin: 11.9.0

[REQUIRED] Test case

import { logger } from "firebase-functions/v2";
export const foo = onDocumentWritten(
  {
    document: "/foo/{fooId}",
  },
  async (event) => {
    logger.info("This log should have trace. But it does not 😭");
  }
);

[REQUIRED] Steps to reproduce

Create a v2 firestore function and look at the logs in the Google Cloud Logs

[REQUIRED] Expected behavior

There should be a trace, to make debugging easier. It is a massive pain to do right now.

This is how firebase-function tasks show up in the logs. Lovely, a trace. So easy to debug! 😍

CleanShot 2023-07-11 at 20 49 55@2x

[REQUIRED] Actual behavior

This is how v2 firestore logs show up. No trace, so hard to debug 😭

CleanShot 2023-07-11 at 20 48 35@2x

Were you able to successfully deploy your functions?

Yes

Activity

google-oss-bot

google-oss-bot commented on Jul 11, 2023

@google-oss-bot
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.
milo-

milo- commented on Jul 11, 2023

@milo-
ContributorAuthor

Looking at the source for other v2 triggers, they wrap all the handlers using wrapTraceContext:
https://github.com/firebase/firebase-functions/blob/master/src/v2/providers/database.ts#L471

The v2 Firestore handler isn't using wrapTraceContext:
https://github.com/firebase/firebase-functions/blob/master/src/v2/providers/firestore.ts#L448

self-assigned this
on Jul 11, 2023
ciriousjoker

ciriousjoker commented on Oct 29, 2023

@ciriousjoker

It might be worth adding that when importing v1 stuff into a v2 function (e.g. the old config(), which no longer works), the error messages produced by the v1 stuff aren't tagged with a trace.

I assume this is working as intended.

fgatti675

fgatti675 commented on Jan 10, 2024

@fgatti675

Hi,
I see this ticket marked as closed but I still don't see the traces like in previous v1 functions.
V2 sample:
Screenshot 2024-01-10 at 13 35 51
V1 sample:
Screenshot 2024-01-10 at 13 37 53
The trace id is extremely useful for finding all the logs to specific invocation. Right now it is pretty painful.
Also note that in V2 there is no tag for the function name.

I suspect there might be something wrong with my setup. This is how I initialize my API:

import { onRequest } from "firebase-functions/v2/https";
import { setGlobalOptions } from "firebase-functions/v2";
import { buildExpressApp } from "./app";

const expressApp = buildExpressApp();

setGlobalOptions({
    timeoutSeconds: 120,
    memory: "512MiB",
    region: "europe-west3"
});

export * from "./functions";

// Expose Express API as a single Cloud Function:
exports.api = onRequest(expressApp);
abdulaziz-mohammed

abdulaziz-mohammed commented on Apr 26, 2024

@abdulaziz-mohammed

why is this closed?

blidd-google

blidd-google commented on Apr 26, 2024

@blidd-google
Contributor

Hi @fgatti675, see my comment here for more details about how to trace logs from the same invocation in 2nd gen. If you are continuing to have issues, please open a new issue with a reproducible sample and we'll investigate as soon as we can.

fgatti675

fgatti675 commented on Apr 29, 2024

@fgatti675

Hi @fgatti675, see my comment here for more details about how to trace logs from the same invocation in 2nd gen. If you are continuing to have issues, please open a new issue with a reproducible sample and we'll investigate as soon as we can.

Thank you! We managed to get the traces working again, we were really missing this.
As a comment, they only work using the logger imported from firebase-functions/logger, it doesn't work using console.log, but much appreciated

fgatti675

fgatti675 commented on Sep 23, 2024

@fgatti675

Traces are gone, not sure since when, with no changes in our side.
You don't understand how frustrating this is.
Really, what is going on at Google?

Byrontoo

Byrontoo commented on Sep 29, 2024

@Byrontoo
  1. After 2024-09-13 10:29:33.257514 UTC, the traces are lost in the prod environment, but occasionally appears in other environments;
  2. The trace is shortened in v2api, without the prefix: /projects/${projectId}
  3. resource type: Cloud Run Revision
  4. There is an additional field in the label node: execution_id
adamxi

adamxi commented on Oct 3, 2024

@adamxi

@Byrontoo: We were having the same issues. Suddenly our stack traces were shortened after a redeploy, yet no firebase related dependencies had been updated. In fact, through much debugging it seemed that the logging.googleapis.com/trace log entry cannot be set manually AT ALL despite the documentation still indicating otherwise. In production this always gets overwritten.

So it appears that during function deployment, the functions-framework dependency is added to the build, unless already included (which it isn't for our project). In a recent update to the functions-framework library, the LOG_EXECUTION_ID env variable was introduced. Inspecting this on the deployed 2nd gen cloud function from the variables tab, to seems to default to true, despite the documentation stating otherwise. And yes.. after a redeploy with LOG_EXECUTION_ID=false our log trace values were working as before and no longer shortened.

So LOG_EXECUTION_ID=true effectively overwrites logging.googleapis.com/trace and also logging.googleapis.com/spanId it seems. Very frustrating to suddenly have stuff break in production like this.

7 remaining items

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @jits@milo-@fgatti675@gillycheesesteak@adamxi

    Issue actions

      Firestore Cloud functions V2 are missing a trace in logs · Issue #1439 · firebase/firebase-functions