instrument-logs
Automates the integration of PostHog log capture into existing codebases, supporting multiple languages and OpenTelemetry setups.
Install
mkdir -p .claude/skills/instrument-logs && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/19552" && unzip -o skill.zip -d .claude/skills/instrument-logs && rm skill.zipInstalls to .claude/skills/instrument-logs
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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.Key capabilities
- →Detect project platform and existing logging libraries
- →Configure OTLP exporters for PostHog log ingestion
- →Integrate PostHog log export alongside existing logging handlers
- →Add structured key-value properties to log events
- →Manage PostHog project tokens and host URLs via environment variables
How it works
The skill detects the project's platform and logging libraries, then configures an OTLP exporter to send logs to PostHog's ingest endpoint. It integrates these additions alongside existing logging without replacing current handlers.
Inputs & outputs
When to use instrument-logs
- →Instrument new features with logs
- →Configure OTLP exporters
- →Add PostHog logging to a React app
- →Ensure logs have structured properties
- →Setup monitoring for a new backend service
About this skill
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-gettool to retrieve the project'sapi_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-getMCP response for aregionfield —USmaps tohttps://us.i.posthog.com,EUmaps tohttps://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) orhttps://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 - docsreferences/nodejs.md- Node.js logs installation - docsreferences/python.md- Python logs installation - docsreferences/go.md- Go logs installation - docsreferences/java.md- Java logs installation - docsreferences/datadog.md- Datadog logs installation - docsreferences/android.md- Android logs installation - docsreferences/react-native.md- React native logs installation - docsreferences/ios.md- Ios logs installation - docsreferences/flutter.md- Flutter logs installation - docsreferences/other.md- Other languages logs installation - docsreferences/start-here.md- Getting started with logs - docsreferences/search.md- Search logs - docsreferences/best-practices.md- Logging best practices - docsreferences/troubleshooting.md- Logs troubleshooting - docsreferences/link-session-replay.md- Link session replay - docsreferences/debug-logs-mcp.md- Debug logs with mcp - docsreferences/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.
When not to use it
- →Replacing existing log handlers or outputs
- →Hardcoding PostHog project tokens or host URLs
- →Altering the fundamental architecture of existing files
Prerequisites
Limitations
- →Requires manual selection of project if multiple are returned
- →Does not replace existing log handlers
- →Requires user input for region if not available from MCP response
How it compares
Unlike manual logging setup, this skill automates the detection of the platform and the configuration of OTLP exporters while ensuring structured properties are added.
Compared to similar skills
instrument-logs side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| instrument-logs (this skill) | 0 | 10d | Review | Intermediate |
| langfuse | 7 | 6mo | No flags | Intermediate |
| logging-monitoring | 0 | 4mo | No flags | Intermediate |
| i18n-localization | 15 | 6mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by PostHog
View all by PostHog →You might also like
langfuse
davila7
Expert in Langfuse - the open-source LLM observability platform. Covers tracing, prompt management, evaluation, datasets, and integration with LangChain, LlamaIndex, and OpenAI. Essential for debugging, monitoring, and improving LLM applications in production. Use when: langfuse, llm observability, llm tracing, prompt management, llm evaluation.
logging-monitoring
jnPiyush
Implement observability patterns including structured logging, log levels, correlation IDs, metrics, and distributed tracing. Use when adding structured logging, implementing correlation IDs for request tracing, configuring metrics collection, setting up distributed tracing, or designing alerting ru
i18n-localization
davila7
Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.
engineering-skills
alirezarezvani
23 production-ready engineering skills covering architecture, frontend, backend, fullstack, QA, DevOps, security, AI/ML, data engineering, computer vision, and specialized tools like Playwright Pro, Stripe integration, AWS, and MS365. 30+ Python automation tools (all stdlib-only). Works with Claude Code, Codex CLI, and OpenClaw.
podcast-generation
microsoft
Generate AI-powered podcast-style audio narratives using Azure OpenAI's GPT Realtime Mini model via WebSocket. Use when building text-to-speech features, audio narrative generation, podcast creation from content, or integrating with Azure OpenAI Realtime API for real audio output. Covers full-stack implementation from React frontend to Python FastAPI backend with WebSocket streaming.
prowler
prowler-cloud
Main entry point for Prowler development - quick reference for all components. Trigger: General Prowler development questions, project overview, component navigation (NOT PR CI gates or GitHub Actions workflows).