Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"runtime/debug"
"time"

"github.com/sagernet/sing-box/log"
Expand Down Expand Up @@ -95,10 +96,24 @@ 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...)
Comment on lines 98 to 100
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildResource() now adds service.version but there’s no test asserting the attribute is present and that OTEL_RESOURCE_ATTRIBUTES can override it (similar to the existing service.name tests). Adding a unit test will prevent regressions and ensure the dashboard grouping works as expected.

Copilot uses AI. Check for mistakes.
r, _ := resource.New(context.Background(),
resource.WithAttributes(attrs...),
resource.WithFromEnv(),
)
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
}
Comment on lines +108 to +116
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vcsRevision() calls debug.ReadBuildInfo() and scans settings every time buildResource() is called (currently at least for metrics, traces, and crash reporting). Consider memoizing the result (e.g., package-level cached string with sync.Once) to avoid repeated build-info parsing during startup/reporting.

Copilot uses AI. Check for mistakes.
}
return "unknown"
}
Loading