Next.js OpenTelemetry 옵저버빌리티

Next.js 애플리케이션에 분산 트레이싱을 분 만에 추가. Vercel의 내장 instrumentation 훅으로 서버 컴포넌트, API 라우트, 미들웨어 스팬을 자동 캡처.

POST /checkout 8 spans · 203ms
DurationStatus
/checkoutapi-gateway
203ms200
validateTokenauth-service
24.0msOk
createOrderorder-service
111msOk
validateInventory
20.0msOk
reserveItems
16.0msOk
processPaymentpayment-svc
57.0msOk
chargeCard
45.0msOk
sendConfirmationorder-service
30.0msOk
Quick start

Up and running in minutes

1

Install dependencies

bash
npm install @vercel/otel @opentelemetry/sdk-logs @opentelemetry/exporter-logs-otlp-http
2

Configure instrumentation

typescript
// instrumentation.ts (project root)
import { registerOTel } from "@vercel/otel";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
import { SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";

const MAPLE_ENDPOINT = "https://ingest.maple.dev";
const headers = { authorization: "Bearer your-api-key" };

export function register() {
  registerOTel({
    serviceName: "my-next-app",
    attributes: { "deployment.environment.name": "production" },
    traceExporter: { url: `${MAPLE_ENDPOINT}/v1/traces`, headers },
    logRecordProcessors: [
      new SimpleLogRecordProcessor({
        exporter: new OTLPLogExporter({ url: `${MAPLE_ENDPOINT}/v1/logs`, headers }),
      }),
    ],
  });
}

얻을 수 있는 것

Next.js의 자동 계측

HTTP routes

Automatic spans for every page and route handler request with method, status, and duration.

API routes

Spans for API route handlers, with request and response metadata.

Server Components

Spans for React Server Component rendering and data fetching.

Middleware

Traces for Next.js middleware execution including redirects and rewrites.

Log correlation

Log records exported over OTLP carry the trace and span id of the request that wrote them.

External API calls

Outgoing fetch requests traced with context propagation. Add database client instrumentations through the instrumentations option.

통합

Other integrations

오늘 첫 트레이스를 확인하세요.

SDK를 추가하고 OTLP 익스포터를 Maple로 향하게 하면 트레이스가 도착합니다.

maple.dev: OpenTelemetry 위의 옵저버빌리티