selfobs

package
v0.9.611 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package selfobs wires Coremetry's own OTel SDK (traces + metrics) so the running binary emits telemetry about itself — appears on /services alongside the demo + production traffic it observes.

v0.6.42 — operator-reported gap: the frontend already shipped with @opentelemetry/sdk-trace-web (lib/otel.ts) and stamped a W3C `traceparent` on every fetch, but the Go backend had no SDK on the receiving side, so the trace context died at the HTTP boundary and `coremetry-api` / `coremetry-ingest` / `coremetry-worker` / `coremetry-mcp` never showed up as services.

Design choices:

  • Opt-in via env. COREMETRY_SELF_OBS_OTLP_ENDPOINT empty → SDK not initialised; binary behaves exactly as before. Set it to `localhost:4317` (the docker-compose otel-collector) to turn on self-observability.

  • One TracerProvider + one MeterProvider per process. They are stored on the global otel package so otelhttp / otelgrpc / chstore.tracedConn pick them up without explicit plumbing.

  • Resource attributes derived from runMode so each role surfaces as a distinct `service.name` on /services:

  • all: coremetry-monolithic

  • api: coremetry-api

  • ingest: coremetry-ingest

  • worker: coremetry-worker `service.instance.id` is the hostname (so multiple replicas can be told apart on /services rows).

  • Sampling default: ParentBased(TraceIDRatioBased(0.1)). If the frontend's traceparent indicates "sampled", we follow; root spans the backend creates itself get sampled at 10%. Operator can override via COREMETRY_SELF_OBS_SAMPLE_RATE.

  • Self-loop guard: this package is NEVER imported by code that runs inside the OTLP receiver paths (`internal/otlp/*`). The receiver-side instrumentation is enabled only outside ingest mode — see main.go around `mode.ingest` for the gate. Without that, the ingester would emit spans about receiving spans, re-enter itself, and amplify.

  • Metrics — runtime + process counters via go.opentelemetry.io/ contrib/instrumentation/runtime. Periodic export every 30s. Custom counters / histograms register against the package's global meter (returned by `Meter()`) so call sites don't repeat the package path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled reports whether real OTel pipelines are running. Hot paths can fast-skip span work when this is false (the noop tracer already does so internally; this is just for the rare case where building expensive attribute values would itself be wasteful).

func Init

func Init(ctx context.Context, mode, version string) func(context.Context) error

Init constructs both providers when COREMETRY_SELF_OBS_OTLP_ENDPOINT is set. Returns a shutdown function the caller defers; safe to call even when disabled (no-op shutdown).

mode is the running role string ("api", "ingest", "worker", "all") — used to derive service.name. version is the binary version.

func Meter

func Meter() metric.Meter

Meter returns the package-wide meter. Noop when disabled.

func SafeAttr added in v0.9.586

func SafeAttr(s string) string

SafeAttr — bir string'i span attribute'una / durum mesajına koymadan ÖNCE geçerli UTF-8'e indirger (v0.9.586).

Operator-reported, prod:

traces export: rpc error: code = Internal desc = grpc: error while
marshaling: string field contains invalid UTF-8

protobuf'un string alanı geçerli UTF-8 ŞART koşar ve marshaling hatası TÜM BATCH'i düşürür — yani tek bir bozuk bayt yüzünden o tur hiçbir self-telemetri span'i gitmiyor. Sessiz ve toplu bir kayıp: gözlemlenebilirlik katmanının kendisi kör kalıyor.

Bozuk baytın kaynağı bizim ürettiğimiz metin DEĞİL: ClickHouse hata mesajları kusurlu veriyi AYNEN ALINTILAR ("Cannot convert string '<bayt>' …"), ve o veri filodan gelir. Yani filodaki tek bir bozuk span attribute'u, bizim kendi izlerimizi düşürebiliyor.

Maliyet: geçerli string'de yalnız bir tarama (utf8.ValidString) ve SIFIR ayırma. Yalnız bozuk olan yeniden kurulur — sıcak yolda pratikte bedelsiz.

func Tracer

func Tracer() trace.Tracer

Tracer returns the package-wide tracer. Noop when disabled.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL