Skip to content
Open
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
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ module.exports = [
import: createImport('init'),
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '156 KB',
limit: '157 KB',
},
{
name: '@sentry/node - without tracing',
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"@anthropic-ai/sdk": "0.63.0",
"@aws-sdk/client-s3": "^3.552.0",
"@google/genai": "^1.20.0",
"@langchain/anthropic": "^0.3.10",
"@langchain/core": "^0.3.28",
"@growthbook/growthbook": "^1.6.1",
"@hapi/hapi": "^21.3.10",
"@hono/node-server": "^1.19.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
sendDefaultPii: true,
transport: loggingTransport,
// Filter out Anthropic integration to avoid duplicate spans with LangChain
integrations: integrations => integrations.filter(integration => integration.name !== 'Anthropic_AI'),
beforeSendTransaction: event => {
// Filter out mock express server transactions
if (event.transaction.includes('/v1/messages')) {
return null;
}
return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
sendDefaultPii: false,
transport: loggingTransport,
// Filter out Anthropic integration to avoid duplicate spans with LangChain
integrations: integrations => integrations.filter(integration => integration.name !== 'Anthropic_AI'),
beforeSendTransaction: event => {
// Filter out mock express server transactions
if (event.transaction.includes('/v1/messages')) {
return null;
}
return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { ChatAnthropic } from '@langchain/anthropic';
import * as Sentry from '@sentry/node';
import express from 'express';

function startMockAnthropicServer() {
const app = express();
app.use(express.json());

app.post('/v1/messages', (req, res) => {
const model = req.body.model;

// Simulate tool call response
res.json({
id: 'msg_tool_test_123',
type: 'message',
role: 'assistant',
model: model,
content: [
{
type: 'text',
text: 'Let me check the weather for you.',
},
{
type: 'tool_use',
id: 'toolu_01A09q90qw90lq917835lq9',
name: 'get_weather',
input: { location: 'San Francisco, CA' },
},
{
type: 'text',
text: 'The weather looks great!',
},
],
stop_reason: 'tool_use',
stop_sequence: null,
usage: {
input_tokens: 20,
output_tokens: 30,
},
});
});

return new Promise(resolve => {
const server = app.listen(0, () => {
resolve(server);
});
});
}

async function run() {
const server = await startMockAnthropicServer();
const baseUrl = `http://localhost:${server.address().port}`;

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
const model = new ChatAnthropic({
model: 'claude-3-5-sonnet-20241022',
temperature: 0.7,
maxTokens: 150,
apiKey: 'mock-api-key',
clientOptions: {
baseURL: baseUrl,
},
});

await model.invoke('What is the weather in San Francisco?', {
tools: [
{
name: 'get_weather',
description: 'Get the current weather in a given location',
input_schema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
],
});
});

await Sentry.flush(2000);

server.close();
}

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ChatAnthropic } from '@langchain/anthropic';
import * as Sentry from '@sentry/node';
import express from 'express';

function startMockAnthropicServer() {
const app = express();
app.use(express.json());

app.post('/v1/messages', (req, res) => {
const model = req.body.model;

if (model === 'error-model') {
res
.status(400)
.set('request-id', 'mock-request-123')
.json({
type: 'error',
error: {
type: 'invalid_request_error',
message: 'Model not found',
},
});
return;
}

// Simulate basic response
res.json({
id: 'msg_test123',
type: 'message',
role: 'assistant',
content: [
{
type: 'text',
text: 'Mock response from Anthropic!',
},
],
model: model,
stop_reason: 'end_turn',
stop_sequence: null,
usage: {
input_tokens: 10,
output_tokens: 15,
},
});
});

return new Promise(resolve => {
const server = app.listen(0, () => {
resolve(server);
});
});
}

async function run() {
const server = await startMockAnthropicServer();
const baseUrl = `http://localhost:${server.address().port}`;

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
// Test 1: Basic chat model invocation
const model1 = new ChatAnthropic({
model: 'claude-3-5-sonnet-20241022',
temperature: 0.7,
maxTokens: 100,
apiKey: 'mock-api-key',
clientOptions: {
baseURL: baseUrl,
},
});

await model1.invoke('Tell me a joke');

// Test 2: Chat with different model
const model2 = new ChatAnthropic({
model: 'claude-3-opus-20240229',
temperature: 0.9,
topP: 0.95,
maxTokens: 200,
apiKey: 'mock-api-key',
clientOptions: {
baseURL: baseUrl,
},
});

await model2.invoke([
{ role: 'system', content: 'You are a helpful assistant' },
{ role: 'user', content: 'What is the capital of France?' },
]);

// Test 3: Error handling
const errorModel = new ChatAnthropic({
model: 'error-model',
apiKey: 'mock-api-key',
clientOptions: {
baseURL: baseUrl,
},
});

try {
await errorModel.invoke('This will fail');
} catch (error) {
// Expected error
}
});

await Sentry.flush(2000);

server.close();
}

run();
Loading
Loading