Skip to content

Commit 2cfee3b

Browse files
authored
feat(ai-insights): langchain & langraph onboarding (#103286)
1 parent 8309e51 commit 2cfee3b

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

static/app/gettingStartedDocs/node/utils.tsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,74 @@ Sentry.init({
509509
},
510510
];
511511

512+
const langchainContent: ContentBlock[] = [
513+
{
514+
type: 'text',
515+
text: tct(
516+
'Add the [code:langChainIntegration] to your [code:Sentry.init()] call. This integration automatically instruments LangChain to capture spans for AI operations.',
517+
{code: <code />}
518+
),
519+
},
520+
{
521+
type: 'code',
522+
tabs: [
523+
{
524+
label: 'JavaScript',
525+
language: 'javascript',
526+
code: `${getImport(packageName).join('\n')}
527+
528+
Sentry.init({
529+
dsn: "${params.dsn.public}",
530+
integrations: [
531+
// Add the LangChain integration
532+
Sentry.langChainIntegration({
533+
recordInputs: true,
534+
recordOutputs: true,
535+
}),
536+
],
537+
// Tracing must be enabled for agent monitoring to work
538+
tracesSampleRate: 1.0,
539+
sendDefaultPii: true,
540+
});`,
541+
},
542+
],
543+
},
544+
];
545+
546+
const langgraphContent: ContentBlock[] = [
547+
{
548+
type: 'text',
549+
text: tct(
550+
'Add the [code:langChainIntegration] to your [code:Sentry.init()] call. This integration automatically instruments LangGraph to capture spans for AI operations.',
551+
{code: <code />}
552+
),
553+
},
554+
{
555+
type: 'code',
556+
tabs: [
557+
{
558+
label: 'JavaScript',
559+
language: 'javascript',
560+
code: `${getImport(packageName).join('\n')}
561+
562+
Sentry.init({
563+
dsn: "${params.dsn.public}",
564+
integrations: [
565+
// Add the LangChain integration (also works for LangGraph)
566+
Sentry.langChainIntegration({
567+
recordInputs: true,
568+
recordOutputs: true,
569+
}),
570+
],
571+
// Tracing must be enabled for agent monitoring to work
572+
tracesSampleRate: 1.0,
573+
sendDefaultPii: true,
574+
});`,
575+
},
576+
],
577+
},
578+
];
579+
512580
const manualContent: ContentBlock[] = [
513581
{
514582
type: 'text',
@@ -563,6 +631,12 @@ await Sentry.startSpan({
563631
if (selected === 'google_genai') {
564632
content = googleGenAIContent;
565633
}
634+
if (selected === 'langchain') {
635+
content = langchainContent;
636+
}
637+
if (selected === 'langgraph') {
638+
content = langgraphContent;
639+
}
566640
return [
567641
{
568642
title: t('Configure'),
@@ -638,6 +712,63 @@ const response = await ai.models.generateContent({
638712
],
639713
});
640714
}
715+
if (selected === 'langchain') {
716+
content.push({
717+
type: 'code',
718+
tabs: [
719+
{
720+
label: 'JavaScript',
721+
language: 'javascript',
722+
code: `
723+
const { ChatOpenAI } = require("@langchain/openai");
724+
const { HumanMessage, SystemMessage } = require("@langchain/core/messages");
725+
726+
const chatModel = new ChatOpenAI({
727+
modelName: "gpt-4o",
728+
apiKey: process.env.OPENAI_API_KEY,
729+
});
730+
731+
const messages = [
732+
new SystemMessage("You are a helpful assistant."),
733+
new HumanMessage("Tell me a joke"),
734+
];
735+
736+
const response = await chatModel.invoke(messages);
737+
const text = response.content;`,
738+
},
739+
],
740+
});
741+
}
742+
if (selected === 'langgraph') {
743+
content.push({
744+
type: 'code',
745+
tabs: [
746+
{
747+
label: 'JavaScript',
748+
language: 'javascript',
749+
code: `
750+
const { ChatOpenAI } = require("@langchain/openai");
751+
const { createReactAgent } = require("@langchain/langgraph/prebuilt");
752+
const { HumanMessage, SystemMessage } = require("@langchain/core/messages");
753+
754+
const llm = new ChatOpenAI({
755+
modelName: "gpt-4o",
756+
apiKey: process.env.OPENAI_API_KEY,
757+
});
758+
759+
const agent = createReactAgent({ llm, tools: [] });
760+
761+
const result = await agent.invoke({
762+
messages: [new SystemMessage("You are a helpful assistant."), new HumanMessage("Tell me a joke")],
763+
});
764+
765+
const messages = result.messages;
766+
const lastMessage = messages[messages.length - 1];
767+
const text = lastMessage.content;`,
768+
},
769+
],
770+
});
771+
}
641772
return [
642773
{
643774
type: StepType.VERIFY,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ export function Onboarding() {
230230
{label: 'OpenAI SDK', value: 'openai'},
231231
{label: 'Anthropic SDK', value: 'anthropic'},
232232
{label: 'Google Gen AI SDK', value: 'google_genai'},
233+
{label: 'LangChain', value: 'langchain'},
234+
{label: 'LangGraph', value: 'langgraph'},
233235
{label: 'Manual', value: 'manual'},
234236
],
235237
},

0 commit comments

Comments
 (0)