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" +}