getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.76k stars 1.52k forks source link

Sentry Serverless types do not work with Firebase background functions #3269

Open jsakas opened 3 years ago

jsakas commented 3 years ago

Package + Version

@sentry/serverless

6.2.0

Description

Firebase offers a few extra types of cloud functions that do not implement the same interface as the existing GCPFunction options. It seems like these work as expected but the typings do not allow a typescript project to compile.

Primarily the ones I am most interested today are the Cloud Firestore triggers and Authentication triggers. The remaining can be found in the docs: https://firebase.google.com/docs/functions/firestore-event

Here are some examples:

const thingCreateHandler = (snap, context) => {}

export const thingCreated = functions.firestore
  .document('things/{id}')
  .onCreate(Sentry.GCPFunction.wrapEventFunction(thingCreateHandler))

Argument of type 'EventFunctionWithCallback' is not assignable to parameter of type '(snapshot: QueryDocumentSnapshot, context: EventContext) => any'.ts(2345)

const userCreateHandler = (user, context) => {}

export const userCreate = functions.auth.user().onCreate(
  Sentry.GCPFunction.wrapEventFunction(userCreateHandler)
);

Argument of type 'EventFunctionWithCallback' is not assignable to parameter of type '(user: UserRecord, context: EventContext) => any'.ts(2345)

This is what the interface looks like:

    /** Respond to the creation of a Firebase Auth user. */
    onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
    /** Respond to the deletion of a Firebase Auth user. */
    onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
jsakas commented 3 years ago

After some more testing, I've found that the GCP wrappers don't work well for Firebase functions. I think this is actually more likely a feature request to support Firebase functions entirely - which might involve new wrapper types. I'd be willing to help implement this if it's something that the Sentry team is interested in bringing in.

zanona commented 3 years ago

Yes, it would be great to have support for firebase handlers in addition to GCP. I have created some wrappers myself which I am using. However, having something similar under Sentry.Firebase.wrapHttpsOnRequestHandler would be neat.

https://gist.github.com/zanona/0f3d42093eaa8ac5c33286cc7eca1166

AbhiPrasad commented 2 years ago

PRs are welcome if anyone wants to help contribute!

github-actions[bot] commented 2 years ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

teebu commented 2 years ago

any updates on this?

beardsleym commented 2 years ago

I'd love to see Sentry <> FIrebase functions as well

abierbaum commented 2 years ago

@zanona Have you considered making a PR to add these into the core like @AbhiPrasad suggested?

zanona commented 2 years ago

Hey, @abierbaum. I am not entirely familiar with the structure Sentry expects for that add-on, and, unfortunately, I'm a little short in time to learn how to adapt that gist. However, if anyone would like to take the initial code and port into a PR form, I definitely wouldn't mind. :smiley:

samatcodeapprove commented 1 year ago

➕ another vote for this! Would be extremely useful for my team.

Bogdan1988 commented 1 year ago

One more vote, this feature can be very useful for my team as well!

michi88 commented 2 months ago

At least update the docs that firebase events are not supported (until they are) please!

AbhiPrasad commented 2 months ago

Hi @michi88 - docs PR here: https://github.com/getsentry/sentry-docs/pull/9789

Again PRs are welcome if anyone would like to contribute to this!