Home / Reference

obskitpy guide

CLI and library reference. For a step-by-step walkthrough, see the quick start.

The CLI output is currently in Brazilian Portuguese. The flags, commands and file names below are the real ones.

CLI

Every command accepts --dir FOLDER (default: observability) and must be run from the project root.

Command What it does
obskitpy init Wizard: creates observability/ (stack and dashboard) and, if you want, starts everything and runs an example.
obskitpy up Starts the stack, shows progress, waits until it is healthy and applies the dashboard (Kibana). Can be repeated at will.
obskitpy down [-v] Brings the stack down. -v also deletes the data (the Elasticsearch volume).
obskitpy status A table of the containers (state and ports) and the dashboard links.
obskitpy open [--ui kibana\|dash-obskitpy] [--realtime] Opens the dashboard in the browser (default: dash-obskitpy if it exists, otherwise Kibana). --realtime opens the dash already live (logs every 1 s).
obskitpy dash update Updates the dash-obskitpy files (observability/dash/) to the installed package's version; keeps yours as .bak.
obskitpy run [--] COMMAND... Runs your program already pointed at the stack (e.g. obskitpy run python app.py). If the stack is stopped, it starts it first. With no command, it runs obskitpy_demo.py.
obskitpy portal enable Turns on the integrations and automations portal (PostgreSQL + API + Integrations, Automations and Incidents tabs in the dash). See Portal.
obskitpy portal password Generates a new password for the portal administrator.
obskitpy doctor Diagnoses Docker, Compose v2, Docker memory and ports.
obskitpy login [--url URL] · logout · whoami Signs in to the portal and stores an API token on this computer (~/.config/obskitpy/credentials.json).
obskitpy robot create\|list\|get\|apply\|enable\|disable\|archive\|run Registers and manages robots from the terminal. See Robots, runs and agents.
obskitpy runs list\|logs\|cancel Inspects and controls robot runs.
obskitpy agent run A worker that executes robots (also available as a container: Azure).
obskitpy dashboard apply Imports observability/dashboard.ndjson into Kibana (overwrites objects with the same id).
obskitpy dashboard export Writes the dashboard as it is in Kibana right now to dashboard.ndjson.
obskitpy --version Shows the version.

The CLI solves things instead of failing

The goal is not to stop at an error when there is a way out. What is safe happens automatically; anything that installs or starts something asks for your confirmation.

Situation What obskitpy does
docker compose does not exist, but there is a docker-compose binary Uses the binary by itself.
No Compose v2 (macOS with Homebrew) Offers brew install docker-compose and carries on.
Docker does not answer, but Colima is up Points DOCKER_HOST at Colima's socket.
Colima is stopped Offers to start it (colima start).
docker-credential-desktop not found Retries with a Docker configuration without the credential helper.
A port is busy on startup Picks the next free one, writes it to .env and tries again (one port at a time, if needed).
A shortcut or a typo in the command (start, ps, upp) Understands it (up, status...) and tells you. For the others, suggests: "Você quis dizer…?" ("Did you mean…?").
An obskitpy stack is already running init asks whether this automation should join it (same dashboard; in the dash you pick the project).
A folder without observability/ Offers to run the init wizard right away.
An otel-collector-config.yaml from an old version On up, updates it (keeps a .bak) and recreates the Collector so it sends data every 1 s.
Dash files from an old version up warns you; obskitpy dash update updates them.
init in a folder that already has obskitpy Asks: start as is, reconfigure (keeps a copy in observability.bak/) or cancel.
Collector still starting / data still being indexed Waits for the Collector to accept data and for the data to become queryable before running the example or finishing run.
obskitpy not on the PATH The hints already show up as uv run obskitpy ... (or python -m obskitpy ...).

The output is colored, with spinners and boxes. It respects NO_COLOR and turns into plain text in pipes and CI (use FORCE_COLOR=1 to force colors).

obskitpy init

With an interactive terminal, it asks questions (and uses the defaults where you press Enter). Without a terminal, or with --yes, it asks nothing.

Option Default Description
--service NAME current folder name Service name (lowercase letters, numbers and -). Identifies your data.
--local {kibana,dash-obskitpy,both} asks; without a terminal, kibana Where to view the logs (both; ambos from 0.x still works). See dash-obskitpy.
-y, --yes — Ask nothing (uses the defaults and whatever came by flag).
--up — Starts the stack when finished.
--demo — With --up: generates obskitpy_demo.py and runs it, so there is data right away.
--es-port 9200 Local Elasticsearch port.
--kibana-port 5601 Local Kibana port (if you use Kibana).
--dash-port 8600 Local dash-obskitpy port (if you use it).
--otlp-grpc-port 4317 Local Collector port (gRPC), the one the library uses.
--otlp-http-port 4318 Local Collector port (HTTP).
--join [STACK] — Uses an obskitpy stack that is already running (by its service name; without a value, the first one found) instead of creating another.
--standalone — Does not look for running stacks: creates a stack of its own.
--force — Recreates an existing installation (the previous one is kept in observability.bak/).

Ports you do not set that turn out to be busy are swapped automatically for the next free one (init tells you). In an already initialized folder, the interactive terminal asks what to do; without a terminal, it asks for --force.

What init creates

observability/
├── .env                        # service, chosen interface, compose profiles and ports
├── docker-compose.yml          # Elasticsearch 8.17, Collector and, depending on --local, Kibana 8.17 and/or the dash
├── otel-collector-config.yaml  # receives OTLP and writes to Elasticsearch
├── dashboard.ndjson            # (Kibana) dashboard in "saved objects" format
├── nginx.conf                  # (dash-obskitpy) serves the dash and gives read-only access to Elasticsearch
└── dash/                       # (dash-obskitpy) the dashboard: HTML, CSS, JS and logo

Version everything in git. .env holds only the name, interface and ports, no secrets.

Library

import obskitpy

obskitpy.setup(service_name, *, environment=None, version="0.0.0", flush_interval_ms=1_000, metrics_interval_ms=5_000, instrument_requests=True)

Configures traces, metrics and logs and returns a shutdown() function. Call it once, at the start of the program.

Parameter Description
service_name Becomes service.name; it must equal OBSKITPY_SERVICE in .env.
environment deployment.environment (default: the APP_ENV variable, or local).
version service.version.
flush_interval_ms How often logs and traces are sent (default 1 s, for the dash's Realtime).
metrics_interval_ms Metrics send interval (default 5 s).
instrument_requests Creates a span for every requests.get/post/... (needs the obskitpy[requests] extra; ignored without it).

What happens under the hood:

Always call shutdown() when finished (or in a finally); without it, the last data may be lost.

@obskitpy.traced(name=None)

A decorator that opens a span per call. If the function raises an exception, it is recorded on the span (which gets status Error) and re-raised. The default name is module.function.

obskitpy.tracer(name="app")

Returns an OpenTelemetry tracer for manual spans and attributes:

tracer = obskitpy.tracer("orders")
with tracer.start_as_current_span("process_order", attributes={"order.id": 42}) as span:
    ...
    span.set_attribute("order.items", 3)

obskitpy.meter(name="app")

Returns an OpenTelemetry meter for business metrics:

meter = obskitpy.meter("orders")
processed = meter.create_counter("orders.processed", unit="{order}")
duration = meter.create_histogram("orders.duration", unit="ms")

processed.add(1, {"status": "success"})
duration.record(123.4, {"status": "success"})

In Elasticsearch the counter shows up as metrics.orders.processed and the attributes as attributes.status (use those fields when building panels).

obskitpy.error_chain(exc) and obskitpy.error_attributes(exc)

Used internally; handy if you want to build the error log by hand. error_attributes returns error.type, error.origin (file:function:line of the point where the error was born) and error.chain (JSON with one item per traceback frame).

Environment variables

Variable Default Effect
OTEL_EXPORTER_OTLP_ENDPOINT http://localhost:4317 Where to send the data.
OTEL_EXPORTER_OTLP_PROTOCOL grpc http/protobuf sends over HTTP (Collector port 4318): use it behind proxies, tunnels and serverless platforms that refuse gRPC.
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE delta Do not change it to cumulative (histograms would be dropped).
APP_ENV local Value of deployment.environment.

Where the data lives in Elasticsearch

Signal Data stream Useful fields
Logs logs-generic.otel-default body.text, severity_text, attributes.*, trace_id, resource.attributes.service.name
Traces traces-generic.otel-default name, duration (ns), parent_span_id (absent on root spans), status.code, trace_id
Metrics metrics-generic.otel-default metrics.<name>, attributes.*, resource.attributes.service.name

All services pointing at the same stack share these data streams; service.name separates them. Spans that record an exception also produce event documents without a name, which is why the dashboard queries use name : * when counting root spans.

✎ Edit this page on GitHub