Metrics — go-discord-caller¶
All telemetry is emitted via OpenTelemetry (OTLP gRPC) — there is no direct
Prometheus client. Instruments are created from a single meter in
internal/telemetry/ and exported to the OTLP endpoint set by OTEL_ENDPOINT
(empty disables telemetry — see internal/config/config.go). The collector /
Alloy / Prometheus OTLP receiver translates each OTel instrument into one or
more Prometheus series.
This file lists every instrument by its OTel name (the dotted name in code) alongside the Prometheus series name produced by the default OTLP→Prometheus translation.
OTel → Prometheus naming rules¶
The Prometheus names below assume the default OTLP translation (Prometheus
native OTLP receiver / OpenTelemetry Collector prometheus exporter, with unit
and type suffixes enabled — the defaults):
| OTel | Prometheus |
|---|---|
. and other illegal chars |
_ |
unit ms |
_milliseconds suffix |
unit s |
_seconds suffix |
| monotonic counter | _total suffix (not doubled if the name already ends in total) |
Float64Histogram |
_bucket / _sum / _count series |
UpDownCounter, ObservableUpDownCounter, Gauge, ObservableGauge |
gauge, no suffix |
Names vary if the exporter is configured with
without_units/without_type_suffix, or if Prometheus is run with--enable-feature=otlp-deltatocumulativestyle flags. The collector also adds atarget_infoseries andotel_scope_*labels. Tune accordingly.
All instruments carry the resource attribute service.name="go-discord-caller".
🤖 Bot / Discord entities (internal/telemetry/bot_metrics.go)¶
| OTel instrument | Type | Prometheus series | Attributes | Description |
|---|---|---|---|---|
gdc.discord.guild |
ObservableGauge | gdc_discord_guild |
guild_id, guild_name |
One series per guild the owner bot is in; the value is the number of bots (the owner and its registered speakers) in it, so at least 1. Dashboards join on it for guild_name. From internal/manager/service.go. |
gdc.voice.callers |
ObservableUpDownCounter | gdc_voice_callers |
guild_id, channel_id |
Non-bot users with the caller role currently in a voice channel the guild's active raid captures — the owner's channel on a host raid or a guest raid in a caller mode, plus the speakers' channels in modes where speakers capture — recounted from the owner bot's cache on each collection; channels with none are absent. From internal/manager/service.go. |
gdc.command.started.total |
Counter | gdc_command_started_total |
command, guild_id ⚠️ |
Slash command invocations entering the handler. Recorded before the handler runs, so a handler that never returns is still counted. From internal/bot/middleware.go. |
gdc.command.duration |
Histogram (s) |
gdc_command_duration_seconds (_bucket/_sum/_count) |
command, guild_id ⚠️ |
Slash command execution duration. Buckets (s): 1, 3, 5, with 3 s being Discord's acknowledgement deadline. _count is the number of invocations that completed; a sustained gdc_command_started_total - gdc_command_duration_seconds_count means handlers went in and never came out. From internal/bot/middleware.go. |
⚠️ The two
gdc.command.*instruments label the guild asguild.id(dotted) in code — seeRecordCommand. The OTLP→Prometheus translation rewrites this toguild_id, so dashboards still queryguild_id, but the attribute is inconsistent with theguild_idused by every other instrument. Worth normalising in code.
🛰️ Speaker pool (internal/telemetry/pool_metrics.go)¶
Emitted from internal/pool/service.go (observable gauges via a registered
callback; counters inline in the watchdog). The verification labels and the
server count on gdc.discord.bot come from each bot's own application, fetched
at startup and then hourly; a failed fetch keeps the last known value.
| OTel instrument | Type | Prometheus series | Attributes | Description |
|---|---|---|---|---|
gdc.discord.bot |
ObservableGauge | gdc_discord_bot |
bot_id, bot_name, verified, verification_blocked, members_intent |
One series per bot, owner and speakers. The value is the approximate server count, as Discord counts it against the 100-server limit an unverified bot cannot pass; 0 until Discord reports one. verified and verification_blocked (blocked because of unusual growth) are true/false; members_intent is approved, limited (switched on without review, allowed until the bot reaches 10,000 users) or off. The three are absent until the first fetch. |
gdc.pool.bots.total |
ObservableGauge | gdc_pool_bots_total |
— | Total speaker bots registered in the pool. (Gauge — not a counter despite the total suffix.) |
gdc.pool.bots.connected |
ObservableGauge | gdc_pool_bots_connected |
— | Speaker bots with a healthy gateway connection. |
gdc.bot.gateway.latency |
ObservableGauge (ms) |
gdc_bot_gateway_latency_milliseconds |
bot_id |
Gateway WebSocket heartbeat RTT per bot. 0 until first ACK. See docs/LATENCY.md — this is the control channel, not audio latency. |
gdc.voice.server.region |
ObservableGauge | gdc_voice_server_region |
guild_id, bot_id, region |
Info gauge (always 1) for the Discord voice region a bot's connection landed on. Present only while the bot is in voice. |
gdc.voice.server.latency |
ObservableGauge (ms) |
gdc_voice_server_latency_milliseconds |
guild_id, bot_id, region |
Voice websocket heartbeat RTT to that voice server — the network leg audio takes, unlike gdc.bot.gateway.latency. Absent until the first heartbeat ACK. |
gdc.pool.reconnect.attempts.total |
Counter | gdc_pool_reconnect_attempts_total |
bot_id |
Watchdog gateway reconnect attempts. |
gdc.pool.reconnect.failures.total |
Counter | gdc_pool_reconnect_failures_total |
bot_id |
Watchdog gateway reconnect failures. |
gdc.gateway.ready.total |
Counter | gdc_gateway_ready_total |
bot_id |
Gateway READY events of the owner bot. Each follows an IDENTIFY, and Discord resets a bot's token after 1000 in a day: alert on increase(gdc_gateway_ready_total[10m]) > 10. |
🏰 Session lifecycle & fanout (internal/telemetry/session_metrics.go)¶
Emitted from internal/manager/voice_raid.go (start/stop) and the auto-router
pipelines in internal/manager/pipeline/ (route transitions); frame drops from
the opus pipeline via FrameDropper.
| OTel instrument | Type | Prometheus series | Attributes | Description |
|---|---|---|---|---|
gdc.voice.session.start.total |
Counter | gdc_voice_session_start_total |
guild_id |
Voice raid starts. |
gdc.voice.bot.join.duration |
Histogram (s) |
gdc_voice_bot_join_duration_seconds (_bucket/_sum/_count) |
guild_id, bot_kind, outcome |
Time from the start of a raid (/start, or joining one by code) until each bot is in its voice channel — outcome="joined" — or until its join gave up ("failed"). bot_kind is owner or speaker. The owner joins after the speakers, so its time includes theirs. Buckets (s): 1, 3, 5, 10, 15. |
gdc.voice.session.stop.total |
Counter | gdc_voice_session_stop_total |
guild_id |
Voice raid stops. |
gdc.session.speakers |
Gauge | gdc_session_speakers |
guild_id |
Speakers (pool speaker bots plus the owner bot, if it joined) in the active raid; reset to 0 on stop. |
gdc.session.mode |
Gauge | gdc_session_mode |
guild_id, mode |
1 while the guild's active raid runs in the labelled mode, 0 once it ends. mode: one_caller / guild_caller / ally_listener / ally_caller / one_many_guild_caller / one_many_ally_caller. Summed over mode it is the guild's number of active raids. |
gdc.fanout.frames.dropped.total |
Counter | gdc_fanout_frames_dropped_total |
guild_id, path, bot_id |
Opus frames dropped on full channels, per destination buffer. path: mixer / direct / channel_mixer / relay_bridge / provider / receiver. bot_id is the bot whose output queue was full; set on direct and channel_mixer only. |
gdc.opus.source.frames.lost.total |
Counter | gdc_opus_source_frames_lost_total |
guild_id |
Frames fed through the voice receiver that evicted an older frame from at least one mixer input, counted once per frame; relay-fed inputs are not included. path="mixer" above counts each destination's eviction separately, so with several destination channels it overstates how much speech was lost; use this one for that. |
gdc.session.route_transitions.total |
Counter | gdc_session_route_transitions_total |
guild_id, from, to |
Auto-router source-mode transitions. from/to: off / copy / mix. |
🎙️ Opus / mixer timing (internal/telemetry/opus_metrics.go)¶
All histograms, attribute guild_id; unit ms unless noted. Recorded on the hot path via a
pre-baked OpusRecorder (Metrics.ForGuild) — zero-alloc per frame.
| OTel instrument | Prometheus series (_bucket/_sum/_count) |
Buckets (ms) | Emitter | Description |
|---|---|---|---|---|
gdc.opus.receive.duration |
gdc_opus_receive_duration_milliseconds |
0.5, 1, 2, 5, 12, 20 | internal/opus/voice_receiver.go |
ReceiveOpusFrame execution time (excludes channel-wait). |
gdc.opus.provide.duration |
gdc_opus_provide_duration_milliseconds |
0.5, 1, 2, 5, 12, 20 | internal/opus/voice_provider.go |
ProvideOpusFrame drain+return time (excludes frame-wait). |
gdc.mixer.tick.duration |
gdc_mixer_tick_duration_milliseconds |
0.5, 1, 2, 5, 10, 20 | internal/opus/mixer.go |
Mixer tick processing time. Not recorded while the mixer is paused. |
gdc.mixer.tick.lateness |
gdc_mixer_tick_lateness_milliseconds |
0.5, 1, 2, 5, 10, 20, 40, 80 | internal/opus/mixer.go |
How far past its 20 ms boundary a mixer tick fired. Scheduler or GC stalls show up here; they are what push a queued frame past the 60 ms cap in gdc.mixer.pipeline.latency. Not recorded while the mixer is paused, when it ticks every 200 ms instead. |
gdc.opus.copy.queue_depth |
gdc_opus_copy_queue_depth |
0, 1, 2, 3 (frames) | internal/opus/voice_receiver.go |
Copy mode only (a single caller, mixer bypassed): frames already queued ahead of a copied frame in a speaker's output channel. disgo drains one frame per 20 ms, so 0 / 1 / 2 / 3 ahead ≈ under 20 / 20–40 / 40–60 / 60+ ms of wait. A frame that finds the queue full is dropped (path="direct") and not recorded here. Integer histogram, unit {frame}, not ms. |
gdc.opus.receive.interval |
gdc_opus_receive_interval_milliseconds |
2, 5, 10, 15, 18, 22, 25, 30, 40, 60 | internal/opus/voice_receiver.go |
Time between two consecutive frames (by RTP timestamp) from the same user as they reach the receiver. Even delivery is ~20 ms; a clump of frames lands near 0, a frame held back at 40+. Gaps across a pause in speech are not recorded. With gdc.mixer.tick.lateness clean, clumps here come from delivery rather than our own scheduling. |
gdc.opus.source.depth |
gdc_opus_source_depth |
0, 1, 2, 3, 4, 5 (frames) | internal/opus/voice_receiver.go |
Mix mode: frames already waiting in a user's mixer input when a new frame is fed. An input holds 3 frames and grows by one per eviction, up to 6, while its bursts keep overflowing it, then shrinks back after ~10 s without filling; so a depth of 3+ is a grown input, and evictions are gdc.opus.source.frames.lost.total. A distribution sitting at 1–2 is a backlog that does not drain while the user keeps talking. Integer histogram, unit {frame}. |
gdc.mixer.pipeline.latency |
gdc_mixer_pipeline_latency_milliseconds |
10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 120 | internal/opus/mixer.go |
Latency from Discord receive to the mixer tick that consumes the frame. Floor ~20 ms (tick period), ceiling 60 ms (audioSourceCap), up to 120 ms for an input grown under sustained jitter. See docs/LATENCY.md. |
🔐 DAVE end-to-end encryption (internal/telemetry/dave_metrics.go)¶
Counted in memory by internal/dave and exported once per collection, so the
per-frame path stays an atomic increment. No sender identity is exported:
decrypt health is reported as a count of senders per bucket.
| OTel instrument | Type | Prometheus series | Attributes | Description |
|---|---|---|---|---|
gdc.dave.decrypt.total |
ObservableCounter | gdc_dave_decrypt_total |
bot_user_id, outcome (success/passthrough/dropped/failure), reason |
Inbound frame decryption outcomes, summed over senders. |
gdc.dave.decrypt.senders |
ObservableGauge | gdc_dave_decrypt_senders |
bot_user_id, health (clean/partial/failing) |
Distinct senders per decrypt-health bucket. One failing sender among clean ones points at that sender; partial everywhere points at the session. |
gdc.dave.encrypt.total |
ObservableCounter | gdc_dave_encrypt_total |
bot_user_id, outcome (success/failure/unsent_alone), reason |
Outbound frame encryption outcomes. unsent_alone counts frames discarded because the bot is alone in its channel (never ready, nobody listening); it is not a failure and does not count toward a rejoin. A bot whose encryptor lost its key ratchet fails every frame (reason="missing_key_ratchet") and is silent in its channel while looking connected; after ~10 s of failures it rejoins its channel. |
gdc.dave.decrypt.duration |
Histogram | gdc_dave_decrypt_duration_milliseconds |
bot_user_id |
How long one frame decryption took. Frames from every speaker are decrypted in turn on one receive goroutine, so a slow decrypt delays them all. Buckets (ms): 0.1, 0.5, 2, 10. Compare its tail with gdc_opus_receive_interval_milliseconds to tell a stall in decryption from frames that were already late when they arrived. |
reason is none on success, otherwise one of missing_key_ratchet,
invalid_nonce, missing_cryptor, decrypt_failure, encrypt_failure,
too_many_attempts or other.
🖥️ Process & Go runtime (internal/telemetry/process_metrics.go)¶
The process's own resource use, for capacity planning against the container limit. Compare gdc_process_memory_usage_bytes with go_memory_used_bytes: the gap is memory libdave and libopus allocate outside the Go heap, which GOMEMLIMIT does not cover.
| OTel instrument | Type | Prometheus series | Attributes | Description |
|---|---|---|---|---|
gdc.build.info |
ObservableGauge | gdc_build_info |
version, revision, go_version, libdave_version |
Info gauge (always 1) for the running build. version is the release tag stamped by the Dockerfile (dev for local builds); revision is the short commit, -dirty when built with uncommitted changes. Also sent as service.version on every signal. |
gdc.process.cpu.time |
ObservableCounter (s) |
gdc_process_cpu_time_seconds_total |
— | CPU time consumed by the process, user plus system. rate() of it is the fraction of one core in use. |
gdc.process.memory.usage |
ObservableGauge (By) |
gdc_process_memory_usage_bytes |
— | Resident set size, including C allocations. Linux only — absent elsewhere. |
gdc.gc.pause.duration |
Histogram (ms) |
gdc_gc_pause_duration_milliseconds_* |
— | Stop-the-world GC pauses, recorded when the runtime metrics are sampled. Buckets (0.25, 1, 5, 20 ms) read as fine, watch, warn and a missed 20 ms mixer tick; compare with gdc.mixer.tick.lateness. |
gdc.sched.latency.over |
ObservableCounter | gdc_sched_latency_over_total |
over_ms (0, 1, 5, 20) |
Goroutine schedulings that waited at least over_ms for a CPU; 0 counts all of them. rate(over_ms="5") / rate(over_ms="0") is the share of schedulings delayed by 5 ms or more — a late mixer tick that coincides with a rise is CPU starvation, not slow work in the tick. |
go.memory.used, go.memory.limit, go.memory.gc.goal, go.goroutine.count, … |
ObservableGauge / Counter | go_memory_used_bytes, go_memory_limit_bytes, go_goroutine_count, … |
go.memory.type on go.memory.used |
Go runtime metrics from go.opentelemetry.io/contrib/instrumentation/runtime, sampled at most every 15 s. |
Implementation¶
Instruments are defined in internal/telemetry/, split by subsystem:
bot_metrics.go, pool_metrics.go, session_metrics.go, opus_metrics.go,
dave_metrics.go, process_metrics.go.
metrics.go wires them together (NewMetrics); setup.go configures the OTLP
exporters (traces, metrics, logs) and the periodic metric reader (15 s interval).
Per-guild recorders are obtained via Metrics.ForGuild(ctx, guildID)
(guild_metrics.go), which bakes the guild_id attribute once and returns a
reusable GuildMetrics value — keeping the hot path allocation-free.
Example PromQL¶
# p99 mixer pipeline latency per guild (ms)
histogram_quantile(0.99,
sum by (guild_id, le) (rate(gdc_mixer_pipeline_latency_milliseconds_bucket[5m])))
# frame drop rate by pipeline stage
sum by (path) (rate(gdc_fanout_frames_dropped_total[5m]))
# which speaker bot is losing frames
sum by (bot_id) (rate(gdc_fanout_frames_dropped_total{path=~"direct|channel_mixer"}[5m]))
# speaker bots connected vs registered
gdc_pool_bots_connected / gdc_pool_bots_total
# bots that cannot encrypt outbound audio (silent while connected)
sum by (bot_user_id) (rate(gdc_dave_encrypt_total{outcome="failure"}[5m])) > 0
# active voice raids
sum(gdc_session_mode)
Traces: session startup phases¶
/start takes seconds before any audio flows (measured in production: ~0.8–1.9 s
with 2 speakers, ~3 s with 5, ~3.2–4.1 s with 10), and the work is a chain of
Discord round trips. voice.session / voice.session.guest spans last as long
as the raid, so the startup cost has its own child span with one child per round
trip. startPhase (internal/manager/trace.go) opens them.
voice.session (whole raid)
└── voice.session.setup (/start → first frame flowing)
├── voice.speakers.setup speaker.candidates, speaker.joined, capture
│ └── voice.bot.attach bot.id, bot.kind=speaker (one per speaker, concurrent)
│ ├── voice.conn.open voice handshake through SessionDescription
│ ├── voice.members.prefetch user.count (capture modes only)
│ ├── voice.conn.apply provider/receiver wiring + SetSpeaking op
│ └── voice.deaf.reconcile deaf.want, deaf.cached
├── voice.bot.attach bot.kind=owner (runs after every speaker)
│ └── … same four children
└── voice.pipeline.build local graph construction, expected ~0
What to read off a trace:
voice.bot.attach{bot.kind=owner}starting only after the last speaker's attach ends is the serialized owner handshake.voice.deaf.reconcilespans withdeaf.cached=falsestacking one after another are the per-guild REST bucket serializing member PATCHes — disgo holds the bucket mutex across each request.voice.conn.openis the irreducible part: op4 → voice server update → WSS+TLS → identify/ready → UDP discovery → session description.
Everything is sampled (default ParentBased(AlwaysSample)). The parent
voice.session span only exports when the raid ends, so a trace looks
incomplete while a raid is live — the startup children are already there.