Skip to content

Conversation

@JPeer264
Copy link
Member

@JPeer264 JPeer264 commented Nov 24, 2025

closes #18294

Problem

In #18064 we fixed that any Cloudflare compatible app can be passed and the original types were passed (e.g. Hono). This caused a problem with the environment variables, as they were not inferred correctly. Those are two scenarios which should work:

  1. That we can wrap any app (e.g. Hono), which is compatible with Cloudflare and ensure the types are there (actually what fix(cloudflare): Ensure types for cloudflare handlers #18064 should have solved - but it introduced a bug)
  2. The optionCallback infers the correct types, based on the handler it was given

Solution

To ensure now that types are passed through (for e.g. Hono) and the all necessary types are inferred correctly, there is now only one source of truth for the types in the generics.

So instead of having withSentry<Env = unknown, ..., T extends ExportedHandler<Env>>() it is now withSentry<Handler extends ExportedHandler<Env>> and whenever we would need the types, we actively infer them inside the function with InferEnv<Env>. With that approach we make sure both scenarios work properly

The tests are now using the correct types as well (that was not the case and was the main issue why #18064 went through)


This is now also true for .instrumentDurableObjectWithSentry() and .instrumentWorkflowWithSentry().

@JPeer264 JPeer264 marked this pull request as ready for review November 24, 2025 11:46
@JPeer264 JPeer264 added this to the 11.0.0 milestone Nov 24, 2025
@JPeer264 JPeer264 self-assigned this Nov 24, 2025
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, this PR introduces breaking changes to the way generics are used and we can thus not merge this in this major.

Let's add this to the v11 milestone and fix it then, for now document what users have to do to get correct types.

JPeer264 added a commit that referenced this pull request Nov 26, 2025
This PR is a result of
#18302. This ensures
that the types are checked throughout the development of the Cloudflare
SDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare types for env no longer work

3 participants