Worker used to collect viewers count from Twitch streams and export them as OpenTelemetry metrics to SigNoz (or any OTLP-compatible backend).
Metrics output is selected by --otel-exporter-endpoint: set it to export over OTLP/HTTP, or leave it unset to print metrics to the console (useful for local development).
The project is organized into four modules:
config— CLI and environment configuration (parsed withclap)crawler— Twitch stream fetching and metric recording logictelemetry— OpenTelemetry meter provider initialization (OTLP/HTTP or stdout)main— Application entry point, measurement loop, and token management
Metrics exported:
twitch.viewers(gauge) — Number of viewers on a Twitch stream
Metric attributes:
- Custom labels via
OTEL_ADDITIONAL_LABELS(format:key1=value1,key2=value2) stream_idgame_idgame_nameuser_iduser_name
Rust version: 1.97+
cargo build --releaseParameters can be passed to binary by environment variables or as command parameters.
twitch-crawler -h
Usage: twitch-crawler [OPTIONS] --twitch-client-id <TWITCH_CLIENT_ID> --twitch-client-secret <TWITCH_CLIENT_SECRET>
Options:
--otel-additional-labels <OTEL_ADDITIONAL_LABELS>
Extra labels added to every record, format: key1=value1,key2=value2 [env: OTEL_ADDITIONAL_LABELS=] [default: ""]
--twitch-client-id <TWITCH_CLIENT_ID>
Twitch client id [env: TWITCH_CLIENT_ID=]
--twitch-client-secret <TWITCH_CLIENT_SECRET>
Twitch client secret [env: TWITCH_CLIENT_SECRET=]
--game-ids <GAME_IDS>
Filter streams on game ids (Max value: 100) [env: GAME_IDS=]
--languages <LANGUAGES>
Filter streams on languages (Max value: 100) [env: LANGUAGES=]
--user-logins <USER_LOGINS>
Filter streams on user logins [env: USER_LOGINS=]
--minimum-viewers <MINIMUM_VIEWERS>
Keep only datapoint viewers count superior to the value [env: MINIMUM_VIEWERS=] [default: 0]
--interval <INTERVAL>
Interval of seconds between each measurement [env: INTERVAL=] [default: 15]
--otel-exporter-endpoint <OTEL_EXPORTER_ENDPOINT>
OTLP metrics endpoint. When set, metrics are exported to this endpoint; when unset, metrics are printed to the console [env: OTEL_EXPORTER_ENDPOINT=]
-h, --help
Print help information
-V, --version
Print version informationWe use env_logger crate to handle logging, if you need to have debug logs you can add environment variable RUST_LOG=twitch_crawler=debug.
To send metrics to SigNoz Cloud, set the following environment variables:
export OTEL_EXPORTER_ENDPOINT="https://ingest.<region>.signoz.cloud:443/v1/metrics"
export OTEL_EXPORTER_OTLP_METRICS_HEADERS="signoz-ingestion-key=<your-ingestion-key>"
export OTEL_SERVICE_NAME="twitch-crawler"export TWITCH_CLIENT_ID=xxx
export TWITCH_CLIENT_SECRET=xxx
export OTEL_EXPORTER_ENDPOINT=https://ingest.us.signoz.cloud:443/v1/metrics
export OTEL_EXPORTER_OTLP_METRICS_HEADERS="signoz-ingestion-key=xxx"
docker-compose up -d- Warp10 removed — metrics are no longer pushed to Warp10; OpenTelemetry with OTLP/HTTP export replaces it entirely.
- Crate migration — upgraded from
twitch_api2/twitch_oauth2totwitch_api0.8 (unified crate). - OpenTelemetry stack — added
opentelemetry0.32,opentelemetry_sdk,opentelemetry-otlp, andopentelemetry-stdoutfor metrics instrumentation. - Modular codebase — logic split into
config,crawler, andtelemetrymodules instead of a singlemain.rs. --event-nameremoved — replaced by the generic--otel-additional-labelsflag to add arbitrary key=value labels.- Proper error handling — uses
anyhow::Resultthroughout instead ofexpect()/panic!. - Docker image — base image updated to
rust:1.97-slim-bookworm/debian:bookworm-slim.