{"id":51013880,"url":"https://github.com/ipfans/claude-code-logfire-plugin-extend","last_synced_at":"2026-06-21T07:31:06.179Z","repository":{"id":361997480,"uuid":"1256804042","full_name":"ipfans/claude-code-logfire-plugin-extend","owner":"ipfans","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-02T05:38:13.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-02T07:21:55.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipfans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-02T05:26:41.000Z","updated_at":"2026-06-02T05:38:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ipfans/claude-code-logfire-plugin-extend","commit_stats":null,"previous_names":["ipfans/claude-code-logfire-plugin-extend"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ipfans/claude-code-logfire-plugin-extend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfans%2Fclaude-code-logfire-plugin-extend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfans%2Fclaude-code-logfire-plugin-extend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfans%2Fclaude-code-logfire-plugin-extend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfans%2Fclaude-code-logfire-plugin-extend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfans","download_url":"https://codeload.github.com/ipfans/claude-code-logfire-plugin-extend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfans%2Fclaude-code-logfire-plugin-extend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34601660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-21T07:31:05.476Z","updated_at":"2026-06-21T07:31:06.172Z","avatar_url":"https://github.com/ipfans.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logfire plugin for Claude Code\n\nA [Claude Code](https://docs.anthropic.com/en/docs/claude-code) plugin that sends OpenTelemetry traces to [Pydantic Logfire](https://logfire.pydantic.dev), giving you full observability into your Claude Code sessions.\n\nEach session becomes a trace with child spans per LLM API call, with full token usage, cost tracking, and conversation history visible in Logfire.\n\n\u003c!-- TODO: add Logfire screenshot here --\u003e\n\n## Installation\n\n### System requirements\n\n- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) installed\n- A [Logfire](https://logfire.pydantic.dev) project with a write token\n- `python3` (3.7+) — pre-installed on macOS and most Linux distributions; uses stdlib only (no pip dependencies)\n\n### Install the plugin\n\nFrom within Claude Code, run:\n\n```\n/plugin marketplace add ipfans/claude-code-logfire-plugin-extend\n/plugin install logfire-session-capture@claude-code-logfire-plugin-extend\n```\n\n### Set your Logfire token\n\n```bash\nexport LOGFIRE_TOKEN=\"your-logfire-write-token\"\n```\n\nAdd this to your shell profile (`~/.zshrc`, `~/.bashrc`, etc.) so it persists across sessions.\n\nFor the EU region:\n\n```bash\nexport LOGFIRE_BASE_URL=\"https://logfire-eu.pydantic.dev\"\n```\n\n| Variable | Required | Default | Description |\n|---|---|---|---|\n| `LOGFIRE_TOKEN` | Yes | _(none)_ | Logfire write token |\n| `LOGFIRE_BASE_URL` | No | `https://logfire-us.pydantic.dev` | Logfire ingest endpoint |\n| `LOGFIRE_LOCAL_LOG` | No | `false` | Set to `true` to write JSONL event logs locally |\n| `LOGFIRE_DIAGNOSTICS` | No | `false` | Set to `true` to write diagnostic logs (enabled automatically when `LOGFIRE_LOCAL_LOG` is set) |\n| `LOGFIRE_ENVIRONMENT` | No | _(none)_ | Sets `deployment.environment.name` on every trace (e.g. `production`, `dev`) |\n| `LOGFIRE_SESSION_LABEL` | No | `Claude Code session` | Label for the root session span — useful when running multiple CC sessions in one trace |\n| `OTEL_SERVICE_NAME` | No | `claude-code-plugin` | Overrides the `service.name` resource attribute |\n| `OTEL_RESOURCE_ATTRIBUTES` | No | _(none)_ | Standard OTel env var for additional resource attributes, e.g. `deployment.environment.name=prod,service.instance.id=worker-1` |\n\nWithout `LOGFIRE_TOKEN`, no traces are sent. The plugin does nothing unless at least one of `LOGFIRE_TOKEN` or `LOGFIRE_LOCAL_LOG` is set.\n\n## What you get\n\nEvery Claude Code session produces a trace in Logfire:\n\n```\nClaude Code session              \u003c- root span (the full session)\n├── chat claude-opus-4-6         \u003c- LLM API call 1\n├── chat claude-opus-4-6         \u003c- LLM API call 2\n└── chat claude-opus-4-6         \u003c- LLM API call 3\n```\n\nEach `chat` child span includes:\n\n- **Token usage** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`)\n- **Cost** (`operation.cost` in USD)\n- **Messages** (`gen_ai.input.messages`, `gen_ai.output.messages`)\n- **Finish reason** (`gen_ai.response.finish_reasons`)\n\nThe root span carries the full conversation, so you can inspect the entire session in Logfire's trace view.\n\n## Distributed tracing\n\nIf you call Claude Code from a Python application that already uses Logfire or OpenTelemetry, you can link the Claude Code session into your existing trace by passing a `TRACEPARENT` environment variable:\n\n```bash\nTRACEPARENT=\"00-\u003ctrace_id\u003e-\u003cparent_span_id\u003e-01\" claude --print \"your prompt\"\n```\n\nSee [`examples/distributed-tracing.py`](examples/distributed-tracing.py) for a complete example using `logfire` and `subprocess`.\n\n## Local JSONL log\n\nSet `LOGFIRE_LOCAL_LOG=true` to write all hook events as JSON Lines to `.claude/logs/session-events.jsonl` in the project directory. This is off by default.\n\n## Data collected\n\nWhen `LOGFIRE_TOKEN` is set, the plugin sends the following data to Logfire as OpenTelemetry span attributes:\n\n| Data | Span | Attribute |\n|---|---|---|\n| Full conversation (user prompts, assistant responses, tool calls and results) | Root span | `pydantic_ai.all_messages` |\n| Per-call input/output messages | Child spans | `gen_ai.input.messages`, `gen_ai.output.messages` |\n| Token counts | Child spans | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |\n| Cost in USD | Child spans | `operation.cost` |\n| Model name | Both | `gen_ai.request.model` |\n| Working directory | Root span | `session.cwd` |\n| Assistant thinking blocks | Child spans | Included in `gen_ai.output.messages` |\n\n**Privacy note:** Conversation data sent to Logfire may contain sensitive information including file contents read by Claude, tool outputs, environment details, and any text in the conversation. Logfire data is stored according to [Pydantic's privacy policy](https://pydantic.dev/privacy). If this is a concern, use `LOGFIRE_LOCAL_LOG=true` without `LOGFIRE_TOKEN` to keep all data local.\n\n## Troubleshooting\n\n**Enable diagnostics** to see what the plugin is doing:\n\n```bash\nexport LOGFIRE_DIAGNOSTICS=true\n```\n\nDiagnostic logs are written to `.claude/logs/diagnostics.jsonl` in the project directory.\n\n**Common issues:**\n\n- **No traces appearing in Logfire** -- Check that `LOGFIRE_TOKEN` is set and valid. Enable diagnostics to see if OTLP exports are failing.\n- **Export errors (HTTP 401/403)** -- Your Logfire token may be invalid or expired. Generate a new write token in the Logfire console.\n- **Export errors (HTTP 4xx/5xx)** -- Check `LOGFIRE_BASE_URL` if using a non-default region. The plugin logs HTTP status codes to stderr and diagnostics.\n\n## Development\n\n```bash\nuv sync\nuv run ruff check scripts/\nuv run ruff format scripts/\n```\n\n## How it works\n\nThe plugin is a single Python script ([`scripts/log-event.py`](scripts/log-event.py), stdlib only) invoked by Claude Code hooks on every session event. On `Stop` events it parses the transcript file to extract per-API-call data (deduplicating streaming fragments) and sends OTLP/HTTP JSON to Logfire. On `SessionEnd` it sends the root span with the accumulated conversation.\n\nState is persisted in a temp file between hook invocations. The `trace_id` is deterministically derived from `session_id` via SHA-256.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfans%2Fclaude-code-logfire-plugin-extend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfans%2Fclaude-code-logfire-plugin-extend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfans%2Fclaude-code-logfire-plugin-extend/lists"}