Skip to content
Closed
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
@@ -0,0 +1,140 @@
import {
PlatformContentPayload,
RUNTIMES,
} from 'sentry-docs/components/frameworkSelector/frameworks';
import {getFileBySlugWithCache} from 'sentry-docs/mdx';
import {resolvePlatformContent} from 'sentry-docs/platformContentResolver';

/**
* Serves the compiled MDX of a `<PlatformContent>` include as it applies to a framework running
* on a runtime, so a runtime's page can swap in framework snippets client-side
* (see `<FrameworkSelector>`).
*
* Only the combinations from `generateStaticParams` are built; there is no runtime rendering.
*/

export const dynamic = 'force-static';
export const dynamicParams = false;

export function generateStaticParams() {
return Object.entries(RUNTIMES).flatMap(([runtime, {frameworks, includePaths}]) =>
frameworks.flatMap(({key: framework}) =>
includePaths.map(includePath => ({
platform: 'javascript',
runtime,
framework,
includePath: includePath.split('/'),
}))
)
);
}

type SlugFile = Awaited<ReturnType<typeof getFileBySlugWithCache>>;

async function tryGetFile(slug: string): Promise<SlugFile | undefined> {
try {
return await getFileBySlugWithCache(slug);
} catch {
return undefined;
}
}

/**
* Resolves an include for a framework on a runtime:
* 1. `<platform>.<runtime>.<framework>`, for snippets specific to both
* 2. On Node.js, the framework guide's content, which falls back to Node.js
* Elsewhere, only a `<platform>.<framework>` snippet, to not pull in Node.js content
* 3. The runtime guide's own content
*/
async function resolveForFramework(
includePath: string,
platform: string,
runtime: string,
framework: string
): Promise<SlugFile | undefined> {
const base = `platform-includes/${includePath}/${platform}`;

const doc = await tryGetFile(`${base}.${runtime}.${framework}`);
if (doc) {
return doc;
}

if (runtime === 'node') {
return resolvePlatformContent({
includePath,
path: ['platforms', platform, 'guides', framework],
});
}

return (
(await tryGetFile(`${base}.${framework}`)) ??
resolvePlatformContent({
includePath,
path: ['platforms', platform, 'guides', runtime],
})
);
}

const INCLUDE_RE = /<Include\s+name=["']([^"']+)["']/g;
const PLATFORM_CONTENT_RE = /<PlatformContent\s+includePath=["']([^"']+)["']/g;

async function collectNested(
source: string,
resolve: (includePath: string) => Promise<SlugFile | undefined>,
payload: PlatformContentPayload
) {
for (const [, rawName] of source.matchAll(INCLUDE_RE)) {
const name = rawName.replace(/\.mdx$/, '');
if (name in payload.includes) {
continue;
}
// Missing includes render nothing, same as <Include>.
const doc = await tryGetFile(`includes/${name}`);
if (doc) {
payload.includes[name] = doc.mdxSource;
await collectNested(doc.matter.content, resolve, payload);
}
}

for (const [, includePath] of source.matchAll(PLATFORM_CONTENT_RE)) {
if (includePath in payload.platformContents) {
continue;
}
const doc = await resolve(includePath);
payload.platformContents[includePath] = doc?.mdxSource ?? null;
if (doc) {
await collectNested(doc.matter.content, resolve, payload);
}
}
}

export async function GET(
_request: Request,
{
params,
}: {
params: Promise<{
framework: string;
includePath: string[];
platform: string;
runtime: string;
}>;
}
) {
const {platform, runtime, framework, includePath} = await params;
const resolve = (path: string) =>
resolveForFramework(path, platform, runtime, framework);

const doc = await resolve(includePath.join('/'));

const payload: PlatformContentPayload = {
code: doc?.mdxSource ?? null,
includes: {},
platformContents: {},
};
if (doc) {
await collectNested(doc.matter.content, resolve, payload);
}

return Response.json(payload);
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,47 @@ Sentry.init({
});
```

## Options

### `shouldHandleError`

A function that decides whether an error is captured. By default, errors with a 5xx status code (and errors with a 2xx status code or lower) are captured, and errors with a 3xx or 4xx status code aren't.

```typescript
declare function shouldHandleError(
error: Error,
request: FastifyRequest,
reply: FastifyReply
): boolean;
```

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.fastifyIntegration({
shouldHandleError(error, request, reply) {
return reply.statusCode >= 500;
},
}),
],
});
```

If you use TypeScript, cast the request and reply to get full type safety:

```typescript
import type { FastifyRequest, FastifyReply } from "fastify";

Sentry.fastifyIntegration({
shouldHandleError(error, minimalRequest, minimalReply) {
const request = minimalRequest as FastifyRequest;
const reply = minimalReply as FastifyReply;
return reply.statusCode >= 500;
},
});
```

## Supported Versions

- `fastify`: `^3.21.0 || ^4.0.0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Scrubbing Sensitive Data"
description: "Learn about filtering or scrubbing sensitive data within the Sentry JavaScript SDK, so that data is not sent with the event. You can also configure server-side scrubbing to ensure the data is not stored."
customCanonicalTag: "/platforms/javascript/guides/koa/data-management/sensitive-data/"
customCanonicalTag: "/platforms/javascript/guides/node/data-management/sensitive-data/"
sidebar_order: 100
keywords:
- pii
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Rollup
description: "Upload your source maps with the Sentry Rollup Plugin."
sidebar_order: 5
customCanonicalTag: "/platforms/javascript/guides/koa/sourcemaps/uploading/rollup/"
customCanonicalTag: "/platforms/javascript/guides/node/sourcemaps/uploading/rollup/"
---

<Alert>
Expand Down
71 changes: 11 additions & 60 deletions docs/platforms/javascript/guides/bun/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ categories:
- server-only
---

<FrameworkSelector runtime="bun">

<Alert title="Using Elysia?">

Elysia has its own Sentry SDK. Follow the [Elysia guide](/platforms/javascript/guides/elysia/) instead.

</Alert>

<PlatformContent includePath="getting-started-prerequisites" />

<StepConnector selector="h2" showNumbers={true}>
Expand Down Expand Up @@ -140,66 +148,7 @@ bun --preload ./instrument.js dist/app.js

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

### Issues

<SplitLayout>
<SplitSection>
<SplitSectionText>

First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add the following code snippet to your main application file, which will call an undefined function, triggering an error that Sentry will capture:

</SplitSectionText>
<SplitSectionCode>

```javascript
setTimeout(() => {
try {
foo();
} catch (e) {
Sentry.captureException(e);
}
}, 99);
```

</SplitSectionCode>
</SplitSection>
</SplitLayout>

<OnboardingOption optionId="performance">
### Tracing

<SplitLayout>
<SplitSection>
<SplitSectionText>

To test your tracing configuration, update the previous code snippet by starting a trace to measure the time it takes for the execution of your code:

</SplitSectionText>
<SplitSectionCode>

```javascript
Sentry.startSpan(
{
op: "test",
name: "My First Test Transaction",
},
() => {
setTimeout(() => {
try {
foo();
} catch (e) {
Sentry.captureException(e);
}
}, 99);
}
);
```

</SplitSectionCode>
</SplitSection>
</SplitLayout>

</OnboardingOption>
<PlatformContent includePath="getting-started-verify-issues-tracing" switchable />

<OnboardingOption optionId="logs">

Expand Down Expand Up @@ -236,3 +185,5 @@ Our next recommended steps for you are:
</Expandable>

</StepConnector>

</FrameworkSelector>
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ To read the DSN from a Worker binding, pass a callback instead of a plain option
app.use(sentry(app, (env) => ({ dsn: env.SENTRY_DSN })));
```

For the full setup, including verification and the other runtimes, see the **[Hono Quick Start Guide](/platforms/javascript/guides/hono/)**.
To set up Sentry for Hono on other runtimes, see [Hono](/platforms/javascript/guides/hono/).
2 changes: 1 addition & 1 deletion docs/platforms/javascript/guides/cloudflare/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This guide covers Cloudflare Workers. If you're deploying a Cloudflare Pages app
If you're using any of the listed frameworks, follow their specific setup instructions:

- **[Astro](/platforms/javascript/guides/cloudflare/frameworks/astro/)**
- **[Hono](/platforms/javascript/guides/hono/)** (with @sentry/hono)
- **[Hono](/platforms/javascript/guides/cloudflare/frameworks/hono/)** (with @sentry/hono)
- **[Hydrogen](/platforms/javascript/guides/cloudflare/frameworks/hydrogen-react-router/)**
- **[Next.js](/platforms/javascript/guides/cloudflare/frameworks/nextjs/)**
- **[Nuxt](/platforms/javascript/guides/cloudflare/frameworks/nuxt/)**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Scrubbing Sensitive Data"
description: "Learn about filtering or scrubbing sensitive data within the Sentry JavaScript SDK, so that data is not sent with the event. You can also configure server-side scrubbing to ensure the data is not stored."
customCanonicalTag: "/platforms/javascript/guides/koa/data-management/sensitive-data/"
customCanonicalTag: "/platforms/javascript/guides/node/data-management/sensitive-data/"
sidebar_order: 100
keywords:
- pii
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Rollup
description: "Upload your source maps with the Sentry Rollup Plugin."
sidebar_order: 5
customCanonicalTag: "/platforms/javascript/guides/koa/sourcemaps/uploading/rollup/"
customCanonicalTag: "/platforms/javascript/guides/node/sourcemaps/uploading/rollup/"
---

<Alert>
Expand Down
Loading
Loading