logs-nextjs

Configure OpenTelemetry log export from Next.js to PostHog via OTLP.

Updated Feb 24, 2026
One-click install
npx skills add https://github.com/FrekiManagarm/dunlo --skill logs-nextjs-frekimanagarm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logs-nextjs
Source: https://github.com/FrekiManagarm/dunlo/tree/main/.agents/skills/logs-nextjs
Command: npx skills add https://github.com/FrekiManagarm/dunlo --skill logs-nextjs-frekimanagarm

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you get useful, queryable PostHog log ingestion working in Next.js by wiring OpenTelemetry Logs to PostHog’s OTLP endpoint with correct Next.js-specific setup.

Core Features & Use Cases

  • PostHog log ingestion for Next.js: Enables exporting structured logs from a Next.js app to PostHog using OTLP over HTTP.
  • Framework-guided instrumentation: Provides guidance for Next.js instrumentation setup and placement (notably for Next.js 15.3+ via instrumentation-client.ts).
  • Production-ready logging guidance: Reinforces best practices like using environment variables, structured key-value attributes, minimal code changes, and trace/session context for correlation.

Quick Start

Add PostHog log ingestion to your Next.js app by configuring an OpenTelemetry logger provider that exports logs to https://us.i.posthog.com/i/v1/logs using your project token from environment variables, and ensure logs are flushed in route handlers.

Frequently Asked Questions about logs-nextjs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I send structured logs from Next.js to PostHog?

To send structured logs from Next.js to PostHog, you can configure an OpenTelemetry Logs provider to export events over OTLP HTTP to PostHog's ingestion endpoint using your project token. This captures backend log events for querying in PostHog.

How do I set up OpenTelemetry instrumentation for Next.js 15.3 logging?

Setting up OpenTelemetry instrumentation for Next.js 15.3 logging involves configuring the logger provider in the instrumentation-client.ts file. This ensures server-side log events are correctly captured and exported via OTLP before route handlers finish execution.

Can I use environment variables to configure PostHog log ingestion in Next.js?

Yes, you can and should use environment variables to configure PostHog log ingestion in Next.js. This best practice involves passing your PostHog project token from environment variables into the OTLP exporter setup to keep credentials secure and manageable.

What is the best way to ensure Next.js API route logs are flushed to PostHog?

The best way to ensure Next.js API route logs are flushed to PostHog is to explicitly trigger log flushing within your route handlers. This guarantees that structured log events are exported via OTLP before the server-side request cycle completes.

Does PostHog log ingestion support structured logging with trace context in Next.js?

Yes, PostHog log ingestion supports structured logging with trace context in Next.js. By using OpenTelemetry Logs over OTLP, you can attach structured key-value attributes and trace or session context to enable correlation in PostHog.

What are the limitations of using OTLP for Next.js server-side logging?

A limitation of using OTLP for Next.js server-side logging is ensuring reliable export behavior during serverless execution. It requires minimal code changes and careful placement of instrumentation to prevent logs from being dropped before requests terminate.