AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

instrument-logs

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.

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--instrument-logs at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 19

references/start-here.md

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

Getting started with Logs

Canonical URL: https://posthog.com/docs/logs/start-here

On this page

Use your logging client

PostHog Logs works with any OpenTelemetry client. No PostHog-specific packages required. Use the OTel SDKs you already have, point them at PostHog's HTTP endpoint, and drop in your project token.

On the frontend, our JavaScript web SDK, React Native SDK, iOS SDK, and Android SDK include first-class logging support.

Follow the guides below to set up your logging client:

Configure logging client

Send context-rich logs

PostHog ingests logs in the same pattern as OTel's structured logging model: resource attributes, log attributes, and trace context.

Enrich your logs with granular detail and business context for INFO, DEBUG, WARN, and ERROR log levels.

import logging

# Configure logging to use OpenTelemetry
logging.basicConfig(level=logging.INFO)
logging.getLogger().addHandler(LoggingHandler())

# Use standard Python logging
logger = logging.getLogger("my-app")
logger.info("User action", extra={"userId": "123", "action": "login"})
logger.warning("Deprecated API used", extra={"endpoint": "/old-api"})
logger.error("Database connection failed", extra={"error": "Connection timeout"})

Learn best practices

Search and analyze your logs

Once your logs are flowing into PostHog, you can:

  • Search through logs using full-text searches, multiple search tokens, and negative filters
  • Filter by time ranges to find specific events
  • Filter on attributes for specific resources or events
  • Correlate logs with events from your PostHog analytics

PostHog Logs search interface

Learn how to search logs

Analyze log patterns

The Patterns view automatically mines your logs to find recurring message templates. Use it to spot noisy log lines consuming your log budget, find new error shapes by their template structure, and see which patterns dominate your log volume.

Expand any pattern and click View matching logs to pivot to the Logs view filtered to lines matching that template. The filter lands in the filter bar as a visible, removable chip, and your date range, service, and severity selections carry over.

Explore log patterns

Set up alerts

Get notified when your logs match specific conditions. Create alerts to:

  • Monitor error spikes — Alert when error log counts exceed a threshold
  • Track specific services — Watch for issues in critical services
  • Filter by attributes — Set up granular alerts based on log attributes

Configure alerting rules in your project settings to stay on top of issues as they happen.

Configure log alerts

Use MCP and AI to debug

Connect the PostHog MCP server and your AI agent can query logs directly. Use Cursor, Claude Code, or any MCP-compatible tool.

Your coding agent pulls the relevant logs it needs to debug and build faster without switching workflows.

Try asking your agent for these:

  • Show me error logs from the API service in the last hour
  • What services are logging errors right now?
  • Compare log patterns from today against yesterday and show me what's new

In the web app, you can also open a single log record and have PostHog AI explain it – what it means, what probably caused it, and what to do next.

Explore logs with AI

Integrate your product data

With PostHog, your logs live alongside your Product Analytics, Session Replays, Error Tracking, and Dashboards, so you can go from a log line to a user's session to the flag variant they were on without switching tools.

Session Replay

Log events in PostHog can be connected to the session and user who triggered them. Jump from a log line to a session replay in one click.

logs and errors

Product Analytics

Turn log patterns into trends, funnels, and retention insights. Know which logged errors actually hurt user retention vs. which are just noise.

logs and product analytics

Error Tracking

Logs with $exception events become issues you can assign, resolve, and alert on. No separate error tracking tool needed.

logs and session replay

Dashboards

Add a Recent logs widget to any dashboard to monitor log entries alongside your other metrics and insights. Filter by severity level and service, and click a row to jump to that log on the Logs page.

Use for free

PostHog's Logs is built to be cost-effective by default, with a generous free tier and transparent usage-based pricing. Since we don't charge per seat, more than 90% of companies use PostHog for free.

TL;DR 💸

  • No credit card required to start
  • First 10 GB of ingested logs per month are free
  • Above 10 GB we have usage-based pricing at $0.25/GB with discounts
  • All logs are retained 14 days by default. Set custom retention per service or per source for $0.05/GB per month retained – see logs pricing for more details
  • Set billing limits to avoid surprise charges (they don't cap custom retention)
  • See our pricing page for more up-to-date details

That's it! You're ready to start integrating.

Install logs

1/8

Use your logging client RequiredSend context-rich logs RequiredSearch and analyze your logs RequiredAnalyze log patterns RecommendedSet up alerts RecommendedUse MCP and AI to debug RecommendedIntegrate your product data RecommendedUse for free Free 10 GB/mo

Use your logging client

Required