firebase / firebase-functions

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

FIX: Add wrapTraceContext to onChangedOperation to enable traceId on onDocumentUpdated #1533

Open JonatanSalas opened 3 months ago

JonatanSalas commented 3 months ago

Description

When using firebase-functions v2 traceId is missing for Firestore triggers like onDocumentUpdated.

After a deep dive into the repository's code I've found that there's a difference.

onDocumentCreated relies in the method onOperation which wraps the event handler with the function wrapTraceContext that injects the trace information.

Screenshot 2024-03-04 at 14 14 44

On the other side, onDocumentUpdated relies in the method onChangedOperation which executes the event handler without using the wrapTraceContext function. I don't know if this is intentional, but this is a problem of those who are heavy users of firebase functions under the v2 because in previous version the traceId was available.

Screenshot 2024-03-04 at 14 14 59

I've adapted the code to make onChangedOperation use the wrapTraceContext function. With that line I think we can solve the issue of missing traceId in onDocumentUpdated.

google-cla[bot] commented 3 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

exaby73 commented 3 weeks ago

Hey @JonatanSalas. Can you fix the conflicts?

JonatanSalas commented 3 weeks ago

@exaby73 sure!