0.0.1 • Published 8 months ago
@ogcio/nextjs-o11y v0.0.1
NextJS Observability
This javascript plugin enhances observability by:
- Attaching the
x-trace-idheader to responses using OpenTelemetry tracing.
Installation
Ensure you have @opentelemetry/api installed in your project with version >= 1.x
npm install fastify @ogcio/nextjs-o11yUsage
Ensure you have the instrumentation.ts file in your application with node and edge instrumentation ready.
import { registerOTel } from "@vercel/otel";
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
import("@ogcio/o11y-sdk-node").then(async (sdk) => {
sdk.instrumentNode({
serviceName: "service-name",
collectorUrl: "http:your-otel-collector-url",
});
});
} else {
registerOTel();
}
}Import and register the plugin in NextJS your middleware.ts:
import o11y from "@ogcio/nextjs-o11y";
export default async function (request: NextRequest) {
const response = NextResponse.next({
request,
});
o11y(request, response);
return response;
}Features
1. Trace ID Propagation
This plugin adds the x-trace-id header to responses, extracted from the active OpenTelemetry span.
0.0.1
8 months ago