A CLI tool to fetch full trace details from Pydantic Logfire by traceId.
- Single-purpose - Query traces by traceId, nothing more
- Pretty output - Formatted JSON by default
- Compact mode - Machine-friendly JSON for scripting
- Verbose mode - Show HTTP request/response details
- Flexible config - CLI flags, environment variables, or config file
# Build
make build
# Query a trace
./bin/lfsnag <traceId># Clone the repository
git clone https://github.com/bigbag/lfsnag.git
cd lfsnag
# Build
make build
# Or install to GOPATH/bin
make install-c, --compact- Compact JSON output-v, --verbose- Show HTTP request/response details-e, --env- Environment profile name-f, --fields- Comma-separated list of fields to select (default: all)--sql- Raw SQL query to execute against the Logfire API--token- Override read token
start_timestamp- When the span/log was created (UTC)end_timestamp- When the span/log completed (UTC)duration- Elapsed time in seconds (NULL for logs)trace_id- Trace identifier (32 hex chars)span_id- Span identifier (16 hex chars)parent_span_id- Parent span reference (NULL for root spans)kind-span,log,span_event, orpending_spanspan_name- Short name shared by similar recordsmessage- Human-readable descriptionlevel- Severity levelis_exception- Whether an exception was recordedexception_type- Exception class nameexception_message- Exception messageexception_stacktrace- Formatted tracebackattributes- Arbitrary structured data (JSON)tags- Grouping labelsotel_status_code- Span status indicatorotel_status_message- Span error status descriptionotel_events- Span events (JSON)otel_links- Span links (JSON)service_name- Service/application nameservice_version- Service versionservice_instance_id- Service instance identifierservice_namespace- Service namespacedeployment_environment- Environment (production, staging, etc.)process_pid- Process IDhttp_response_status_code- HTTP status codehttp_method- HTTP methodhttp_route- HTTP route patternurl_full- Complete URLurl_path- URL pathurl_query- URL query stringlog_body- Body of OpenTelemetry log recordsotel_resource_attributes- Resource metadata (JSON)otel_scope_name- Instrumenting library nameotel_scope_version- Instrumenting library versionotel_scope_attributes- Scope metadata (JSON)telemetry_sdk_name- Telemetry SDK nametelemetry_sdk_language- SDK languagetelemetry_sdk_version- SDK version
Configuration is resolved in priority order: CLI flags > environment variables > config file.
Path: ~/.config/lfsnag/config.json
{
"default": "prod",
"environments": {
"prod": {
"token": "prod-read-token",
"base_url": "https://logfire-us.pydantic.dev"
},
"stage": {
"token": "stage-read-token",
"base_url": "https://logfire-eu.pydantic.dev"
}
}
}Select an environment with -e:
lfsnag -e prod abc123def456789012345678abcdef01If -e is omitted, the "default" field is used. CLI flags and env vars still override profile values.
LOGFIRE_READ_TOKEN- Logfire read tokenLOGFIRE_BASE_URL- API base URL (default:https://logfire-us.pydantic.dev)
lfsnag abc123def456789012345678abcdef01Paste a full Logfire URL — the traceId query parameter is extracted automatically:
lfsnag 'https://logfire-us.pydantic.dev/org/proj?traceId=abc123def456789012345678abcdef01&spanId=...'lfsnag -c abc123def456789012345678abcdef01lfsnag -v abc123def456789012345678abcdef01lfsnag -f span_name,start_timestamp,duration abc123def456789012345678abcdef01lfsnag --token "your-token" abc123def456789012345678abcdef01lfsnag -e dev --sql "SELECT span_name, duration FROM records WHERE is_exception = true"Filter by trace with custom fields:
lfsnag -e dev --sql "SELECT span_name, duration FROM records WHERE trace_id = '019d05ee9be731d9f95c339fb7b9c6c1' AND is_exception = true"Aggregate spans:
lfsnag -e dev --sql "SELECT span_name, count(*) as cnt FROM records GROUP BY span_name ORDER BY cnt DESC LIMIT 10"Extract span names:
lfsnag -c abc123def456789012345678abcdef01 | jq '.[].span_name'Count spans in a trace:
lfsnag -c abc123def456789012345678abcdef01 | jq 'length'Filter spans by attribute:
lfsnag -c abc123def456789012345678abcdef01 | jq '[.[] | select(.is_exception == true)]'Save trace to file:
lfsnag abc123def456789012345678abcdef01 > trace.jsonmake build # Build binary to bin/lfsnag
make run # Build and run
make run/quick # Run without rebuild
make test # Run tests
make test-race # Run tests with race detection
make coverage # Run tests with coverage report
make coverage-html # Generate HTML coverage report
make fmt # Format code
make vet # Run go vet
make lint # Run fmt and vet
make tidy # Tidy Go modules
make clean # Remove build artifacts
make install # Install to GOPATH/bin
make build-all # Build for linux/darwin/windows amd64/arm64# Run all tests
make test
# Run tests with verbose output
go test -v ./...
# Run tests with coverage
make coverage
# Run tests with race detection
make test-racelfsnag includes a Claude Code plugin. Use /lfsnag:trace to investigate Logfire traces directly from Claude Code.
/plugin marketplace add bigbag/lfsnag
/plugin install lfsnag@bigbag-lfsnag/plugin marketplace add /path/to/lfsnag
/plugin install lfsnag@lfsnagThen type /lfsnag:trace to start investigating a trace.
claude --plugin-dir .Use /reload-plugins after making changes to the skill without restarting.
MIT License - see LICENSE file.