portal-observability

Instruments FastAPI applications with OpenTelemetry traces, FinOps token attributes, and prompt hashing.

Updated Jul 27, 2026
One-click install
npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-observability-arthurzizumbo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: portal-observability
Source: https://github.com/ArthurZizumbo/karisma-data/tree/main/.claude/skills/portal-observability
Command: npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-observability-arthurzizumbo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires opentelemetry-sdk, opentelemetry-instrumentation-fastapi, opentelemetry-exporter-gcp-trace.

What problem does it solve? Adding observability to a FastAPI + LLM stack is error-prone: spans get orphaned in async code, raw prompts leak into logs, and token costs go untracked. This Skill provides a complete, privacy-safe OpenTelemetry instrumentation pattern for the Portal Centralizado de Datos Financieros. ## Core Features & Use Cases - Structured trace hierarchy: Automatic FastAPI request traces with nested sub-spans (db.retrieval, rag.retrieval, llm.call, llm.postprocess) and verified async context propagation. - FinOps telemetry: Captures llm.usage.prompt_tokens, llm.usage.completion_tokens, llm.usage.total_tokens, model name, tool-call counts, and TTFT for streaming requests, feeding a tokens/cost dashboard. - Privacy by design: Raw prompt content never reaches traces or logs; only a SHA-256 llm.prompt_hash computed at the single Gemini egress point, plus a grep-based privacy verification check. - Use Case: Instrument a RAG chat endpoint so every request produces a Cloud Trace span tree with token usage and TTFT attributes, then build a daily cost dashboard from the exported spans. ## Quick Start Ask the AI to instrument the FastAPI app with OpenTelemetry following the portal-observability rules, including the llm.call span with FinOps attributes and prompt hashing.

Frequently Asked Questions about portal-observability

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add OpenTelemetry tracing to a FastAPI application?

Create a TracerProvider with a BatchSpanProcessor, then call FastAPIInstrumentor.instrument_app(app) to get automatic per-request traces. Add manual sub-spans with tracer.start_as_current_span for database, retrieval, and LLM operations.

How do I track LLM token usage and cost in OpenTelemetry spans?

Set span attributes like llm.usage.prompt_tokens, llm.usage.completion_tokens, and llm.usage.total_tokens from the model's usage metadata on each llm.call span. Exported spans can then feed a dashboard computing tokens per day and estimated cost.

How do I capture time to first token (TTFT) for streaming LLM responses?

Record a monotonic timestamp when the first streamed chunk arrives and store the delta from request start as an llm.ttft_ms span attribute. This supports latency targets such as a p50 under 700 ms.

How do I avoid logging raw prompts while keeping LLM traces debuggable?

Never write prompt content to spans or logs; instead store a SHA-256 hash of the prompt as an llm.prompt_hash attribute computed at the single model egress point. Verify with a grep check that no logger call references prompt or password content.

Why do OpenTelemetry child spans get lost in async Python code?

Span context does not automatically propagate across asyncio.gather or threadpool boundaries, leaving orphaned spans. Explicitly verify context propagation so child spans like db.retrieval stay nested under the parent request trace.

Can I switch between console and Cloud Trace exporters without code changes?

Yes, select the exporter based on application settings: ConsoleSpanExporter for development and CloudTraceSpanExporter for cloud environments. This avoids commenting code when moving between environments.