Originally created by @marcschaeferger on GitHub (Sep 7, 2025).
Originally assigned to: @oschwartz10612 on GitHub.
Reference: https://github.com/fosrl/gerbil/issues/25
Instrument Newt with OpenTelemetry Metrics (OTel) following CNCF / industry standards so that:
site_id
tunnel_id
transport
newt_site_registrations_total
region
result
newt_site_online
newt_site_last_heartbeat_seconds
newt_tunnel_sessions_total
newt_tunnel_bytes_total
direction
newt_tunnel_latency_seconds
newt_tunnel_reconnects_total
reason
newt_connection_attempts_total
newt_connection_errors_total
error_type
newt_nat_mapping_active
mapping_type
newt_peer_heartbeat_latency_seconds
peer_id
newt_peer_last_handshake_seconds
newt_config_reloads_total
newt_restart_count_total
newt_go_goroutines
newt_go_mem_alloc_bytes
Dependencies (example packages)
go.mod
go.opentelemetry.io/otel
go.opentelemetry.io/otel/sdk/metric
go.opentelemetry.io/otel/exporters/prometheus
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
go.opentelemetry.io/contrib/instrumentation/runtime
Central metrics package
internal/metrics/
MeterProvider
/metrics
metrics
Inc(name string, labels ...attribute.KeyValue)
Observe(name string, value float64, labels ...attribute.KeyValue)
SetGauge(name string, value float64, labels ...attribute.KeyValue)
Shutdown(ctx)
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=true
NEWT_METRICS_OTLP_ENABLED=false
OTEL_EXPORTER_OTLP_ENDPOINT
OTEL_EXPORTER_OTLP_PROTOCOL
http/protobuf
grpc
OTEL_SERVICE_NAME=newt
OTEL_RESOURCE_ATTRIBUTES
service.instance.id=...
OTEL_METRIC_EXPORT_INTERVAL
Local testing
docker-compose.metrics.yml
Collector example
examples/collector.yaml
wg_interface
peer
out_of_order_time_window
Documentation
observability.md
Testing & validation
docs/observability.md
Guides & integrations
Practical walkthroughs & blog posts
@marcschaeferger commented on GitHub (Nov 8, 2025):
Done in PR https://github.com/fosrl/newt/pull/162
No dependencies set.
The note is not visible to the blocked user.
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