Skip to content

Commit 535e8dc

Browse files
committed
debug
1 parent 62397c5 commit 535e8dc

File tree

12 files changed

+165
-6
lines changed

12 files changed

+165
-6
lines changed

dev-packages/browser-integration-tests/suites/tracing/ai-providers/anthropic/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
tracesSampleRate: 1,
8+
debug: true,
89
});

dev-packages/browser-integration-tests/suites/tracing/ai-providers/anthropic/mocks.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Mock Anthropic client for browser testing
22
export class MockAnthropic {
33
constructor(config) {
4+
// eslint-disable-next-line no-console
5+
console.log('[Mock Anthropic] Constructor called with config:', config);
46
this.apiKey = config.apiKey;
57

68
// Main focus: messages.create functionality
79
this.messages = {
810
create: async (...args) => {
11+
// eslint-disable-next-line no-console
12+
console.log('[Mock Anthropic] messages.create called with args:', args);
913
const params = args[0];
1014
// Simulate processing time
1115
await new Promise(resolve => setTimeout(resolve, 10));
@@ -17,7 +21,7 @@ export class MockAnthropic {
1721
throw error;
1822
}
1923

20-
return {
24+
const response = {
2125
id: 'msg_mock123',
2226
type: 'message',
2327
role: 'assistant',
@@ -37,6 +41,9 @@ export class MockAnthropic {
3741
cache_read_input_tokens: 0,
3842
},
3943
};
44+
// eslint-disable-next-line no-console
45+
console.log('[Mock Anthropic] Returning response:', response);
46+
return response;
4047
},
4148
countTokens: async (..._args) => ({ id: 'mock', type: 'model', model: 'mock', input_tokens: 0 }),
4249
};
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import * as Sentry from '@sentry/browser';
22
import { MockAnthropic } from './mocks.js';
33

4+
// eslint-disable-next-line no-console
5+
console.log('[Anthropic Test] Starting test...');
6+
7+
// eslint-disable-next-line no-console
8+
console.log('[Anthropic Test] Creating mock client...');
49
const mockClient = new MockAnthropic({
510
apiKey: 'mock-api-key',
611
});
712

13+
// eslint-disable-next-line no-console
14+
console.log('[Anthropic Test] Mock client created:', mockClient);
15+
16+
// eslint-disable-next-line no-console
17+
console.log('[Anthropic Test] Instrumenting client with Sentry...');
818
const client = Sentry.instrumentAnthropicAiClient(mockClient);
919

20+
// eslint-disable-next-line no-console
21+
console.log('[Anthropic Test] Client instrumented:', client);
22+
1023
// Test that manual instrumentation doesn't crash the browser
1124
// The instrumentation automatically creates spans
25+
// eslint-disable-next-line no-console
26+
console.log('[Anthropic Test] Calling messages.create...');
1227
const response = await client.messages.create({
1328
model: 'claude-3-haiku-20240307',
1429
messages: [{ role: 'user', content: 'What is the capital of France?' }],
@@ -17,7 +32,12 @@ const response = await client.messages.create({
1732
});
1833

1934
// eslint-disable-next-line no-console
20-
console.log(JSON.stringify(response));
35+
console.log('[Anthropic Test] Response received:', JSON.stringify(response));
2136

37+
// eslint-disable-next-line no-console
38+
console.log('[Anthropic Test] Flushing Sentry...');
2239
// Ensure transaction is flushed in CI
2340
await Sentry.flush(2000);
41+
42+
// eslint-disable-next-line no-console
43+
console.log('[Anthropic Test] Test completed!');

dev-packages/browser-integration-tests/suites/tracing/ai-providers/anthropic/test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,38 @@ import { envelopeRequestParser, waitForTransactionRequest } from '../../../../ut
88
// and that gen_ai transactions are sent.
99

1010
sentryTest('manual Anthropic instrumentation sends gen_ai transactions', async ({ getLocalTestUrl, page }) => {
11+
// Listen for console logs
12+
page.on('console', msg => {
13+
// eslint-disable-next-line no-console
14+
console.log(`[Browser Console ${msg.type()}]`, msg.text());
15+
});
16+
17+
// Listen for page errors
18+
page.on('pageerror', error => {
19+
// eslint-disable-next-line no-console
20+
console.error('[Browser Error]', error);
21+
});
22+
1123
const transactionPromise = waitForTransactionRequest(page, event => {
24+
// eslint-disable-next-line no-console
25+
console.log('[Test] Received transaction event:', JSON.stringify(event, null, 2));
1226
return !!event.transaction?.includes('claude-3-haiku-20240307');
1327
});
1428

1529
const url = await getLocalTestUrl({ testDir: __dirname });
30+
// eslint-disable-next-line no-console
31+
console.log('[Test] Navigating to URL:', url);
1632
await page.goto(url);
1733

34+
// eslint-disable-next-line no-console
35+
console.log('[Test] Waiting for transaction...');
1836
const req = await transactionPromise;
37+
// eslint-disable-next-line no-console
38+
console.log('[Test] Transaction received!');
39+
1940
const eventData = envelopeRequestParser(req);
41+
// eslint-disable-next-line no-console
42+
console.log('[Test] Parsed event data:', JSON.stringify(eventData, null, 2));
2043

2144
// Verify it's a gen_ai transaction
2245
expect(eventData.transaction).toBe('messages claude-3-haiku-20240307');

dev-packages/browser-integration-tests/suites/tracing/ai-providers/google-genai/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
tracesSampleRate: 1,
8+
debug: true,
89
});

dev-packages/browser-integration-tests/suites/tracing/ai-providers/google-genai/mocks.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Mock Google GenAI client for browser testing
22
export class MockGoogleGenAI {
33
constructor(config) {
4+
// eslint-disable-next-line no-console
5+
console.log('[Mock Google GenAI] Constructor called with config:', config);
46
this.apiKey = config.apiKey;
57

68
// models.generateContent functionality
79
this.models = {
810
generateContent: async (...args) => {
11+
// eslint-disable-next-line no-console
12+
console.log('[Mock Google GenAI] models.generateContent called with args:', args);
913
const params = args[0];
1014
// Simulate processing time
1115
await new Promise(resolve => setTimeout(resolve, 10));
@@ -61,16 +65,20 @@ export class MockGoogleGenAI {
6165
// chats.create implementation
6266
this.chats = {
6367
create: (...args) => {
68+
// eslint-disable-next-line no-console
69+
console.log('[Mock Google GenAI] chats.create called with args:', args);
6470
const params = args[0];
6571
const model = params.model;
6672

6773
return {
6874
modelVersion: model,
6975
sendMessage: async (..._messageArgs) => {
76+
// eslint-disable-next-line no-console
77+
console.log('[Mock Google GenAI] chat.sendMessage called with args:', _messageArgs);
7078
// Simulate processing time
7179
await new Promise(resolve => setTimeout(resolve, 10));
7280

73-
return {
81+
const response = {
7482
candidates: [
7583
{
7684
content: {
@@ -92,6 +100,9 @@ export class MockGoogleGenAI {
92100
},
93101
modelVersion: model, // Include model version in response
94102
};
103+
// eslint-disable-next-line no-console
104+
console.log('[Mock Google GenAI] Returning response:', response);
105+
return response;
95106
},
96107
sendMessageStream: async () => {
97108
// Return a promise that resolves to an async generator

dev-packages/browser-integration-tests/suites/tracing/ai-providers/google-genai/subject.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import * as Sentry from '@sentry/browser';
22
import { MockGoogleGenAI } from './mocks.js';
33

4+
// eslint-disable-next-line no-console
5+
console.log('[Google GenAI Test] Starting test...');
6+
7+
// eslint-disable-next-line no-console
8+
console.log('[Google GenAI Test] Creating mock client...');
49
const mockClient = new MockGoogleGenAI({
510
apiKey: 'mock-api-key',
611
});
712

13+
// eslint-disable-next-line no-console
14+
console.log('[Google GenAI Test] Mock client created:', mockClient);
15+
16+
// eslint-disable-next-line no-console
17+
console.log('[Google GenAI Test] Instrumenting client with Sentry...');
818
const client = Sentry.instrumentGoogleGenAIClient(mockClient);
919

20+
// eslint-disable-next-line no-console
21+
console.log('[Google GenAI Test] Client instrumented:', client);
22+
1023
// Test that manual instrumentation doesn't crash the browser
1124
// The instrumentation automatically creates spans
1225
// Test both chats and models APIs
26+
// eslint-disable-next-line no-console
27+
console.log('[Google GenAI Test] Creating chat...');
1328
const chat = client.chats.create({
1429
model: 'gemini-1.5-pro',
1530
config: {
@@ -25,12 +40,19 @@ const chat = client.chats.create({
2540
],
2641
});
2742

43+
// eslint-disable-next-line no-console
44+
console.log('[Google GenAI Test] Sending message...');
2845
const response = await chat.sendMessage({
2946
message: 'Tell me a joke',
3047
});
3148

3249
// eslint-disable-next-line no-console
33-
console.log(JSON.stringify(response));
50+
console.log('[Google GenAI Test] Response received:', JSON.stringify(response));
3451

52+
// eslint-disable-next-line no-console
53+
console.log('[Google GenAI Test] Flushing Sentry...');
3554
// Ensure transaction is flushed in CI
3655
await Sentry.flush(2000);
56+
57+
// eslint-disable-next-line no-console
58+
console.log('[Google GenAI Test] Test completed!');

dev-packages/browser-integration-tests/suites/tracing/ai-providers/google-genai/test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,38 @@ import { envelopeRequestParser, waitForTransactionRequest } from '../../../../ut
88
// and that gen_ai transactions are sent.
99

1010
sentryTest('manual Google GenAI instrumentation sends gen_ai transactions', async ({ getLocalTestUrl, page }) => {
11+
// Listen for console logs
12+
page.on('console', msg => {
13+
// eslint-disable-next-line no-console
14+
console.log(`[Browser Console ${msg.type()}]`, msg.text());
15+
});
16+
17+
// Listen for page errors
18+
page.on('pageerror', error => {
19+
// eslint-disable-next-line no-console
20+
console.error('[Browser Error]', error);
21+
});
22+
1123
const transactionPromise = waitForTransactionRequest(page, event => {
24+
// eslint-disable-next-line no-console
25+
console.log('[Test] Received transaction event:', JSON.stringify(event, null, 2));
1226
return !!event.transaction?.includes('gemini-1.5-pro');
1327
});
1428

1529
const url = await getLocalTestUrl({ testDir: __dirname });
30+
// eslint-disable-next-line no-console
31+
console.log('[Test] Navigating to URL:', url);
1632
await page.goto(url);
1733

34+
// eslint-disable-next-line no-console
35+
console.log('[Test] Waiting for transaction...');
1836
const req = await transactionPromise;
37+
// eslint-disable-next-line no-console
38+
console.log('[Test] Transaction received!');
39+
1940
const eventData = envelopeRequestParser(req);
41+
// eslint-disable-next-line no-console
42+
console.log('[Test] Parsed event data:', JSON.stringify(eventData, null, 2));
2043

2144
// Verify it's a gen_ai transaction
2245
expect(eventData.transaction).toBe('chat gemini-1.5-pro create');

dev-packages/browser-integration-tests/suites/tracing/ai-providers/openai/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
tracesSampleRate: 1,
8+
debug: true,
89
});

dev-packages/browser-integration-tests/suites/tracing/ai-providers/openai/mocks.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Mock OpenAI client for browser testing
22
export class MockOpenAi {
33
constructor(config) {
4+
// eslint-disable-next-line no-console
5+
console.log('[Mock OpenAI] Constructor called with config:', config);
46
this.apiKey = config.apiKey;
57

68
this.chat = {
79
completions: {
810
create: async (...args) => {
11+
// eslint-disable-next-line no-console
12+
console.log('[Mock OpenAI] chat.completions.create called with args:', args);
913
const params = args[0];
1014
// Simulate processing time
1115
await new Promise(resolve => setTimeout(resolve, 10));
@@ -17,7 +21,7 @@ export class MockOpenAi {
1721
throw error;
1822
}
1923

20-
return {
24+
const response = {
2125
id: 'chatcmpl-mock123',
2226
object: 'chat.completion',
2327
created: 1677652288,
@@ -39,6 +43,9 @@ export class MockOpenAi {
3943
total_tokens: 25,
4044
},
4145
};
46+
// eslint-disable-next-line no-console
47+
console.log('[Mock OpenAI] Returning response:', response);
48+
return response;
4249
},
4350
},
4451
};

0 commit comments

Comments
 (0)