Generated banner for Instrument Logs
Generated logo for Instrument Logs

Instrument Logs

PostHogOfficialCreated by PostHog

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • Low risk

From the author

Add PostHog log capture to track application logs. Use after implementing features or reviewing PRs to ensure meaningful log events are captured with structured properties. Also handles initial OTLP exporter setup if not yet configured.
— the description by PostHog

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill guides the integration of PostHog log capture into various application stacks. It automates the setup of OTLP exporters and provides instructions for adding structured logging alongside existing application logs. The skill ensures that log events are captured with meaningful properties, facilitating better observability and debugging within the PostHog platform.

What it does

  • Detects the application platform and existing logging infrastructure.
  • Configures the OpenTelemetry (OTLP) exporter for PostHog ingestion.
  • Integrates PostHog log capture without replacing existing logging handlers.
  • Ensures logs are captured with structured key-value properties.
  • Manages environment variable configuration for API tokens and host URLs.
  • Provides platform-specific guidance for SDK-native log capture.

When to use it

  • After implementing new features that require observability.
  • During code reviews when you identify a need for better log coverage.
  • When setting up initial log export for a new project.
  • When migrating from standard logging to structured, centralized log management.

Advantages

  • Maintains existing logging architecture without disruptive changes.
  • Supports a wide range of languages and frameworks via OpenTelemetry.
  • Enables structured logging for improved search and filtering in PostHog.
  • Automates the configuration of environment variables and ingestion endpoints.

Usage examples

“Add PostHog log capture to my Node.js application.”
The agent will analyze your package.json, install necessary OpenTelemetry dependencies, configure the OTLP exporter, and guide you through adding PostHog logging calls to your code.
“I need to start tracking logs in my Android app using PostHog.”
The agent will verify your Android SDK setup, configure the PostHogAndroidConfig for logs, and show you how to use PostHog.logger to capture structured events.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/posthog/instrument-logs/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip instrument-logs.zip -d .agents/skills

Documentation by PostHog

Add PostHog log capture

Use this skill to add PostHog log capture for new or changed code. Use it after implementing features or reviewing PRs to ensure meaningful log events are captured with structured properties. If PostHog log export is not yet configured, this skill also covers initial OTLP exporter setup. Supports any platform or language.

Supported platforms: Next.js, Node.js, Python, Go, Java, Datadog, Android, React Native, iOS, and any language via OpenTelemetry.

Instructions

Follow these steps IN ORDER:

STEP 1: Analyze the codebase and detect the platform.

  • Detect the language, framework, and existing logging setup.

  • Look for dependency files and project files (package.json, Podfile, Package.swift, requirements.txt, go.mod, pom.xml, etc.).

  • Look for log libraries (winston, pino, logging module, logrus, log4j, serilog, os_log, Logger, etc.).

  • Look for lockfiles (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lockb, go.sum, Podfile.lock, Package.resolved, etc.) to determine the package manager.

  • Check for existing PostHog log export setup. If the OTLP exporter is already configured, skip to STEP 5 to add log capture for new code.

STEP 2: Research log capture. (Skip if PostHog log export is already configured.) 2.1. Find the reference file below that matches the detected platform — it is the source of truth for OTLP exporter configuration and integration with existing logging. Read it now. 2.2. If no reference matches, use the "Other Languages" reference as a fallback — it covers the generic OpenTelemetry approach.

STEP 3: Install dependencies. (Skip if PostHog log export is already configured.)

  • Install the OpenTelemetry SDK and OTLP exporter packages for the detected platform.

  • Do not manually edit dependency files — use the package manager's install command.

STEP 4: Configure the OTLP exporter. (Skip if PostHog log export is already configured.)

  • PostHog logs use the OpenTelemetry protocol. Set up an OTLP exporter pointed at PostHog's ingest endpoint.

  • For SDK-native log support such as Android, React Native, and iOS, follow the platform reference instead of adding a separate OTLP exporter.

  • Follow the platform-specific reference for the exact configuration.

STEP 5: Integrate with existing logging.

  • Add the PostHog log exporter alongside existing logging. Don't replace existing log handlers or outputs.

  • Do not alter the fundamental architecture of existing files. Make additions minimal and targeted.

  • You must read a file immediately before attempting to write it.

STEP 6: Add structured properties.

  • Ensure logs include structured key-value properties for filtering and search in PostHog.

  • Prefer structured log formats with key-value properties over plain text messages.

STEP 7: Set up environment variables.

  • Check if the project already has PostHog environment variables configured (e.g. in .env, .env.local, or framework-specific env files). If valid values already exist, skip this step.

  • If the PostHog project token is missing, use the PostHog MCP server's projects-get tool to retrieve the project's api_token. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.

  • For the PostHog host URL: check the projects-get MCP response for a region field — US maps to https://us.i.posthog.com, EU maps to https://eu.i.posthog.com. If the region is not available from the MCP response or from existing project configuration, ask the user: "Are you on PostHog US Cloud or EU Cloud?" Do not assume US Cloud.

  • For the OpenTelemetry endpoint, use https://us.i.posthog.com/v1 (US) or https://eu.i.posthog.com/v1 (EU), matching the region determined above.

  • Write these values to the appropriate env file using the framework's naming convention.

  • Reference these environment variables in code instead of hardcoding them.

Reference files

  • references/nextjs.md - Next.js logs installation

  • references/nodejs.md - Node.js logs installation

  • references/python.md - Python logs installation

  • references/go.md - Go logs installation

  • references/java.md - Java logs installation

  • references/datadog.md - Datadog logs installation

  • references/android.md - Android logs installation

  • references/react-native.md - React native logs installation

  • references/ios.md - Ios logs installation

  • references/flutter.md - Flutter logs installation

  • references/other.md - Other languages logs installation

  • references/start-here.md - Getting started with logs

  • references/search.md - Search logs

  • references/best-practices.md - Logging best practices

  • references/troubleshooting.md - Logs troubleshooting

  • references/link-session-replay.md - Link session replay

  • references/mcp.md - Use logs over PostHog mcp

  • references/COMMANDMENTS.md - Framework-specific rules the integration must follow

Each platform reference contains specific OTLP configuration, SDK setup, and integration patterns. Find the one matching the user's stack.

Key principles

  • Environment variables: Always use environment variables for PostHog keys and OpenTelemetry endpoints. Never hardcode them.

  • Minimal changes: Add log export alongside existing logging. Don't replace or restructure existing logging code.

  • OpenTelemetry: PostHog logs use the OpenTelemetry protocol. Configure an OTLP exporter pointed at PostHog's ingest endpoint unless the platform SDK provides native log capture.

  • SDK-native logs: For Android, React Native, and iOS, use the SDK logger/capture APIs from the platform reference instead of adding a separate OTLP exporter.

  • Structured logging: Prefer structured log formats with key-value properties over plain text messages.

Files

references/troubleshooting.md

AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt

Logs troubleshooting

Canonical URL: https://posthog.com/docs/logs/troubleshooting

Cloud region: This page uses US Cloud hosts. For an EU Cloud project, use https://eu.i.posthog.com instead of https://us.i.posthog.com (ingestion host), and use https://eu.posthog.com instead of https://app.posthog.com (app host for links).

On this page

  • Authentication errors

  • Connection issues

  • Logs not appearing in PostHog

  • Early startup logs are missing

  • Performance issues

  • Log format problems

  • Logs not appearing on a person's profile

  • Project token authentication issues

  • Self-hosted endpoint issues

  • Still having issues?

This page covers troubleshooting for Logs. For setup, see the installation guide.

Authentication errors

Problem: Getting 401 Unauthorized errors when sending logs.

Solutions:

  • Verify you're using the correct project token from Project Settings

  • Check the Authorization header format: Bearer <ph_project_token>

  • If using query parameter, verify the format: ?token=<ph_project_token>

  • Ensure your project token hasn't been rotated or revoked

Connection issues

Problem: Cannot connect to the PostHog Logs endpoint.

Solutions:

  • Verify the endpoint URL: https://us.i.posthog.com/i/v1/logs

  • Check that your application can make outbound HTTPS requests

  • Ensure firewall rules allow outbound connections to PostHog

  • For self-hosted instances, verify the endpoint is correct for your deployment

Logs not appearing in PostHog

Problem: Logs are being sent but don't appear in the PostHog interface.

Solutions:

  • Verify your project token is correct and associated with the right project

  • Check that logs are being sent in the correct OTLP format

  • Ensure your project has access to the Logs feature in PostHog

  • Check the network tab in your browser/application to verify requests are succeeding (200 status)

Early startup logs are missing

Problem: Console output from the first moments of a page load – React hydration warnings, errors thrown during bootstrap – never reaches Logs, while console calls made later arrive fine.

Solutions:

  • Upgrade to posthog-js 1.422.0 or later, which buffers console.* calls made while the logs script is still loading and backfills them once it is ready.

  • Enable capture with logs: { captureConsoleLogs: true } in posthog.init() rather than only with the Capture console logs project setting. With the project setting alone, a visitor's first page load does not start capturing until remote config responds; the init() option starts at posthog.init() on every load.

  • Check that the calls are among the levels captured: console.log, console.info, console.debug, console.warn, and console.error.

  • If more than logs.maxBufferSize console calls (100 by default) happen before the script loads, only the earliest are kept.

Performance issues

Problem: High memory usage or slow log processing.

Solutions:

  • Adjust the batch size in your OpenTelemetry configuration

  • Use BatchLogRecordProcessor instead of SimpleLogRecordProcessor for better performance

  • Consider filtering logs on the client side to reduce volume

  • Check for network latency between your application and PostHog

Log format problems

Problem: Logs are being received but not parsed correctly.

Solutions:

  • Ensure you're using the standard OTLP log format

  • Verify log levels are set correctly (INFO, WARN, ERROR, etc.)

  • Check that log attributes are properly structured

  • Use the OpenTelemetry logging APIs instead of raw log libraries

Logs not appearing on a person's profile

Problem: Logs are searchable in the Logs view, but the person profile's Logs tab is empty (or missing logs you expected to see).

Solutions:

  • Confirm each log record carries the attribute posthogDistinctId (camelCase, lowercase p) — see Link logs to a person. distinct_id, posthog_distinct_id, and user_id are not equivalent unless you've explicitly configured one as the custom attribute key.

  • The value of the attribute must equal one of the person's distinct_ids exactly — partial or prefixed matches are not picked up.

  • If your team has customized the attribute key (via the logs_config endpoint), the person profile's Logs tab shows a hint above the chart indicating which key is being used. Make sure your pipeline emits logs under that exact key.

  • Date range: the person Logs tab respects the same date range picker as the main Logs view. Expand the range if the logs are older than the default window.

Project token authentication issues

Problem: Confused about which key to use or how to authenticate.

Solutions:

  • Use your project token (the same one you use for capturing events)

  • Find it in Project Settings

  • You can authenticate in two ways:

    • Header: Authorization: Bearer <ph_project_token>

    • Query param: ?token=<ph_project_token>

  • Do not use your personal API key or other authentication methods

Self-hosted endpoint issues

Problem: Logs not working with self-hosted PostHog.

Solutions:

  • Use your self-hosted instance URL instead of https://us.i.posthog.com

  • Verify the logs endpoint is enabled on your self-hosted instance

  • Check that the endpoint path is correct: /logs

  • Ensure your PostHog version supports the logs feature

Still having issues?

If you're still experiencing problems:

  1. Verify your OpenTelemetry client configuration matches the examples in the installation guide

  2. Test with a simple log message first before sending complex logs

  3. Check the network requests to see the actual HTTP status codes and error messages

  4. Contact PostHog support with your specific error messages and configuration details

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an MCP server, Needs Python, Needs Node.js

Security

What our scanner noticed· Low risk

  • Instructions that use the network

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
PostHog
Publisher
PostHog (Official)
Source
PostHog/skills · skills/omnibus/instrument-logs · commit a5d30e7
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by PostHog or PostHog.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download instrument-logs.zip