Skip to content

Commit 7d3cedf

Browse files
ArthurKnausandrewshie-sentry
authored andcommitted
feat(ai-insights-onboarding): Add anthropic ai snippets (#99007)
Add onboarding snippets for the anthropic ai SDK integration. Fix inconsistent imports in snippets (cjs vs esm). Fix 404 in manual instrumentation link. Fix & improve manual instrumentation snippet content.
1 parent 0ab6884 commit 7d3cedf

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

static/app/utils/gettingStartedDocs/node.tsx

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ContentBlock,
66
DocsParams,
77
OnboardingConfig,
8+
OnboardingStep,
89
} from 'sentry/components/onboarding/gettingStartedDoc/types';
910
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/types';
1011
import {t, tct} from 'sentry/locale';
@@ -436,8 +437,8 @@ Sentry.init({
436437
label: 'JavaScript',
437438
value: 'javascript',
438439
language: 'javascript',
439-
code: `import { generateText } from 'ai';
440-
import { openai } from '@ai-sdk/openai';
440+
code: `const { generateText } = require('ai');
441+
const { openai } = require('@ai-sdk/openai');
441442
442443
const result = await generateText({
443444
model: openai("gpt-4o"),
@@ -454,6 +455,60 @@ const result = await generateText({
454455
],
455456
};
456457

458+
const anthropicStep: OnboardingStep = {
459+
title: t('Configure'),
460+
content: [
461+
{
462+
type: 'text',
463+
text: tct(
464+
'Add the [code:anthropicAIIntegration] to your [code:Sentry.init()] call. This integration automatically instruments the Anthropic SDK to capture spans for AI operations.',
465+
{code: <code />}
466+
),
467+
},
468+
{
469+
type: 'code',
470+
tabs: [
471+
{
472+
label: 'JavaScript',
473+
language: 'javascript',
474+
code: `${getImport(basePackage === '@sentry/node' ? 'node' : (basePackage as any)).join('\n')}
475+
476+
Sentry.init({
477+
dsn: "${params.dsn.public}",
478+
integrations: [
479+
// Add the AnthropicAI integration
480+
Sentry.anthropicAIIntegration({
481+
recordInputs: true,
482+
recordOutputs: true,
483+
}),
484+
],
485+
// Tracing must be enabled for agent monitoring to work
486+
tracesSampleRate: 1.0,
487+
sendDefaultPii: true,
488+
});`,
489+
},
490+
],
491+
},
492+
{
493+
type: 'code',
494+
tabs: [
495+
{
496+
label: 'JavaScript',
497+
language: 'javascript',
498+
code: `
499+
const Anthropic = require("anthropic");
500+
const anthropic = new Anthropic();
501+
502+
const msg = await anthropic.messages.create({
503+
model: "claude-3-5-sonnet",
504+
messages: [{role: "user", content: "Tell me a joke"}],
505+
});`,
506+
},
507+
],
508+
},
509+
],
510+
};
511+
457512
const openaiStep = {
458513
title: t('Configure'),
459514
description: tct(
@@ -494,7 +549,7 @@ Sentry.init({
494549
value: 'javascript',
495550
language: 'javascript',
496551
code: `
497-
import OpenAI from "openai";
552+
const OpenAI = require("openai");
498553
const client = new OpenAI();
499554
500555
const response = await client.responses.create({
@@ -513,7 +568,7 @@ const response = await client.responses.create({
513568
'If you are not using a supported SDK integration, you can instrument your AI calls manually. See [link:manual instrumentation docs] for details.',
514569
{
515570
link: (
516-
<ExternalLink href="https://docs.sentry.io/platforms/javascript/tracing/instrumentation/ai-agents-module/#manual-instrumentation" />
571+
<ExternalLink href="https://docs.sentry.io/platforms/node/tracing/instrumentation/ai-agents-module/#manual-instrumentation" />
517572
),
518573
}
519574
),
@@ -525,18 +580,22 @@ const response = await client.responses.create({
525580
label: 'JavaScript',
526581
value: 'javascript',
527582
language: 'javascript',
528-
code: `import * as Sentry from "@sentry/${
529-
basePackage === 'nextjs' ? 'nextjs' : basePackage
530-
}";
583+
code: `${getImport(basePackage === '@sentry/node' ? 'node' : (basePackage as any)).join('\n')}
531584
532585
// Create a span around your AI call
533586
await Sentry.startSpan({
534-
op: "gen_ai.request",
535-
name: "Generate Text",
587+
op: "gen_ai.chat",
588+
name: "chat gpt-4o",
589+
attributes: {
590+
"gen_ai.operation.name": "chat",
591+
"gen_ai.request.model": "gpt-4o",
592+
}
536593
}, async (span) => {
537594
// Call your AI function here
538595
// e.g., await generateText(...)
539-
span.setAttribute("ai.model", "gpt-4o");
596+
597+
// Set further span attributes after the AI call
598+
span.setAttribute("gen_ai.response.text", "<Your model's response>");
540599
});`,
541600
},
542601
],
@@ -545,6 +604,9 @@ await Sentry.startSpan({
545604
};
546605

547606
const selected = (params.platformOptions as any)?.integration ?? 'vercelai';
607+
if (selected === 'anthropic') {
608+
return [anthropicStep];
609+
}
548610
if (selected === 'openai') {
549611
return [openaiStep];
550612
}

static/app/views/insights/agents/views/onboarding.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export function Onboarding() {
263263
: [
264264
{label: 'Vercel AI SDK', value: 'vercelai'},
265265
{label: 'OpenAI SDK', value: 'openai'},
266+
{label: 'Anthropic SDK', value: 'anthropic'},
266267
{label: 'Manual', value: 'manual'},
267268
],
268269
},

0 commit comments

Comments
 (0)