getsentry / sentry-docs

Sentry's documentation (and tools to build it)
https://docs.sentry.io
Other
332 stars 1.45k 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 8 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 8 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!

shevy11 commented 3 months ago

any updates on this one?

lforst commented 3 months ago

@shevy11 no updates. You will see it here.

Janscode commented 1 month ago

If I'm not mistaken this isn't just a content issue, the current Sentry.GCPFunction.wrapCloudEventFunction has a function signature that is incompatible with functions-framework. Trying to do:

import * as functions from "@google-cloud/functions-framework";
import * as Sentry from "@sentry/serverless";
functions.cloudEvent('helloCloudEvents',  Sentry.GCPFunction.wrapCloudEventFunction(async (cloudEvent: functions.CloudEventFunction) => {
 })

Throws a type error:

Argument of type 'CloudEventFunctionWithCallback' is not assignable to parameter of type 'CloudEventFunction<unknown>'.
  Target signature provides too few arguments. Expected 2 or more, but got 1.
chargome commented 1 month ago

@Janscode the current way of instrumenting cloud event functions is documented in https://docs.sentry.io/platforms/javascript/guides/gcp-functions/ , if this however does not work for you then you will have to fall back to using @sentry/node and use manual instrumentation. Hope this helps you getting started for now!

lforst commented 1 month ago

@Janscode I think you are correct that the current SDK is a bit outdated with regards to the newer cloud function interface. We need to update it but haven't gotten round to doing so. We accept PRs.