Closed
@flaeppe

Description

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/google-cloud-serverless

SDK Version

9.30.0

Framework Version

@sentry/[email protected]

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "@sentry/google-cloud-serverless";
import { type CloudEvent } from "@google-cloud/functions-framework";
Sentry.wrapCloudEventFunction(async (cloudevent: CloudEvent<any>) => {});

Steps to Reproduce

  1. Install @google-cloud/[email protected], [email protected] and @sentry/[email protected]
  2. Paste repro script
  3. Run tsc --noEmit, strict mode enabled

Worth noting here is that [email protected] installs "cloudevents": "^8.0.2"

Expected Result

No typechecking errors

Actual Result

> tsc --noEmit

index.ts:30:31 - error TS2345: Argument of type '(cloudevent: CloudEvent<any>) => Promise<void>' is not assignable to parameter of type 'CloudEventFunction | CloudEventFunctionWithCallback'.
  Type '(cloudevent: CloudEvent<any>) => Promise<void>' is not assignable to type 'CloudEventFunction'.
    Types of parameters 'cloudevent' and 'cloudevent' are incompatible.
      Type 'CloudEventsContext' is not assignable to type 'CloudEventV1<any>'.
        Types of property 'id' are incompatible.
          Type 'string | undefined' is not assignable to type 'string'.
            Type 'undefined' is not assignable to type 'string'.

30 Sentry.wrapCloudEventFunction(async (cloudevent: CloudEvent<any>) => {});
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To rephrase the error message; problem is that attributes of the CloudEventsContext interface from Sentry are not matching with the CloudEvent interface from Google's functions framework package, where CloudEvent is reexported from cloudevents.

CloudEventsContext from Sentry:

export interface CloudEventsContext {
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
type?: string;
specversion?: string;
source?: string;
id?: string;
time?: string;
schemaurl?: string;
contenttype?: string;
}

vs. CloudEvent from functions framework (via cloudevents) (ref: https://.com/cloudevents/sdk-javascript/blob/c07afa9b774deefa137a960d2d11adee0bf3674a/src/event/interfaces.ts#L10-L31):

export interface CloudEventV1<T> extends CloudEventV1Attributes<T> {
  // REQUIRED Attributes
  /**
   * [REQUIRED] Identifies the event. Producers MUST ensure that `source` + `id`
   * is unique for each distinct event. If a duplicate event is re-sent (e.g. due
   * to a network error) it MAY have the same `id`. Consumers MAY assume that
   * Events with identical `source` and `id` are duplicates.
   * @required Non-empty string. Unique within producer.
   * @example An event counter maintained by the producer
   * @example A UUID
   */
  id: string;

  /**
   * [REQUIRED] The version of the CloudEvents specification which the event
   * uses. This enables the interpretation of the context. Compliant event
   * producers MUST use a value of `1.0` when referring to this version of the
   * specification.
   * @required MUST be a non-empty string.
   */
  specversion: string;
}