Skip to content

Commit d85a9f2

Browse files
authored
feat(onboarding): Add Hono SDK (Deno) (#117416)
Continuation of #115476 Merge after this is released: getsentry/sentry-javascript#21450
1 parent 8574547 commit d85a9f2

4 files changed

Lines changed: 179 additions & 0 deletions

File tree

static/app/gettingStartedDocs/node-hono/feedback.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export const feedback: OnboardingConfig = {
5050
language: 'javascript',
5151
code: getFeedbackSnippet('@sentry/hono/bun'),
5252
},
53+
{
54+
label: 'Deno',
55+
value: 'deno',
56+
language: 'javascript',
57+
code: getFeedbackSnippet('@sentry/hono/deno'),
58+
},
5359
],
5460
},
5561
],

static/app/gettingStartedDocs/node-hono/onboarding.spec.tsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,83 @@ describe('hono onboarding docs', () => {
301301
});
302302
});
303303

304+
describe('Deno runtime', () => {
305+
let denoDocs: typeof docs;
306+
beforeAll(() => {
307+
denoDocs = {
308+
...docs,
309+
platformOptions: {
310+
...docs.platformOptions,
311+
runtime: {
312+
...docs.platformOptions!.runtime,
313+
defaultValue: Runtime.DENO,
314+
},
315+
},
316+
};
317+
});
318+
319+
it('renders onboarding docs correctly', () => {
320+
renderWithOnboardingLayout(denoDocs);
321+
322+
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
323+
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
324+
expect(
325+
screen.getByRole('heading', {name: /Upload Source Maps/i})
326+
).toBeInTheDocument();
327+
expect(screen.getByRole('heading', {name: 'Verify'})).toBeInTheDocument();
328+
329+
expect(
330+
screen.getAllByText(textWithMarkupMatcher(/@sentry\/deno/)).length
331+
).toBeGreaterThanOrEqual(1);
332+
expect(
333+
screen.getByText(
334+
textWithMarkupMatcher(/import { sentry } from "@sentry\/hono\/deno"/)
335+
)
336+
).toBeInTheDocument();
337+
expect(
338+
screen.getByText(textWithMarkupMatcher(/Deno\.serve\(app\.fetch\)/))
339+
).toBeInTheDocument();
340+
expect(
341+
screen.getByText(textWithMarkupMatcher(/sentry\(app, \{/))
342+
).toBeInTheDocument();
343+
});
344+
345+
it('displays tracesSampleRate when performance is selected', () => {
346+
renderWithOnboardingLayout(denoDocs, {
347+
selectedProducts: [
348+
ProductSolution.ERROR_MONITORING,
349+
ProductSolution.PERFORMANCE_MONITORING,
350+
],
351+
});
352+
353+
expect(
354+
screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
355+
).toBeInTheDocument();
356+
});
357+
358+
it('enables logs by setting enableLogs to true', () => {
359+
renderWithOnboardingLayout(denoDocs, {
360+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.LOGS],
361+
});
362+
363+
expect(
364+
screen.getByText(textWithMarkupMatcher(/enableLogs: true/))
365+
).toBeInTheDocument();
366+
});
367+
368+
it('shows profiling info alert when profiling is selected', () => {
369+
renderWithOnboardingLayout(denoDocs, {
370+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.PROFILING],
371+
});
372+
373+
expect(
374+
screen.getByText(
375+
textWithMarkupMatcher(/Profiling is only available on the Node.js runtime/)
376+
)
377+
).toBeInTheDocument();
378+
});
379+
});
380+
304381
describe('shared behavior', () => {
305382
it('displays logs integration next step when logs are selected', () => {
306383
renderWithOnboardingLayout(docs, {

static/app/gettingStartedDocs/node-hono/onboarding.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const RUNTIME_CONFIG: Record<
2828
peerDep: '@sentry/bun',
2929
label: 'the Bun runtime',
3030
},
31+
[Runtime.DENO]: {
32+
importPath: '@sentry/hono/deno',
33+
peerDep: '@sentry/deno',
34+
label: 'the Deno runtime',
35+
},
3136
};
3237

3338
function getNodeInstrumentSnippet(params: Params): string {
@@ -129,6 +134,60 @@ app.get("/", (c) => {
129134
export default app;`;
130135
}
131136

137+
function getDenoAppSnippet(params: Params): string {
138+
return `import { Hono } from "hono";
139+
import { sentry } from "${RUNTIME_CONFIG[Runtime.DENO].importPath}";
140+
141+
const app = new Hono();
142+
143+
app.use(
144+
sentry(app, {
145+
dsn: "${params.dsn.public}",${
146+
params.isPerformanceSelected
147+
? `
148+
tracesSampleRate: 1.0,`
149+
: ''
150+
}${
151+
params.isLogsSelected
152+
? `
153+
enableLogs: true,`
154+
: ''
155+
}
156+
// To disable sending user data and HTTP bodies, uncomment the line below. For more info visit:
157+
// https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#dataCollection
158+
// dataCollection: { userInfo: false, httpBodies: [] },
159+
}),
160+
);
161+
162+
// Your routes here
163+
164+
Deno.serve(app.fetch);`;
165+
}
166+
167+
function getDenoInstallStep() {
168+
return {
169+
type: StepType.INSTALL as const,
170+
content: [
171+
{
172+
type: 'text' as const,
173+
text: tct(
174+
'Install the [sentryHono] package and the [peerDep] peer dependency for [label]:',
175+
{
176+
sentryHono: <code>@sentry/hono</code>,
177+
peerDep: <code>{RUNTIME_CONFIG[Runtime.DENO].peerDep}</code>,
178+
label: RUNTIME_CONFIG[Runtime.DENO].label,
179+
}
180+
),
181+
},
182+
{
183+
type: 'code' as const,
184+
language: 'bash',
185+
code: `deno add npm:@sentry/hono npm:${RUNTIME_CONFIG[Runtime.DENO].peerDep}`,
186+
},
187+
],
188+
};
189+
}
190+
132191
function getWranglerSnippet(): string {
133192
return `{
134193
"compatibility_flags": ["nodejs_compat"]
@@ -383,6 +442,38 @@ const runtimeOnboarding: Record<Runtime, OnboardingConfig<PlatformOptions>> = {
383442
],
384443
verify: (params: Params) => [getVerifyStep(params)],
385444
},
445+
[Runtime.DENO]: {
446+
install: () => [getDenoInstallStep()],
447+
configure: (params: Params) => [
448+
{
449+
type: StepType.CONFIGURE,
450+
content: [
451+
getProfilingAlert(params),
452+
{
453+
type: 'text',
454+
text: tct(
455+
'Add the [code:sentry()] middleware as early as possible in your Hono app. On Deno, you pass your Sentry options directly to the middleware:',
456+
{code: <code />}
457+
),
458+
},
459+
{
460+
type: 'code',
461+
tabs: [
462+
{
463+
label: 'TypeScript',
464+
language: 'typescript',
465+
filename: 'index.ts',
466+
value: 'typescript',
467+
code: getDenoAppSnippet(params),
468+
},
469+
],
470+
},
471+
],
472+
},
473+
getSourceMapsStep(params),
474+
],
475+
verify: (params: Params) => [getVerifyStep(params)],
476+
},
386477
};
387478

388479
export const onboarding: OnboardingConfig<PlatformOptions> = {

static/app/gettingStartedDocs/node-hono/utils.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export enum Runtime {
88
NODE = 'node',
99
CLOUDFLARE = 'cloudflare',
1010
BUN = 'bun',
11+
DENO = 'deno',
1112
}
1213

1314
export const platformOptions = {
@@ -26,6 +27,10 @@ export const platformOptions = {
2627
label: t('Bun'),
2728
value: Runtime.BUN,
2829
},
30+
{
31+
label: t('Deno'),
32+
value: Runtime.DENO,
33+
},
2934
],
3035
defaultValue: Runtime.CLOUDFLARE,
3136
},

0 commit comments

Comments
 (0)