mirror of
https://github.com/fosrl/newt.git
synced 2026-03-09 07:12:28 -05:00
[Feature Request] Implement OpenTelemetry Metrics in Newt #57
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @marcschaeferger on GitHub (Sep 7, 2025).
Originally assigned to: @oschwartz10612 on GitHub.
Add OpenTelemetry-based observability to Newt
Reference: https://github.com/fosrl/gerbil/issues/25
Summary / Goal
Instrument Newt with OpenTelemetry Metrics (OTel) following CNCF / industry standards so that:
Why OpenTelemetry (OTel)
Requirements & Constraints
site_id,tunnel_id,transport).Recommended Newt Metrics
newt_site_registrations_totalsite_id,region,resultnewt_site_onlinesite_id,transportnewt_site_last_heartbeat_secondssite_idnewt_tunnel_sessions_totalsite_id,tunnel_id,transportnewt_tunnel_bytes_totalsite_id,tunnel_id,directionnewt_tunnel_latency_secondssite_id,tunnel_id,transportnewt_tunnel_reconnects_totalsite_id,tunnel_id,reasonnewt_connection_attempts_totalsite_id,transport,resultnewt_connection_errors_totalsite_id,transport,error_typenewt_nat_mapping_activesite_id,mapping_typenewt_peer_heartbeat_latency_secondssite_id,peer_idnewt_peer_last_handshake_secondssite_id,peer_idnewt_config_reloads_totalresultnewt_restart_count_totalnewt_go_goroutinesnewt_go_mem_alloc_bytesImplementation Plan
Dependencies (example packages)
go.mod:go.opentelemetry.io/otelgo.opentelemetry.io/otel/sdk/metricgo.opentelemetry.io/otel/exporters/prometheusgo.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc(or OTLP HTTP variant)go.opentelemetry.io/contrib/instrumentation/net/http/otelhttpgo.opentelemetry.io/contrib/instrumentation/runtimeCentral metrics package
internal/metrics/that:MeterProvider./metrics(or mounts to existing server route).metricsAPI with helper functions:Inc(name string, labels ...attribute.KeyValue)Observe(name string, value float64, labels ...attribute.KeyValue)SetGauge(name string, value float64, labels ...attribute.KeyValue)Shutdown(ctx)to flush and stop providers/exporters.Instrumentation approach
site_online/site_last_heartbeat.Histograms & buckets
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30][512, 1024, 4096, 16384, 65536, 262144, 1048576]Exporter configuration (runtime)
NEWT_METRICS_PROMETHEUS_ENABLED=trueNEWT_METRICS_OTLP_ENABLED=falseOTEL_EXPORTER_OTLP_ENDPOINT(when OTLP enabled)OTEL_EXPORTER_OTLP_PROTOCOL(http/protobuforgrpc)OTEL_SERVICE_NAME=newtOTEL_RESOURCE_ATTRIBUTES(e.g.,service.instance.id=...)OTEL_METRIC_EXPORT_INTERVAL(ms)Local testing
docker-compose.metrics.ymlwith:/metricsor scraping Collector)Collector example
examples/collector.yamldemonstrating:wg_interface,peer,site_id)out_of_order_time_windowif sending OTLP to PrometheusDocumentation
observability.md:Testing & validation
/metrics, verify metrics names, units, labels and histogram buckets./metricsoutput in the PR.Acceptance Criteria
/metricsendpoint exposes OTel metrics in Prometheus format with correct naming and units.docs/observability.mdadded with metric catalog and run instructions.🔗 References & Best Practices
Guides & integrations
Practical walkthroughs & blog posts
@marcschaeferger commented on GitHub (Nov 8, 2025):
Done in PR https://github.com/fosrl/newt/pull/162