Skip to content

Commit

Permalink
Update TracerProviderBuilder.WithBuildInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed May 31, 2024
1 parent 9e554db commit a096c44
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.25.0"
"golang.org/x/net/context"
"runtime/debug"
"strings"
Expand Down Expand Up @@ -101,20 +102,31 @@ func (tra *TracerProviderBuilder) WithGrpcExporter(opts ...otlptracegrpc.Option)
return tra.With(trace.WithBatcher(exp))
}

func (tra *TracerProviderBuilder) WithBuildInfo(info *debug.BuildInfo) *TracerProviderBuilder {
func (tra *TracerProviderBuilder) WithBuildInfo(info *debug.BuildInfo, modules ...string) *TracerProviderBuilder {
if info == nil {
return tra
}
if tra.Attributes == nil {
tra.Attributes = make([]attribute.KeyValue, 0, len(info.Settings))
}

_ = tra.WithAttributes(semconv.ServiceVersion(info.Main.Version))
for _, set := range info.Settings {
if !strings.HasPrefix(set.Key, "vcs.") {
continue
}

tra.Attributes = append(tra.Attributes, attribute.String(set.Key, set.Value))
}
if len(modules) > 0 {
for _, dep := range info.Deps {
for _, name := range modules {
if dep.Path != name {
continue
}

tra.Attributes = append(tra.Attributes, attribute.String(dep.Path, dep.Version))
}
}
}

return tra
}

Expand Down

0 comments on commit a096c44

Please sign in to comment.