getsentry / sentry-docs

Sentry's documentation (and tools to build it)
https://docs.sentry.io
Other
326 stars 1.4k forks source link

@sentry/serverless documentation for Google Cloud Functions doesn't match API #7003

Open maurocolella opened 1 year ago

maurocolella commented 1 year ago

Core or SDK?

Platform/SDK

Which part? Which one?

@sentry/serverless

Description

The documentation suggests this form to wrap CloudEvent-type Google Cloud Functions:

exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  (context, callback) => {
    throw new Error("oh, hello there!");
  }
);

But this doesn't match the actual recommended shape of handlers:

const functions = require('@google-cloud/functions-framework');

functions.cloudEvent('helloCloudEvents', (cloudevent) => {
  console.log(cloudevent.specversion);
  console.log(cloudevent.type);
  console.log(cloudevent.source);
  console.log(cloudevent.subject);
  console.log(cloudevent.id);
  console.log(cloudevent.time);
  console.log(cloudevent.datacontenttype);
});

As a result, types do not align. Code samples in git are also minimal.

Suggested Solution

Update the documentation to clearly indicate usage with the current API.

getsantry[bot] commented 1 year ago

Assigning to @getsentry/support for routing, due by (sfo). ⏲️

getsantry[bot] commented 1 year ago

Routing to @getsentry/product-owners-sdks-web-frontend for triage, due by (vie). ⏲️

lforst commented 1 year ago

Hey, thanks for reporting this. We should probably add this to the example. FWIW I think the current version still applies and we should keep it.

mattgraphlan commented 5 months ago

I cannot add sentry profiling at all to my gen2, nodejs + Typescript endpoint at all because this is missing. There type error occurs when calling:

import { MessagePublishedData } from '@google/events/cloud/pubsub/v1/MessagePublishedData';
import {
  cloudEvent,
  CloudEventFunction,
} from '@google-cloud/functions-framework';
import { CloudEventV1 } from 'cloudevents';

const main: CloudEventFunction<MessagePublishedData> = async (
  event: CloudEventV1<MessagePublishedData>,
) => {
// function here
};

cloudEvent<MessagePublishedData>(
  'topicName',
  Sentry.GCPFunction.wrapEventFunction(main),
);

The error is:

Argument of type 'EventFunctionWithCallback' is not assignable to parameter of type 'CloudEventFunction<MessagePublishedData>'.
  Target signature provides too few arguments. Expected 3 or more, but got 1

Any help is greatly appreciated, because I can't use sentry in any of my cloud functions.

Lms24 commented 5 months ago

Hey @mattgraphlan if I'm not mistaken, this problem isn't related to the original issue. Would you mind opening a new one?

My suspicion is that GCP cloud function APIs have changed or new ones were added. However, our Serverless package is generally not up to date with these more recent developments as it isn't a major focus of support for us. If you have any ideas or solutions how to use Sentry with these new APIs, feel free to let us know. We're more than happy to review PRs!