Skip to content

feat(cloudflare): Use explicit Env casting #14085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ _(Available in version [9.16.0](https://github.com/getsentry/sentry-javascript/r

You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/).

```javascript
```typescript
import * as Sentry from "@sentry/cloudflare";

class MyDurableObjectBase extends DurableObject<Env> {
// impl
// impl
}

// Export your named class as defined in your wrangler config
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
(env) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyDurableObjectBase,
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyDurableObjectBase
);
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Hono, HTTPException } from "hono";
import * as Sentry from "@sentry/cloudflare";

export default Sentry.withSentry(
(env) => {
(env: Env) => {
const { id: versionId } = env.CF_VERSION_METADATA;

return {
Expand All @@ -30,7 +30,7 @@ export default Sentry.withSentry(
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
}
};
},
// your existing worker export
app
Expand Down
4 changes: 2 additions & 2 deletions platform-includes/logs/setup/javascript.cloudflare.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
To enable logging, you need to initialize the SDK with the `_experiments.enableLogs` option set to `true`.

```js
```typescript
import * as Sentry from "@sentry/cloudflare";

export default Sentry.withSentry(
(env) => ({
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
// Enable logs to be sent to Sentry
_experiments: { enableLogs: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const onRequest = [
import * as Sentry from "@sentry/cloudflare";

export default Sentry.withSentry(
env => ({
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
// To set a uniform sample rate
tracesSampleRate: 0.2
Expand Down