mcpField
O
otel-flask-style

otel-flask-style

github.com/superloglabsDevelopment13320 installsUpdated 21w ago
Repository

About otel-flask-style

A style skill for adding OpenTelemetry observability to Flask applications. It specifies native Flask instrumentation, initialization timing, module-scope telemetry objects, log bridging, and LLM token coverage.

Key features

  1. 01Native Flask instrumentation
  2. 02Initialize before serving traffic
  3. 03Module-scope tracers and meters
  4. 04OTLP log bridge requirements
  5. 05LLM token coverage guidance

Use cases

  1. 01Setting up observability in a Flask app
  2. 02Adding spans around helper operations
  3. 03Forwarding correlated Python logs
  4. 04Tracking LLM input and output tokens

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/superloglabs/skills --skill otel-flask-style

After installing, type/otel-flask-stylein Claude Code to confirm it loaded.

Details

From the project README

OTel Flask Style

Use native Flask instrumentation. Do not replace request handling with manual middleware just to create spans.

from flask import Flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor

def init_observability(app: Flask) -> bool:
    ...
    FlaskInstrumentor().instrument_app(app)
    return True

Keep FlaskInstrumentor().instrument_app(app) with the rest of the observability setup so the bootstrap is easy to reason about. If the generated token is not claimed yet because signup is still in progress, it is still okay to initialize providers; ingest may reject exports until the browser flow finishes.

Entrypoint

Initialize before serving user traffic.

app = Flask(__name__)
init_observability(app)

Bounded Work

Use module-scope OTel objects and decorators for helpers that auto-instrumented HTTP spans cannot see.

tracer = trace.get_tracer("mugline.api")
meter = metrics.get_meter("mugline.api")

@tracer.start_as_current_span("mug.recommend")
def recommend_mug(*, tenant_id: str, preference: str) -> dict[str, str]:
    span = trace.get_current_span()
    span.set_attribute("tenant.id", tenant_id)
    ...

Logs

For OTLP-forwarded stdlib logs, configure all of these:

  • LoggerProvider
  • set_logger_provider(logger_provider)
  • OTLPLogExporter
  • LoggingHandler
  • LoggingInstrumentor().instrument(...)

LLM Calls

LLM routes need token coverage:

  • llm.tokens.input
  • llm.tokens.output

Tag explicit token counters with tenant, provider, model, use case, call site, and outcome only when provider instrumentation cannot capture token usage. Do not add app-side LLM cost metrics or pricing tables; Superlog estimates cost centrally from provider/model/token data.

Comments

Markdown supported