Skip to content

wrapCloudEventFunction incompatible with CloudEvent type from Google Cloud functions framework #16653

@flaeppe

Description

@flaeppe
Contributor

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/google-cloud-serverless@9.30.0

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/functions-framework@4.0.0, typescript@5.8.3 and @sentry/google-cloud-serverless@9.30.0
  2. Paste repro script
  3. Run tsc --noEmit, strict mode enabled

Worth noting here is that functions-framework@4.0.0 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://github.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;
}

Activity

moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 19, 2025
AbhiPrasad

AbhiPrasad commented on Jun 19, 2025

@AbhiPrasad
Member

Hey @flaeppe - thanks for writing in! I'm taking a look.

self-assigned this
on Jun 19, 2025
moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 19, 2025
AbhiPrasad

AbhiPrasad commented on Jun 19, 2025

@AbhiPrasad
Member

Opened #16661 as a fix

github-actions

github-actions commented on Jun 23, 2025

@github-actions
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #16661, which was included in the 9.31.0 release.

flaeppe

flaeppe commented on Jun 23, 2025

@flaeppe
ContributorAuthor

@AbhiPrasad I tried out the newly released changes from #16661 in https://github.com/getsentry/sentry-javascript/releases/tag/9.31.0 but it errored out on 2 other properties. Namely source and type which would also need to be required in order to have CloudEventsContext compatible with CloudEvent.

Ref: https://github.com/cloudevents/sdk-javascript/blob/c07afa9b774deefa137a960d2d11adee0bf3674a/src/event/interfaces.ts#L33-L66

export interface CloudEventV1Attributes<T> extends CloudEventV1OptionalAttributes<T> {
  /**
   * [REQUIRED] Identifies the context in which an event happened. Often this
   * will include information such as the type of the event source, the
   * organization publishing the event or the process that produced the event. The
   * exact syntax and semantics behind the data encoded in the URI is defined by
   * the event producer.
   * Producers MUST ensure that `source` + `id` is unique for each distinct event.
   * An application MAY assign a unique `source` to each distinct producer, which
   * makes it easy to produce unique IDs since no other producer will have the same
   * source. The application MAY use UUIDs, URNs, DNS authorities or an
   * application-specific scheme to create unique `source` identifiers.
   * A source MAY include more than one producer. In that case the producers MUST
   * collaborate to ensure that `source` + `id` is unique for each distinct event.
   * @required Non-empty URI-reference
   */
  source: string;

  /**
   * [REQUIRED] This attribute contains a value describing the type of event
   * related to the originating occurrence. Often this attribute is used for
   * routing, observability, policy enforcement, etc. The format of this is
   * producer defined and might include information such as the version of the
   * `type` - see
   * [Versioning of Attributes in the Primer](primer.md#versioning-of-attributes)
   * for more information.
   * @required MUST be a non-empty string
   * @should SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the
   *   organization which defines the semantics of this event type.
   * @example com.github.pull.create
   * @example com.example.object.delete.v2
   */
  type: string;
}

When also making source and type required for CloudEventsContext I didn't see any more errors.

added a commit that references this issue on Jun 23, 2025
9cd3153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

    Participants

    @flaeppe@AbhiPrasad

    Issue actions

      `wrapCloudEventFunction` incompatible with `CloudEvent` type from Google Cloud functions framework · Issue #16653 · getsentry/sentry-javascript