OpenTelemetry: PostHog logs use the OpenTelemetry protocol. Configure an OTLP exporter pointed at PostHog's ingest endpoint.
Structured logging: Prefer structured log formats with key-value properties over plain text messages.
Framework guidelines
Remember that source code is available in the venv/site-packages directory
posthog is the Python SDK package name
Install dependencies with pip install posthog or pip install -r requirements.txt and do NOT use unquoted version specifiers like >= directly in shell commands
In CLIs and scripts: MUST call posthog.shutdown() before exit or all events are lost
Always use the Posthog() class constructor (instance-based API) instead of module-level posthog.api_key config
Always include enable_exception_autocapture=True in the Posthog() constructor to automatically track exceptions
NEVER send PII in capture() event properties — no emails, full names, phone numbers, physical addresses, IP addresses, or user-generated content
PII belongs in identify() person properties, NOT in capture() event properties. Safe event properties are metadata like message_length, form_type, boolean flags.
Register posthog_client.shutdown with atexit.register() to ensure all events are flushed on exit
The Python SDK has NO identify() method — use posthog_client.set(distinct_id=user_id, properties={...}) to set person properties, or use identify_context(user_id) within a context
1---2name: logs-python3description: PostHog logs for Python4---56# PostHog logs for Python78This skill helps you add PostHog log ingestion to Python applications.910## Reference files1112- `references/python.md` - Python logs installation - docs13- `references/start-here.md` - Getting started with logs - docs14- `references/search.md` - Search logs - docs15- `references/best-practices.md` - Logging best practices - docs16- `references/troubleshooting.md` - Logs troubleshooting - docs17- `references/link-session-replay.md` - Link session replay - docs18- `references/debug-logs-mcp.md` - Debug logs with mcp - docs1920Consult the documentation for API details and framework-specific patterns.2122## Key principles2324- **Environment variables**: Always use environment variables for PostHog keys and OpenTelemetry endpoints. Never hardcode them.25- **Minimal changes**: Add log export alongside existing logging. Don't replace or restructure existing logging code.26- **OpenTelemetry**: PostHog logs use the OpenTelemetry protocol. Configure an OTLP exporter pointed at PostHog's ingest endpoint.27- **Structured logging**: Prefer structured log formats with key-value properties over plain text messages.2829## Framework guidelines3031- Remember that source code is available in the venv/site-packages directory32- posthog is the Python SDK package name33- Install dependencies with `pip install posthog` or `pip install -r requirements.txt` and do NOT use unquoted version specifiers like `>=` directly in shell commands34- In CLIs and scripts: MUST call posthog.shutdown() before exit or all events are lost35- Always use the Posthog() class constructor (instance-based API) instead of module-level posthog.api_key config36- Always include enable_exception_autocapture=True in the Posthog() constructor to automatically track exceptions37- NEVER send PII in capture() event properties — no emails, full names, phone numbers, physical addresses, IP addresses, or user-generated content38- PII belongs in identify() person properties, NOT in capture() event properties. Safe event properties are metadata like message_length, form_type, boolean flags.39- Register posthog_client.shutdown with atexit.register() to ensure all events are flushed on exit40- The Python SDK has NO identify() method — use posthog_client.set(distinct_id=user_id, properties={...}) to set person properties, or use identify_context(user_id) within a context
Run npx skillmds@latest add posthog-skills/logs-python in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
PostHog logs for Python It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
posthog (@posthog-skills) published this skill. Their other Agent Skills are listed on their SkillMD profile.