diff --git a/dev-packages/node-integration-tests/suites/tracing/anthropic/scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/anthropic/scenario.mjs index d0acf5c42b79..577c63dc3d08 100644 --- a/dev-packages/node-integration-tests/suites/tracing/anthropic/scenario.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/anthropic/scenario.mjs @@ -2,8 +2,6 @@ import Anthropic from '@anthropic-ai/sdk'; import * as Sentry from '@sentry/node'; import express from 'express'; -const PORT = 3333; - function startMockAnthropicServer() { const app = express(); app.use(express.json()); @@ -50,16 +48,21 @@ function startMockAnthropicServer() { }, }); }); - return app.listen(PORT); + + return new Promise(resolve => { + const server = app.listen(0, () => { + resolve(server); + }); + }); } async function run() { - const server = startMockAnthropicServer(); + const server = await startMockAnthropicServer(); await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { const client = new Anthropic({ apiKey: 'mock-api-key', - baseURL: `http://localhost:${PORT}/anthropic`, + baseURL: `http://localhost:${server.address().port}/anthropic`, }); // First test: basic message completion diff --git a/dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs index cfae135b6878..ddb9e16b8254 100644 --- a/dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs @@ -2,8 +2,6 @@ import { GoogleGenAI } from '@google/genai'; import * as Sentry from '@sentry/node'; import express from 'express'; -const PORT = 3333; - function startMockGoogleGenAIServer() { const app = express(); app.use(express.json()); @@ -39,16 +37,20 @@ function startMockGoogleGenAIServer() { }); }); - return app.listen(PORT); + return new Promise(resolve => { + const server = app.listen(0, () => { + resolve(server); + }); + }); } async function run() { - const server = startMockGoogleGenAIServer(); + const server = await startMockGoogleGenAIServer(); await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { const client = new GoogleGenAI({ apiKey: 'mock-api-key', - httpOptions: { baseUrl: `http://localhost:${PORT}` }, + httpOptions: { baseUrl: `http://localhost:${server.address().port}` }, }); // Test 1: chats.create and sendMessage flow diff --git a/dev-packages/node-integration-tests/suites/tracing/openai/scenario-root-span.mjs b/dev-packages/node-integration-tests/suites/tracing/openai/scenario-root-span.mjs index d1a06e5ccbb2..2aaca0700312 100644 --- a/dev-packages/node-integration-tests/suites/tracing/openai/scenario-root-span.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/openai/scenario-root-span.mjs @@ -1,8 +1,6 @@ import express from 'express'; import OpenAI from 'openai'; -const PORT = 3333; - function startMockOpenAiServer() { const app = express(); app.use(express.json()); @@ -31,14 +29,18 @@ function startMockOpenAiServer() { }, }); }); - return app.listen(PORT); + return new Promise(resolve => { + const server = app.listen(0, () => { + resolve(server); + }); + }); } async function run() { - const server = startMockOpenAiServer(); + const server = await startMockOpenAiServer(); const client = new OpenAI({ - baseURL: `http://localhost:${PORT}/openai`, + baseURL: `http://localhost:${server.address().port}/openai`, apiKey: 'mock-api-key', });