Observability

Logs

Send OpenTelemetry logs to OpsCompanion over OTLP/HTTP JSON.

Get Your API Key

In the OpsCompanion app, click your profile picture in the top right of the navbar, click Manage Account, then open the API Keys tab at the top.

Choose A Method

To create instrumentation.ts and wire it up in your app, follow the official Next.js instrumentation guide.

Use a server-only instrumentation.ts file to register a logger provider and export logs to OpsCompanion.

.env.local

OPSCOMPANION_API_KEY=your_api_key_here

src/instrumentation.ts

import { logs } from "@opentelemetry/api-logs"
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http"
import {
  BatchLogRecordProcessor,
  LoggerProvider,
} from "@opentelemetry/sdk-logs"
import { resourceFromAttributes } from "@opentelemetry/resources"

const loggerProvider = new LoggerProvider({
  resource: resourceFromAttributes({
    "service.name": "my-nextjs-app",
    "deployment.environment": process.env.VERCEL_ENV ?? "local",
  }),
  processors: [
    new BatchLogRecordProcessor(
      new OTLPLogExporter({
        url: "https://otel.opscompanion.ai/v1/logs",
        headers: {
          Authorization: `Bearer ${process.env.OPSCOMPANION_API_KEY}`,
          "Content-Type": "application/json",
        },
      }),
    ),
  ],
})

export function register() {
  if (process.env.NEXT_RUNTIME !== "nodejs") return
  logs.setGlobalLoggerProvider(loggerProvider)
}

Emit a log from server-side code:

import { logs, SeverityNumber } from "@opentelemetry/api-logs"

const logger = logs.getLogger("my-nextjs-app")

logger.emit({
  eventName: "checkout.completed",
  severityNumber: SeverityNumber.INFO,
  body: {
    orderId: "ord_123",
    amount: 4200,
  },
  attributes: {
    workspace: "production",
    route: "/api/checkout",
  },
})

Supabase Log Drains

If you're using Supabase, you can forward your project logs (Postgres, Auth, Storage, Realtime, and Edge Functions) directly to OpsCompanion using Supabase's built-in log drain feature.

Follow the Supabase Log Drains guide to set it up. Use the OpsCompanion OTLP endpoint as the destination:

  • Endpoint: https://otel.opscompanion.ai/v1/logs
  • Authorization: Bearer <your OpsCompanion API key>

Success Response

Successful requests return an OTLP-style partialSuccess object.

{
  "partialSuccess": {
    "rejectedLogRecords": 0,
    "errorMessage": ""
  }
}

On this page