@@ -143,6 +143,80 @@ export const config = {
143143
144144This exposes the MCP endpoint at ` /tidewave/mcp ` .
145145
146+ ** Logging** (optional): To capture application logs for debugging via the
147+ ` get_logs ` MCP tool, add OpenTelemetry instrumentation.
148+
149+ Create an ` instrumentation.ts ` file in your project root:
150+
151+ ``` typescript
152+ // instrumentation.ts
153+ import { NodeSDK } from ' @opentelemetry/sdk-node' ;
154+
155+ export async function register() {
156+ const runtime = process .env .NEXT_RUNTIME ;
157+ const env = process .env .NODE_ENV ;
158+
159+ if (runtime === ' nodejs' && env === ' development' ) {
160+ const { TidewaveSpanProcessor, TidewaveLogRecordProcessor } = await import (
161+ ' tidewave/next-js/instrumentation'
162+ );
163+
164+ const sdk = new NodeSDK ({
165+ spanProcessors: [new TidewaveSpanProcessor ()],
166+ logRecordProcessors: [new TidewaveLogRecordProcessor ()], // Optional
167+ });
168+
169+ sdk .start ();
170+ }
171+ }
172+ ```
173+
174+ This captures:
175+
176+ - Console logs (` console.log ` , ` console.error ` , etc.) - automatic when you
177+ import the module
178+ - Next.js HTTP request/response spans (` GET /api/users 200 45ms ` ) - via
179+ ` TidewaveSpanProcessor `
180+ - OpenTelemetry logger logs - via ` TidewaveLogRecordProcessor ` (optional)
181+
182+ #### With Existing OpenTelemetry Setup
183+
184+ If you already have custom OpenTelemetry instrumentation, simply add the
185+ Tidewave processors to your existing setup:
186+
187+ ``` typescript
188+ // instrumentation.ts
189+ import { NodeSDK } from ' @opentelemetry/sdk-node' ;
190+ import { BatchSpanProcessor } from ' @opentelemetry/sdk-trace-node' ;
191+
192+ export async function register() {
193+ const runtime = process .env .NEXT_RUNTIME ;
194+ const env = process .env .NODE_ENV ;
195+
196+ // Your existing configuration
197+ const sdkConfig = {
198+ spanProcessors: [new BatchSpanProcessor (yourExporter )],
199+ logRecordProcessors: [],
200+ };
201+
202+ // Conditionally add Tidewave processors in development
203+ if (runtime === ' nodejs' && env === ' development' ) {
204+ const { TidewaveSpanProcessor, TidewaveLogRecordProcessor } = await import (
205+ ' tidewave/next-js/instrumentation'
206+ );
207+
208+ sdkConfig .spanProcessors .push (new TidewaveSpanProcessor ());
209+ sdkConfig .logRecordProcessors .push (new TidewaveLogRecordProcessor ());
210+ }
211+
212+ const sdk = new NodeSDK (sdkConfig );
213+ sdk .start ();
214+ }
215+ ```
216+
217+ This allows Tidewave to capture logs alongside your existing OpenTelemetry setup
218+ without conflicts.
219+
146220### CLI Usage
147221
148222Tidewave also provides the MCP features over a CLI tool. Use it directly via
0 commit comments