diff --git a/internal/gitmetadata.go b/internal/gitmetadata.go index f7eb9b78c3..6dabe6a444 100644 --- a/internal/gitmetadata.go +++ b/internal/gitmetadata.go @@ -8,7 +8,10 @@ package internal import ( "net/url" "os" + "runtime/debug" "sync" + + "gopkg.in/DataDog/dd-trace-go.v1/internal/log" ) const ( @@ -73,6 +76,32 @@ func getTagsFromDDTags() map[string]string { } } +// getTagsFromBinary extracts git metadata from binary metadata +func getTagsFromBinary() map[string]string { + res := make(map[string]string) + info, ok := debug.ReadBuildInfo() + if !ok { + log.Debug("ReadBuildInfo failed, skip source code metadata extracting") + return res + } + goPath := info.Path + var vcs, commitSha string + for _, s := range info.Settings { + if s.Key == "vcs" { + vcs = s.Value + } else if s.Key == "vcs.revision" { + commitSha = s.Value + } + } + if vcs != "git" { + log.Debug("Unknown VCS: '%s', skip source code metadata extracting", vcs) + return res + } + res[TagCommitSha] = commitSha + res[TagGoPath] = goPath + return res +} + // GetGitMetadataTags returns git metadata tags func GetGitMetadataTags() map[string]string { lock.Lock() diff --git a/internal/gitmetadatabinary.go b/internal/gitmetadatabinary.go deleted file mode 100644 index 84ded5eda2..0000000000 --- a/internal/gitmetadatabinary.go +++ /dev/null @@ -1,41 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2023 Datadog, Inc. - -//go:build go1.18 -// +build go1.18 - -package internal - -import ( - "runtime/debug" - - "gopkg.in/DataDog/dd-trace-go.v1/internal/log" -) - -// getTagsFromBinary extracts git metadata from binary metadata -func getTagsFromBinary() map[string]string { - res := make(map[string]string) - info, ok := debug.ReadBuildInfo() - if !ok { - log.Debug("ReadBuildInfo failed, skip source code metadata extracting") - return res - } - goPath := info.Path - var vcs, commitSha string - for _, s := range info.Settings { - if s.Key == "vcs" { - vcs = s.Value - } else if s.Key == "vcs.revision" { - commitSha = s.Value - } - } - if vcs != "git" { - log.Debug("Unknown VCS: '%s', skip source code metadata extracting", vcs) - return res - } - res[TagCommitSha] = commitSha - res[TagGoPath] = goPath - return res -} diff --git a/internal/gitmetadatabinary_legacy.go b/internal/gitmetadatabinary_legacy.go deleted file mode 100644 index 85bcb43cc6..0000000000 --- a/internal/gitmetadatabinary_legacy.go +++ /dev/null @@ -1,19 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2023 Datadog, Inc. - -//go:build !go1.18 -// +build !go1.18 - -package internal - -import ( - "gopkg.in/DataDog/dd-trace-go.v1/internal/log" -) - -// getTagsFromBinary extracts git metadata from binary metadata -func getTagsFromBinary() map[string]string { - log.Warn("go version below 1.18, BuildInfo has no vcs info, skip source code metadata extracting") - return make(map[string]string) -}