-
Notifications
You must be signed in to change notification settings - Fork 429
/
gitmetadatabinary.go
41 lines (36 loc) · 1017 Bytes
/
gitmetadatabinary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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.Warn("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
}