From 2e376f0bca5f2c917417f0fa387dcb50ad75d430 Mon Sep 17 00:00:00 2001 From: Jay <110402935+jay-418@users.noreply.github.com> Date: Fri, 20 Mar 2026 19:53:29 -0600 Subject: [PATCH] set service.version for deployment monitoring --- otel/otel.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/otel/otel.go b/otel/otel.go index 6a86f8c..3243dfb 100644 --- a/otel/otel.go +++ b/otel/otel.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "runtime/debug" "time" "github.com/sagernet/sing-box/log" @@ -95,6 +96,7 @@ func deltaForCounters(kind sdkmetric.InstrumentKind) metricdata.Temporality { func buildResource(extras ...attribute.KeyValue) *resource.Resource { attrs := append([]attribute.KeyValue{ semconv.ServiceNameKey.String("lantern-box"), + semconv.ServiceVersionKey.String(vcsRevision()), }, extras...) r, _ := resource.New(context.Background(), resource.WithAttributes(attrs...), @@ -102,3 +104,16 @@ func buildResource(extras ...attribute.KeyValue) *resource.Resource { ) return r } + +func vcsRevision() string { + bi, ok := debug.ReadBuildInfo() + if !ok { + return "unknown" + } + for _, s := range bi.Settings { + if s.Key == "vcs.revision" { + return s.Value + } + } + return "unknown" +}