dcd8de8b00
- pkg/telemetry: shared OTel provider bootstrap (none/stdout/otlp + W3C
propagators + Go runtime metrics); backend/internal/telemetry becomes a thin
facade keeping its gin middleware.
- Telemetry parity: gateway and the Telegram connector gain telemetry runtimes
and config (GATEWAY_/TELEGRAM_ SERVICE_NAME + OTEL_*); otelgrpc instruments the
backend push server, the gateway's backend+connector clients and the connector
server. Default exporter stays none (collector/dashboards are Stage 14).
- Operational metrics (variant attribute on game-scoped ones): game_replay_duration,
game_move_validate_duration, games_started_total, games_abandoned_total,
game_cache_active, chat_messages_total{kind}, gateway edge_request_duration.
Wired via the SetMetrics setter pattern (default no-op meter).
- TODO-3: account.GuestReaper deletes guests with no game seat past
BACKEND_GUEST_RETENTION (default 30d, swept every BACKEND_GUEST_REAP_INTERVAL).
- Tests: pkg/telemetry exporter selection; game/social/edge metric recording via
a manual reader; config (otlp accepted, guest knobs); inttest guest reaper.
- Docs: PLAN.md re-scopes Stage 12 and adds Stage 13 (alphabet-on-wire) + Stage 14
(CI/deploy) with the agreed dictionary-versioning resolution; ARCHITECTURE 11/13,
TESTING, the three READMEs and FUNCTIONAL(+ru) updated.
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package telemetry
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// TestConfigValidate covers the supported and rejected exporter selections.
|
|
func TestConfigValidate(t *testing.T) {
|
|
if err := DefaultConfig().Validate(); err != nil {
|
|
t.Fatalf("default config must be valid: %v", err)
|
|
}
|
|
|
|
otlp := DefaultConfig()
|
|
otlp.TracesExporter = ExporterOTLP
|
|
if err := otlp.Validate(); err != nil {
|
|
t.Errorf("otlp exporter must be accepted: %v", err)
|
|
}
|
|
|
|
bad := DefaultConfig()
|
|
bad.MetricsExporter = "prometheus"
|
|
if err := bad.Validate(); err == nil {
|
|
t.Error("unsupported exporter must be rejected")
|
|
}
|
|
|
|
noName := DefaultConfig()
|
|
noName.ServiceName = ""
|
|
if err := noName.Validate(); err == nil {
|
|
t.Error("empty service name must be rejected")
|
|
}
|
|
}
|
|
|
|
// TestNewNoneAndShutdown builds the providers with the none exporter and shuts
|
|
// them down.
|
|
func TestNewNoneAndShutdown(t *testing.T) {
|
|
rt, err := New(context.Background(), DefaultConfig())
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if rt.TracerProvider() == nil {
|
|
t.Error("TracerProvider must not be nil")
|
|
}
|
|
if rt.MeterProvider() == nil {
|
|
t.Error("MeterProvider must not be nil")
|
|
}
|
|
if err := rt.Shutdown(context.Background()); err != nil {
|
|
t.Errorf("Shutdown: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestNewStdoutTraces builds the providers with the stdout trace exporter; no
|
|
// spans are recorded, so shutdown flushes nothing to stdout.
|
|
func TestNewStdoutTraces(t *testing.T) {
|
|
cfg := DefaultConfig()
|
|
cfg.TracesExporter = ExporterStdout
|
|
rt, err := New(context.Background(), cfg)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if err := rt.Shutdown(context.Background()); err != nil {
|
|
t.Errorf("Shutdown: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestTraceFieldsFromContextEmpty returns no fields without an active span.
|
|
func TestTraceFieldsFromContextEmpty(t *testing.T) {
|
|
if TraceFieldsFromContext(context.Background()) != nil {
|
|
t.Error("expected nil fields without an active span")
|
|
}
|
|
var nilCtx context.Context
|
|
if TraceFieldsFromContext(nilCtx) != nil {
|
|
t.Error("expected nil fields for a nil context")
|
|
}
|
|
}
|
|
|
|
// TestNilRuntime checks the nil-receiver fallbacks used before initialisation.
|
|
func TestNilRuntime(t *testing.T) {
|
|
var rt *Runtime
|
|
if rt.TracerProvider() == nil {
|
|
t.Error("nil runtime must fall back to the global tracer provider")
|
|
}
|
|
if rt.MeterProvider() == nil {
|
|
t.Error("nil runtime must fall back to the global meter provider")
|
|
}
|
|
if err := rt.Shutdown(context.Background()); err != nil {
|
|
t.Errorf("nil runtime Shutdown: %v", err)
|
|
}
|
|
}
|