Next.jsアプリケーションに分散トレーシングを数分で追加。Vercelの組み込みinstrumentationフックでサーバーコンポーネント、APIルート、ミドルウェアのスパンを自動キャプチャ。
npm install @vercel/otel @opentelemetry/sdk-logs @opentelemetry/exporter-logs-otlp-http // 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 }),
}),
],
});
} 得られるもの
Automatic spans for every page and route handler request with method, status, and duration.
Spans for API route handlers, with request and response metadata.
Spans for React Server Component rendering and data fetching.
Traces for Next.js middleware execution including redirects and rewrites.
Log records exported over OTLP carry the trace and span id of the request that wrote them.
Outgoing fetch requests traced with context propagation. Add database client instrumentations through the instrumentations option.
SDKを追加し、OTLPエクスポーターをMapleに向ければトレースが届きます。
maple.dev:OpenTelemetryの上のオブザーバビリティ