Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

OpenTelemetry CLI Tools: Practical Query Alternatives

· 6 min read · Home Tech

In this article
  1. Why OpenTelemetry Has No Query CLI
  2. Backend-Specific CLIs
  3. Generic Tools: curl, jq, and gRPC Clients
  4. Query Languages and How They Differ
  5. Choosing the Right Tool for Your Workflow
  6. Common Pitfalls and Practical Tips
  7. Costs and Performance Considerations
  8. Frequently Asked Questions

OpenTelemetry is the standard for generating and collecting telemetry data, but it deliberately does not include a query language or CLI for exploring that data once it is stored. If you need to query observability data from the command line, you will pair the OpenTelemetry Collector with a dedicated backend and use that backend's CLI tools, or use generic data tools that speak the backend's protocol. This article covers the practical alternatives, from vendor CLIs like `tempo-cli` and `jaeger` to generic tools like `curl` and `jq`, and how to choose among them.

Why OpenTelemetry Has No Query CLI

OpenTelemetry is an instrumentation and data collection framework, not a storage or query engine. The specification defines the data model (traces, metrics, logs), the API/SDK for generating telemetry, and the OTLP protocol for exporting it. Once data leaves the SDK, it is the backend's job to store and serve it. The OpenTelemetry Collector can process and forward data, but it does not retain it or offer a query interface. So any CLI querying must target the backend where the data lives.

Backend-Specific CLIs

Most observability backends ship a CLI that talks to their own API. These are the most direct alternatives because they understand the data model and query language of that backend.

  • Jaeger: The Jaeger project includes the `jaeger` CLI with subcommands like `jaeger query` to fetch traces by service, operation, or trace ID. It works against Jaeger's query service (gRPC or HTTP).
  • Tempo: Grafana Tempo provides `tempo-cli`, which can query traces by ID and perform search queries against a Tempo instance. It is useful for debugging and for scripted trace retrieval.
  • Prometheus: For metrics, `promtool` is the official CLI. It can run PromQL queries against a Prometheus server (`promtool query instant` and `promtool query range`) and also validate rules and check configuration.
  • Loki: For logs, `logcli` is the official CLI for Grafana Loki. It supports LogQL queries, label discovery, and tailing logs from the terminal.
  • Cloud vendor CLIs: AWS, Azure, and GCP offer CLIs (e.g., `aws xray get-trace-summaries`, `az monitor app-insights query`, `gcloud logging read`) that query their respective managed observability services, which can ingest OTLP data.

Generic Tools: curl, jq, and gRPC Clients

If you prefer a tool-agnostic approach, you can use HTTP clients to hit the backend's REST API directly. Most backends expose a JSON-over-HTTP query API. For example, Prometheus has `/api/v1/query`, Loki has `/loki/api/v1/query_range`, and Jaeger has `/api/traces`. You can use `curl` to fetch data and `jq` to parse and filter the JSON response. This is ideal for scripting and for environments where you cannot install a vendor-specific CLI.

For gRPC-based backends (like Jaeger's query service), you can use `grpcurl` with the appropriate protobuf definitions. This is more complex but gives you full access to the API.

Query Languages and How They Differ

Each backend has its own query language, so the CLI you choose determines the syntax you must learn.

  • PromQL (Prometheus): A functional language for metrics, with selectors, range vectors, and functions like `rate()` and `histogram_quantile()`.
  • LogQL (Loki): Similar to PromQL but for logs, with label matchers, line filters, and aggregation operators.
  • TraceQL (Tempo): A purpose-built language for traces, allowing you to filter by span attributes, duration, and structure (e.g., `{ .http.status_code = 200 && duration > 1s }`).
  • Jaeger Query: Jaeger's API is more about lookup by service and trace ID, with limited filtering compared to TraceQL.

Choosing the Right Tool for Your Workflow

Your choice depends on your backend, your data type, and your use case. Here are some guidelines:

  • If you use Prometheus for metrics: Use `promtool` for ad-hoc queries and validation. It is reliable and widely documented.
  • If you use Loki for logs: Use `logcli` for searching and tailing logs. It supports `--since` and `--from` flags for time ranges.
  • If you use Tempo for traces: Use `tempo-cli` for trace ID lookups and TraceQL search. It can output JSON or pretty-printed traces.
  • If you use Jaeger: Use the `jaeger` CLI or `grpcurl` for direct API access.
  • If you use a cloud provider: Use their native CLI, which is often the only way to access the managed service.
  • If you need a generic solution: Use `curl` + `jq` to avoid vendor lock-in and to work with any REST API.

Common Pitfalls and Practical Tips

When using these CLIs, you will encounter a few recurring issues:

  • Authentication: Most backends require authentication (API tokens, basic auth, or mTLS). Check the CLI's environment variables or config file. For example, `promtool` reads `PROMETHEUS_URL` and `PROMETHEUS_TOKEN`.
  • Time ranges: Always specify a time range. Defaults often return the last 5 minutes, which may be empty if no data was sent. Use `--start` and `--end` flags or relative times like `--since=1h`.
  • Output format: Most CLIs default to human-readable output. For scripting, use `-o json` or `--format=json` to get structured data.
  • Escaping quotes: When using `curl` with complex JSON payloads, single-quote the entire URL or data to avoid shell expansion.
  • Rate limits: Managed services often rate-limit API calls. Batch your queries and avoid hammering the API in a loop.

Costs and Performance Considerations

Querying observability data can be expensive if you are not careful. Every query that scans a large time range or many labels consumes backend resources. For cloud-managed services, you may be billed per query or per amount of data scanned. To control costs, narrow your time range, use specific label matchers, and avoid `*` selectors unless necessary. Also, consider using the backend's caching or pre-aggregation features (like recording rules in Prometheus) to reduce query load.

Frequently Asked Questions

Can I query OpenTelemetry data directly with the Collector?

No. The Collector only processes and forwards data; it does not store or serve queries. You must send data to a backend (e.g., Prometheus, Tempo, Loki, Jaeger) and query that backend.

What is the difference between `promtool` and `promql`?

`promtool` is the CLI that executes PromQL queries against a Prometheus server. PromQL is the query language itself. You write PromQL expressions and pass them to `promtool query instant` or `promtool query range`.

Is there a universal CLI that works with any OpenTelemetry backend?

No universal CLI exists because each backend has its own storage engine and API. However, if all backends expose a REST API, you can use `curl` and `jq` as a generic solution, but you will need to adapt to each API's syntax.

How do I get a trace by ID with `tempo-cli`?

Use the `tempo-cli query trace ` command, specifying the Tempo endpoint with `--host` and `--port`. You can also use `--format=json` to get raw JSON output.

Can I use `jq` to filter traces from Jaeger's API?

Yes. Jaeger's HTTP API returns JSON, so you can pipe `curl` output to `jq` to extract fields like trace ID, service name, or duration. For example: `curl -s 'http://jaeger:16686/api/traces?service=my-service' | jq '.data[0].traceID'`.

What is TraceQL and why is it useful?

TraceQL is Tempo's query language for traces. It lets you search for traces based on span attributes, duration, and structural relationships. It is more powerful than simple ID lookups and is useful for finding traces that match specific conditions, such as errors or slow operations.