Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

instrument-llm-analytics

БесплатноБез исполняемых скриптовНе проверен

Add PostHog AI Observability to trace AI model usage. Use after implementing LLM features or reviewing PRs to ensure all generations are captured with token…

PostHogот PostHog★ 81 звезда на GitHub

Об этом скилле

Add PostHog AI Observability

Use this skill to add PostHog AI Observability that traces AI model usage in new or changed code. Use it after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. If PostHog is not yet installed, this skill also covers initial SDK setup. Supports any provider or framework.

Supported providers: OpenAI, Azure OpenAI, Anthropic, Google, Cohere, Mistral, Perplexity, DeepSeek, Groq, Together AI, Fireworks AI, xAI, Cerebras, Hugging Face, Ollama, OpenRouter.

Supported frameworks: LangChain, LlamaIndex, CrewAI, AutoGen, DSPy, LangGraph, Pydantic AI, Vercel AI, LiteLLM, Instructor, Semantic Kernel, Mirascope, Mastra, SmolAgents, OpenAI Agents.

Proxy/gateway: Portkey, Helicone.

Instructions

Before you edit anything, read references/COMMANDMENTS.md. It lists the rules every PostHog install follows: how to install the SDK, where to create the client, how to identify users, Content Security Policy and multi-platform apps, plus the rules for this framework.

Follow these steps IN ORDER:

STEP 1: Analyze the codebase and detect the LLM stack.

  • Look for LLM provider SDKs (openai, anthropic, google-generativeai, etc.) and AI frameworks (langchain, llamaindex, crewai, etc.) in dependency files and imports.
  • Look for lockfiles to determine the package manager.
  • Check for existing PostHog or observability setup. If PostHog is already installed and LLM tracing is configured, skip to STEP 4 to add tracing for any new LLM calls.

STEP 2: Research instrumentation. (Skip if PostHog LLM tracing is already set up.) 2.1. Find the reference file below that matches the detected provider or framework — it is the source of truth for callback setup, middleware configuration, and event capture. Read it now. 2.2. If no reference matches, use manual-capture.md as a fallback — it covers the generic event capture approach that works with any provider.

STEP 3: Install the PostHog SDK. (Skip if PostHog is already set up.)

  • Add the PostHog SDK and any required callback/integration packages.
  • Do not manually edit dependency files — use the package manager's install command.
  • If the project keeps more than one lockfile for the same manifest, such as a second Gemfile lock for another bundle, update each one.

STEP 4: Add LLM tracing.

  • Instrument LLM calls to capture input tokens, output tokens, model name, latency, and costs for every generation.
  • Follow the provider-specific reference for the exact callback/middleware setup.
  • 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 5: Link to users.

  • Associate LLM generations with identified users via distinct IDs when possible.

STEP 6: 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 project token that the tool or CLI which started this setup already gave you (for example in its output or instructions).
  • If it gave you none, call the PostHog MCP server's projects-get tool to list the projects. If more than one comes back, ask the user which project to use. Then call project-get with that project's id and read its api_token. Before you write the token, tell the user the project's name and confirm it is the one this app should send to. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
  • For the PostHog host URL: use the host that the tool or CLI which started this setup already gave you. If it gave you none, use the api_host field of the project-get response. If you still have no host from the calling tool, the MCP response, or existing project configuration, ask the user: "Are you on PostHog US Cloud or EU Cloud?" Do not assume US Cloud.
  • Write these values to the appropriate env file using the framework's naming convention.
  • Reference these environment variables in code instead of hardcoding them.
  • List the key names in .env.example, or the env template the project already uses, with placeholder values, so the next developer knows what to set. Create .env.example if the project has none. Never put real values in it.
  • Read the keys as optional: a missing key must never break the build or boot. Follow the missing-configuration rule in references/COMMANDMENTS.md.

Reference files

  • references/openai.md - Openai observability installation
  • references/azure-openai.md - Azure openai observability installation
  • references/README.md - PostHog.ai for .net
  • references/anthropic.md - Anthropic ai observability installation
  • references/google.md - Google ai observability installation
  • references/cohere.md - Cohere a
Полный SKILL.md на GitHub

Установить instrument-llm-analytics в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/COMMANDMENTS.mdreferences/README.mdreferences/anthropic.mdreferences/autogen.mdreferences/azure-openai.mdreferences/basics.mdreferences/calculating-costs.mdreferences/cerebras.mdreferences/cohere.mdreferences/crewai.mdreferences/deepseek.mdreferences/dspy.mdreferences/fireworks-ai.mdreferences/google.mdreferences/groq.mdreferences/helicone.mdreferences/hugging-face.mdreferences/instructor.mdreferences/langchain.mdreferences/langgraph.mdreferences/litellm.mdreferences/llamaindex.mdreferences/manual-capture.mdreferences/mastra.mdreferences/mirascope.mdreferences/mistral.mdreferences/ollama.mdreferences/openai-agents.mdreferences/openai.mdreferences/openrouter.mdreferences/perplexity.mdreferences/portkey.mdreferences/pydantic-ai.mdreferences/semantic-kernel.mdreferences/smolagents.mdreferences/together-ai.mdreferences/traces.mdreferences/vercel-ai.mdreferences/xai.md

FAQ

Что делает скилл instrument-llm-analytics?

Add PostHog AI Observability to trace AI model usage. Use after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. Also handles initial PostHog SDK setup if not yet installed.

Как установить скилл instrument-llm-analytics?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл instrument-llm-analytics запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить instrument-llm-analytics с