From 07c4ee9960b9aa1549638b597673102b7eeb2fde Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 11:57:02 +0200 Subject: [PATCH 1/8] fix: `//dd:span` on `func main()` does not work Since the tracer was started at the start of the `main` function, a `//dd:span` annotation there may not have been honored, depending on the order in which aspects were woven into the file. This PR mvoes the tracer initialization to a `func init()` function, so that it happens strictly before the `main` function starts executing, making it possible to `//dd:span` the `main` function reliably. --- internal/injector/builtin/generated.go | 10 ++-- internal/injector/builtin/generated_deps.go | 2 - .../builtin/testdata/client/main.go.snap | 60 +++++++++++-------- .../builtin/testdata/server/main.go.snap | 54 ++++++++--------- internal/injector/builtin/yaml/go-main.yml | 60 ++++++++++--------- samples/client/main.go | 1 + 6 files changed, 101 insertions(+), 86 deletions(-) diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 4e3c4741..4af325ae 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -398,15 +398,15 @@ var Aspects = [...]aspect.Aspect{ )), ), Advice: []advice.Advice{ - advice.PrependStmts(code.MustTemplate( - "tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\ndefer tracer.Stop()\n\nswitch os.Getenv(\"DD_PROFILING_ENABLED\") {\ncase \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n defer profiler.Stop()\n}", + advice.InjectDeclarations(code.MustTemplate( + "func init() {\n tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\n defer tracer.Stop()\n\n switch os.Getenv(\"DD_PROFILING_ENABLED\") {\n case \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n defer profiler.Stop()\n }\n}", map[string]string{ "log": "log", "os": "os", "profiler": "gopkg.in/DataDog/dd-trace-go.v1/profiler", "tracer": "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer", }, - )), + ), []string{}), }, }, // From grpc.yml @@ -892,9 +892,7 @@ var InjectedPaths = [...]string{ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec", "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig", "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema", - "gopkg.in/DataDog/dd-trace-go.v1/profiler", "k8s.io/client-go/transport", - "log", "math", "net/http", "os", @@ -902,4 +900,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:Z3JxT6M1P2R2y0LTauBpTytjCBSfA4UTuaU4j5YdZJw1Ssm+qEETXtz4tYXuRr39B23T092cda/wo1ZIlGAiJA==" +const Checksum = "sha512:pI9UsW9w25PylHnocvbmUSTkF9yAlEIqKFX+3JnwElQa6yPfSUPBdGCHFlCq8bg2UTmvMCjrXHldXBjtTD9TjQ==" diff --git a/internal/injector/builtin/generated_deps.go b/internal/injector/builtin/generated_deps.go index 5f166fcb..66529c6d 100644 --- a/internal/injector/builtin/generated_deps.go +++ b/internal/injector/builtin/generated_deps.go @@ -53,9 +53,7 @@ import ( _ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema" - _ "gopkg.in/DataDog/dd-trace-go.v1/profiler" _ "k8s.io/client-go/transport" - _ "log" _ "math" _ "net/http" _ "os" diff --git a/internal/injector/builtin/testdata/client/main.go.snap b/internal/injector/builtin/testdata/client/main.go.snap index 8fc6e9a8..6411bfe3 100644 --- a/internal/injector/builtin/testdata/client/main.go.snap +++ b/internal/injector/builtin/testdata/client/main.go.snap @@ -20,35 +20,20 @@ import ( __orchestrion_log "log" ) -//line samples/client/main.go:18 +//dd:span +//line samples/client/main.go:19 func main() { //line { - __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) - defer __orchestrion_tracer.Stop() + ctx := context.TODO() + var span __orchestrion_tracer.Span + span, ctx = __orchestrion_tracer.StartSpanFromContext(ctx, "main", + __orchestrion_tracer.Tag("function-name", "main"), + ) - switch os.Getenv("DD_PROFILING_ENABLED") { - case "1", "true", "auto": - // The "auto" value can be set if profiling is enabled via the - // Datadog Admission Controller. We always turn on the profiler in - // the "auto" case since we only send profiles after at least a - // minute, and we assume anything running that long is worth - // profiling. - err := __orchestrion_profiler.Start( - __orchestrion_profiler.WithProfileTypes(__orchestrion_profiler.CPUProfile, __orchestrion_profiler.HeapProfile, __orchestrion_profiler.GoroutineProfile, __orchestrion_profiler.MutexProfile), - __orchestrion_profiler.WithTags("orchestrion:true"), - ) - if err != nil { - // TODO: is there a better reporting mechanism? - // The tracer and profiler already use the stdlib logger, so - // we're not adding anything new. But users might be using a - // different logger. - __orchestrion_log.Printf("failed to start profiling: %s", err) - } - defer __orchestrion_profiler.Stop() - } + defer span.Finish() } -//line samples/client/main.go:19 +//line samples/client/main.go:20 if len(os.Args) < 2 { return } @@ -76,3 +61,30 @@ func main() { } fmt.Println(string(b)) } + +//line +func init() { + __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) + defer __orchestrion_tracer.Stop() + + switch os.Getenv("DD_PROFILING_ENABLED") { + case "1", "true", "auto": + // The "auto" value can be set if profiling is enabled via the + // Datadog Admission Controller. We always turn on the profiler in + // the "auto" case since we only send profiles after at least a + // minute, and we assume anything running that long is worth + // profiling. + err := __orchestrion_profiler.Start( + __orchestrion_profiler.WithProfileTypes(__orchestrion_profiler.CPUProfile, __orchestrion_profiler.HeapProfile, __orchestrion_profiler.GoroutineProfile, __orchestrion_profiler.MutexProfile), + __orchestrion_profiler.WithTags("orchestrion:true"), + ) + if err != nil { + // TODO: is there a better reporting mechanism? + // The tracer and profiler already use the stdlib logger, so + // we're not adding anything new. But users might be using a + // different logger. + __orchestrion_log.Printf("failed to start profiling: %s", err) + } + defer __orchestrion_profiler.Stop() + } +} diff --git a/internal/injector/builtin/testdata/server/main.go.snap b/internal/injector/builtin/testdata/server/main.go.snap index aedf5e7f..e4b05ab6 100644 --- a/internal/injector/builtin/testdata/server/main.go.snap +++ b/internal/injector/builtin/testdata/server/main.go.snap @@ -19,33 +19,6 @@ import ( //line samples/server/main.go:14 func main() { -//line - { - __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) - defer __orchestrion_tracer.Stop() - - switch __orchestrion_os.Getenv("DD_PROFILING_ENABLED") { - case "1", "true", "auto": - // The "auto" value can be set if profiling is enabled via the - // Datadog Admission Controller. We always turn on the profiler in - // the "auto" case since we only send profiles after at least a - // minute, and we assume anything running that long is worth - // profiling. - err := __orchestrion_profiler.Start( - __orchestrion_profiler.WithProfileTypes(__orchestrion_profiler.CPUProfile, __orchestrion_profiler.HeapProfile, __orchestrion_profiler.GoroutineProfile, __orchestrion_profiler.MutexProfile), - __orchestrion_profiler.WithTags("orchestrion:true"), - ) - if err != nil { - // TODO: is there a better reporting mechanism? - // The tracer and profiler already use the stdlib logger, so - // we're not adding anything new. But users might be using a - // different logger. - log.Printf("failed to start profiling: %s", err) - } - defer __orchestrion_profiler.Stop() - } - } -//line samples/server/main.go:15 s := &http.Server{ Addr: ":8080", Handler: @@ -89,3 +62,30 @@ func instrumentedHandler(w http.ResponseWriter, r *http.Request) { } // comment that is just hanging out unattached +// +//line +func init() { + __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) + defer __orchestrion_tracer.Stop() + + switch __orchestrion_os.Getenv("DD_PROFILING_ENABLED") { + case "1", "true", "auto": + // The "auto" value can be set if profiling is enabled via the + // Datadog Admission Controller. We always turn on the profiler in + // the "auto" case since we only send profiles after at least a + // minute, and we assume anything running that long is worth + // profiling. + err := __orchestrion_profiler.Start( + __orchestrion_profiler.WithProfileTypes(__orchestrion_profiler.CPUProfile, __orchestrion_profiler.HeapProfile, __orchestrion_profiler.GoroutineProfile, __orchestrion_profiler.MutexProfile), + __orchestrion_profiler.WithTags("orchestrion:true"), + ) + if err != nil { + // TODO: is there a better reporting mechanism? + // The tracer and profiler already use the stdlib logger, so + // we're not adding anything new. But users might be using a + // different logger. + log.Printf("failed to start profiling: %s", err) + } + defer __orchestrion_profiler.Stop() + } +} diff --git a/internal/injector/builtin/yaml/go-main.yml b/internal/injector/builtin/yaml/go-main.yml index ae5e47f9..48d5aa92 100644 --- a/internal/injector/builtin/yaml/go-main.yml +++ b/internal/injector/builtin/yaml/go-main.yml @@ -18,39 +18,45 @@ aspects: - name: main - signature: {} advice: - - prepend-statements: + - inject-declarations: imports: tracer: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer profiler: gopkg.in/DataDog/dd-trace-go.v1/profiler log: log os: os + # Note: it is valid to have multiple func init() in a single compile unit (e.g, `.go` file), in which case + # they get executed in declaration order. This means it's okay for us to add a new init function if there is + # already one in the file, but as it currently is appended AFTER all other declarations in the file, it means + # that it will be executed last (tracing contents of previous init functions will not be possible). template: |- - tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}})) - defer tracer.Stop() + func init() { + tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}})) + defer tracer.Stop() - switch os.Getenv("DD_PROFILING_ENABLED") { - case "1", "true", "auto": - // The "auto" value can be set if profiling is enabled via the - // Datadog Admission Controller. We always turn on the profiler in - // the "auto" case since we only send profiles after at least a - // minute, and we assume anything running that long is worth - // profiling. - err := profiler.Start( - profiler.WithProfileTypes( - profiler.CPUProfile, - profiler.HeapProfile, - // Non-default profiles which are highly likely to be useful: - profiler.GoroutineProfile, - profiler.MutexProfile, - ), - profiler.WithTags("orchestrion:true"), - ) - if err != nil { - // TODO: is there a better reporting mechanism? - // The tracer and profiler already use the stdlib logger, so - // we're not adding anything new. But users might be using a - // different logger. - log.Printf("failed to start profiling: %s", err) + switch os.Getenv("DD_PROFILING_ENABLED") { + case "1", "true", "auto": + // The "auto" value can be set if profiling is enabled via the + // Datadog Admission Controller. We always turn on the profiler in + // the "auto" case since we only send profiles after at least a + // minute, and we assume anything running that long is worth + // profiling. + err := profiler.Start( + profiler.WithProfileTypes( + profiler.CPUProfile, + profiler.HeapProfile, + // Non-default profiles which are highly likely to be useful: + profiler.GoroutineProfile, + profiler.MutexProfile, + ), + profiler.WithTags("orchestrion:true"), + ) + if err != nil { + // TODO: is there a better reporting mechanism? + // The tracer and profiler already use the stdlib logger, so + // we're not adding anything new. But users might be using a + // different logger. + log.Printf("failed to start profiling: %s", err) + } + defer profiler.Stop() } - defer profiler.Stop() } diff --git a/samples/client/main.go b/samples/client/main.go index 73dce232..e45e34db 100644 --- a/samples/client/main.go +++ b/samples/client/main.go @@ -15,6 +15,7 @@ import ( "time" ) +//dd:span func main() { if len(os.Args) < 2 { return From 46ca5cd1b75de5c992a9b95591893f9cdc181af4 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 12:03:52 +0200 Subject: [PATCH 2/8] chore: update generated files --- _integration-tests/go.mod | 4 ---- _integration-tests/go.sum | 3 --- go.mod | 3 --- go.sum | 5 ----- samples/go.mod | 4 ---- samples/go.sum | 6 ------ 6 files changed, 25 deletions(-) diff --git a/_integration-tests/go.mod b/_integration-tests/go.mod index ee7441a2..d686b985 100644 --- a/_integration-tests/go.mod +++ b/_integration-tests/go.mod @@ -77,7 +77,6 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect - github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect @@ -198,7 +197,6 @@ require ( github.com/google/go-licenses/v2 v2.0.0-alpha.1 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect - github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/wire v0.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect @@ -288,7 +286,6 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect - github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -298,7 +295,6 @@ require ( github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/_integration-tests/go.sum b/_integration-tests/go.sum index a36d4b75..1bac2397 100644 --- a/_integration-tests/go.sum +++ b/_integration-tests/go.sum @@ -1139,7 +1139,6 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -2371,7 +2370,6 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -2410,7 +2408,6 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= -gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/go.mod b/go.mod index 831c67d9..0325fbd1 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,6 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect - github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/IBM/sarama v1.43.3 // indirect github.com/Masterminds/goutils v1.1.1 // indirect @@ -251,14 +250,12 @@ require ( github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/redis/go-redis/v9 v9.1.0 // indirect - github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/go.sum b/go.sum index 747557c9..904f0318 100644 --- a/go.sum +++ b/go.sum @@ -444,7 +444,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -479,7 +478,6 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -1282,8 +1280,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -1319,7 +1315,6 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= -gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/samples/go.mod b/samples/go.mod index 76b14abf..138b93ce 100644 --- a/samples/go.mod +++ b/samples/go.mod @@ -53,7 +53,6 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect - github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect @@ -161,7 +160,6 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-licenses/v2 v2.0.0-alpha.1 // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect - github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/google/wire v0.6.0 // indirect @@ -244,7 +242,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect - github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -253,7 +250,6 @@ require ( github.com/sergi/go-diff v1.3.1 // indirect github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/samples/go.sum b/samples/go.sum index e9af0299..efd69da4 100644 --- a/samples/go.sum +++ b/samples/go.sum @@ -431,7 +431,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -465,7 +464,6 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -1263,8 +1261,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -1300,8 +1296,6 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= -gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From e39600de77839bbaf506b20efcd33c73d15d22fc Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 12:16:30 +0200 Subject: [PATCH 3/8] Split tracer & profiler startup in separate inits --- internal/injector/builtin/generated.go | 11 ++++++++--- .../builtin/testdata/client/main.go.snap | 3 ++- .../builtin/testdata/server/main.go.snap | 3 ++- internal/injector/builtin/yaml/go-main.yml | 16 +++++++++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 4af325ae..c1367816 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -399,12 +399,17 @@ var Aspects = [...]aspect.Aspect{ ), Advice: []advice.Advice{ advice.InjectDeclarations(code.MustTemplate( - "func init() {\n tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\n defer tracer.Stop()\n\n switch os.Getenv(\"DD_PROFILING_ENABLED\") {\n case \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n defer profiler.Stop()\n }\n}", + "func init() {\n tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\n defer tracer.Stop()\n}", + map[string]string{ + "tracer": "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer", + }, + ), []string{}), + advice.InjectDeclarations(code.MustTemplate( + "func init() {\n switch os.Getenv(\"DD_PROFILING_ENABLED\") {\n case \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n defer profiler.Stop()\n }\n}", map[string]string{ "log": "log", "os": "os", "profiler": "gopkg.in/DataDog/dd-trace-go.v1/profiler", - "tracer": "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer", }, ), []string{}), }, @@ -900,4 +905,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:pI9UsW9w25PylHnocvbmUSTkF9yAlEIqKFX+3JnwElQa6yPfSUPBdGCHFlCq8bg2UTmvMCjrXHldXBjtTD9TjQ==" +const Checksum = "sha512:Df8rPqS4UaO4jhfs1rtyrMze0xU+6JOC4+4+JcICThslYrzdX8EyhxAbH5FqVAKulLpUafG3embP8RQUsTa16A==" diff --git a/internal/injector/builtin/testdata/client/main.go.snap b/internal/injector/builtin/testdata/client/main.go.snap index 6411bfe3..c88e87c6 100644 --- a/internal/injector/builtin/testdata/client/main.go.snap +++ b/internal/injector/builtin/testdata/client/main.go.snap @@ -66,7 +66,8 @@ func main() { func init() { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) defer __orchestrion_tracer.Stop() - +} +func init() { switch os.Getenv("DD_PROFILING_ENABLED") { case "1", "true", "auto": // The "auto" value can be set if profiling is enabled via the diff --git a/internal/injector/builtin/testdata/server/main.go.snap b/internal/injector/builtin/testdata/server/main.go.snap index e4b05ab6..5d44e6bf 100644 --- a/internal/injector/builtin/testdata/server/main.go.snap +++ b/internal/injector/builtin/testdata/server/main.go.snap @@ -67,7 +67,8 @@ func instrumentedHandler(w http.ResponseWriter, r *http.Request) { func init() { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) defer __orchestrion_tracer.Stop() - +} +func init() { switch __orchestrion_os.Getenv("DD_PROFILING_ENABLED") { case "1", "true", "auto": // The "auto" value can be set if profiling is enabled via the diff --git a/internal/injector/builtin/yaml/go-main.yml b/internal/injector/builtin/yaml/go-main.yml index 48d5aa92..e79ea7ea 100644 --- a/internal/injector/builtin/yaml/go-main.yml +++ b/internal/injector/builtin/yaml/go-main.yml @@ -21,9 +21,6 @@ aspects: - inject-declarations: imports: tracer: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer - profiler: gopkg.in/DataDog/dd-trace-go.v1/profiler - log: log - os: os # Note: it is valid to have multiple func init() in a single compile unit (e.g, `.go` file), in which case # they get executed in declaration order. This means it's okay for us to add a new init function if there is # already one in the file, but as it currently is appended AFTER all other declarations in the file, it means @@ -32,7 +29,19 @@ aspects: func init() { tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}})) defer tracer.Stop() + } + - inject-declarations: + imports: + profiler: gopkg.in/DataDog/dd-trace-go.v1/profiler + log: log + os: os + # Note: it is valid to have multiple func init() in a single compile unit (e.g, `.go` file), in which case + # they get executed in declaration order. This means it's okay for us to add a new init function if there is + # already one in the file, but as it currently is appended AFTER all other declarations in the file, it means + # that it will be executed last (tracing contents of previous init functions will not be possible). + template: |- + func init() { switch os.Getenv("DD_PROFILING_ENABLED") { case "1", "true", "auto": // The "auto" value can be set if profiling is enabled via the @@ -60,3 +69,4 @@ aspects: defer profiler.Stop() } } + From a929389ba3a2518574bffaa84ece1237dbba84e3 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 12:20:47 +0200 Subject: [PATCH 4/8] chore: update generated files --- internal/injector/builtin/generated.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 94c88de7..1ff60955 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -950,4 +950,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:nhpM4PMwbOYG59ltTFFH4IYjMl7wG/gm1RDfLuq6zdj03WwIu1taNm0PXM1GzA6gQjeuQHcqpVWMs1iUq/Kn5w==" +const Checksum = "sha512:7r7UHAfetaIBtLkp0CUx9vpDLyncNCY8HgeTjb2UzLcEBafen+zGW61SOEPPhZWH3tGXSaHP2KA42iU/75zeyA==" From 928a842498579ecbf864ce8bd5dada3f90592f9d Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 15:24:31 +0200 Subject: [PATCH 5/8] Properly stop the tracer and profiler at the end of main instead of the end of their respective init blocks --- internal/injector/builtin/generated.go | 14 +++++++++++--- internal/injector/builtin/generated_deps.go | 1 + .../injector/builtin/testdata/client/main.go.snap | 6 ++++-- .../injector/builtin/testdata/server/main.go.snap | 8 ++++++-- internal/injector/builtin/yaml/go-main.yml | 11 +++++++++-- internal/jobserver/pkgs/resolve.go | 6 +++++- main_test.go | 13 +++++++------ 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 1ff60955..50c8ed04 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -399,19 +399,26 @@ var Aspects = [...]aspect.Aspect{ ), Advice: []advice.Advice{ advice.InjectDeclarations(code.MustTemplate( - "func init() {\n tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\n defer tracer.Stop()\n}", + "func init() {\n tracer.Start(tracer.WithOrchestrion(map[string]string{\"version\": {{printf \"%q\" Version}}}))\n}", map[string]string{ "tracer": "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer", }, ), []string{}), advice.InjectDeclarations(code.MustTemplate( - "func init() {\n switch os.Getenv(\"DD_PROFILING_ENABLED\") {\n case \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n defer profiler.Stop()\n }\n}", + "func init() {\n switch os.Getenv(\"DD_PROFILING_ENABLED\") {\n case \"1\", \"true\", \"auto\":\n // The \"auto\" value can be set if profiling is enabled via the\n // Datadog Admission Controller. We always turn on the profiler in\n // the \"auto\" case since we only send profiles after at least a\n // minute, and we assume anything running that long is worth\n // profiling.\n err := profiler.Start(\n profiler.WithProfileTypes(\n profiler.CPUProfile,\n profiler.HeapProfile,\n // Non-default profiles which are highly likely to be useful:\n profiler.GoroutineProfile,\n profiler.MutexProfile,\n ),\n profiler.WithTags(\"orchestrion:true\"),\n )\n if err != nil {\n // TODO: is there a better reporting mechanism?\n // The tracer and profiler already use the stdlib logger, so\n // we're not adding anything new. But users might be using a\n // different logger.\n log.Printf(\"failed to start profiling: %s\", err)\n }\n }\n}", map[string]string{ "log": "log", "os": "os", "profiler": "gopkg.in/DataDog/dd-trace-go.v1/profiler", }, ), []string{}), + advice.PrependStmts(code.MustTemplate( + "defer tracer.Stop()\ndefer profiler.Stop()", + map[string]string{ + "profiler": "gopkg.in/DataDog/dd-trace-go.v1/profiler", + "tracer": "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer", + }, + )), }, }, // From graphql/gqlgen.yml @@ -942,6 +949,7 @@ var InjectedPaths = [...]string{ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec", "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig", "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema", + "gopkg.in/DataDog/dd-trace-go.v1/profiler", "k8s.io/client-go/transport", "math", "net/http", @@ -950,4 +958,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:7r7UHAfetaIBtLkp0CUx9vpDLyncNCY8HgeTjb2UzLcEBafen+zGW61SOEPPhZWH3tGXSaHP2KA42iU/75zeyA==" +const Checksum = "sha512:pXFHjupxWE+tdgFLK/03Q7H+ireSfSHPXx8ETxc5ZuHABZLZc1DPOpFxCcZmOP2tCoSAc+K6iWr3iwKmJE3/qQ==" diff --git a/internal/injector/builtin/generated_deps.go b/internal/injector/builtin/generated_deps.go index f441aa7d..be89d537 100644 --- a/internal/injector/builtin/generated_deps.go +++ b/internal/injector/builtin/generated_deps.go @@ -56,6 +56,7 @@ import ( _ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema" + _ "gopkg.in/DataDog/dd-trace-go.v1/profiler" _ "k8s.io/client-go/transport" _ "math" _ "net/http" diff --git a/internal/injector/builtin/testdata/client/main.go.snap b/internal/injector/builtin/testdata/client/main.go.snap index c88e87c6..5ec31952 100644 --- a/internal/injector/builtin/testdata/client/main.go.snap +++ b/internal/injector/builtin/testdata/client/main.go.snap @@ -24,6 +24,10 @@ import ( //line samples/client/main.go:19 func main() { //line + { + defer __orchestrion_tracer.Stop() + defer __orchestrion_profiler.Stop() + } { ctx := context.TODO() var span __orchestrion_tracer.Span @@ -65,7 +69,6 @@ func main() { //line func init() { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) - defer __orchestrion_tracer.Stop() } func init() { switch os.Getenv("DD_PROFILING_ENABLED") { @@ -86,6 +89,5 @@ func init() { // different logger. __orchestrion_log.Printf("failed to start profiling: %s", err) } - defer __orchestrion_profiler.Stop() } } diff --git a/internal/injector/builtin/testdata/server/main.go.snap b/internal/injector/builtin/testdata/server/main.go.snap index 5d44e6bf..2738abec 100644 --- a/internal/injector/builtin/testdata/server/main.go.snap +++ b/internal/injector/builtin/testdata/server/main.go.snap @@ -19,6 +19,12 @@ import ( //line samples/server/main.go:14 func main() { +//line + { + defer __orchestrion_tracer.Stop() + defer __orchestrion_profiler.Stop() + } +//line samples/server/main.go:15 s := &http.Server{ Addr: ":8080", Handler: @@ -66,7 +72,6 @@ func instrumentedHandler(w http.ResponseWriter, r *http.Request) { //line func init() { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) - defer __orchestrion_tracer.Stop() } func init() { switch __orchestrion_os.Getenv("DD_PROFILING_ENABLED") { @@ -87,6 +92,5 @@ func init() { // different logger. log.Printf("failed to start profiling: %s", err) } - defer __orchestrion_profiler.Stop() } } diff --git a/internal/injector/builtin/yaml/go-main.yml b/internal/injector/builtin/yaml/go-main.yml index e79ea7ea..a9585405 100644 --- a/internal/injector/builtin/yaml/go-main.yml +++ b/internal/injector/builtin/yaml/go-main.yml @@ -28,7 +28,6 @@ aspects: template: |- func init() { tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}})) - defer tracer.Stop() } - inject-declarations: @@ -66,7 +65,15 @@ aspects: // different logger. log.Printf("failed to start profiling: %s", err) } - defer profiler.Stop() } } + # We need to stop the tracer and profiler at the end of `main` to ensure profiles are complete and all spans are + # properly flushed. + - prepend-statements: + imports: + profiler: gopkg.in/DataDog/dd-trace-go.v1/profiler + tracer: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer + template: |- + defer tracer.Stop() + defer profiler.Stop() diff --git a/internal/jobserver/pkgs/resolve.go b/internal/jobserver/pkgs/resolve.go index a2660aa2..4bc645d0 100644 --- a/internal/jobserver/pkgs/resolve.go +++ b/internal/jobserver/pkgs/resolve.go @@ -131,7 +131,7 @@ func (s *service) resolve(req *ResolveRequest) (ResolveResponse, error) { Dir: req.Dir, Env: env, BuildFlags: req.BuildFlags, - Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, + Logf: func(format string, args ...any) { log.Infof("[JOBSERVER] packages.Load -- "+format+"\n", args...) }, }, req.Pattern, ) @@ -183,6 +183,10 @@ func (r ResolveResponse) mergeFrom(pkg *packages.Package) { return } + for _, err := range pkg.Errors { + log.Errorf("[JOBSERVER] Error during resolution of %q: %v\n", pkg.PkgPath, err) + } + r[pkg.PkgPath] = pkg.ExportFile for _, dep := range pkg.Imports { r.mergeFrom(dep) diff --git a/main_test.go b/main_test.go index 5418c52e..c58ea754 100644 --- a/main_test.go +++ b/main_test.go @@ -15,6 +15,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "sync" "testing" @@ -29,11 +30,11 @@ type testCase interface { } var testCases = map[string]func(b *testing.B) testCase{ - "DataDog:orchestrion": benchmarkOrchestrion, - "traefik:traefik": benchmarkGithub("traefik", "traefik", "./..."), - "go-delve:delve": benchmarkGithub("go-delve", "delve", "./..."), - "jlegrone:tctx": benchmarkGithub("jlegrone", "tctx", "./..."), - "tinylib:msgp": benchmarkGithub("tinylib", "msgp", "./..."), + // "DataDog:orchestrion": benchmarkOrchestrion, + "traefik:traefik": benchmarkGithub("traefik", "traefik", "./..."), + // "go-delve:delve": benchmarkGithub("go-delve", "delve", "./..."), + // "jlegrone:tctx": benchmarkGithub("jlegrone", "tctx", "./..."), + // "tinylib:msgp": benchmarkGithub("tinylib", "msgp", "./..."), } func Benchmark(b *testing.B) { @@ -191,7 +192,7 @@ func getGithubToken() (string, bool) { return "", false } - return bytes.String(), true + return strings.TrimSpace(bytes.String()), true } func (h *harness) gitCloneGithub(owner string, repo string, tag string) string { From a3cbf78c49bb47640c91b742de42d5b5070a8599 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 15:28:05 +0200 Subject: [PATCH 6/8] chore: update generated files --- _integration-tests/go.mod | 4 ++++ _integration-tests/go.sum | 3 +++ go.mod | 3 +++ go.sum | 5 +++++ samples/go.mod | 4 ++++ samples/go.sum | 6 ++++++ 6 files changed, 25 insertions(+) diff --git a/_integration-tests/go.mod b/_integration-tests/go.mod index e830af22..e6e7ccf8 100644 --- a/_integration-tests/go.mod +++ b/_integration-tests/go.mod @@ -82,6 +82,7 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect + github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect @@ -203,6 +204,7 @@ require ( github.com/google/go-licenses/v2 v2.0.0-alpha.1 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect + github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/wire v0.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect @@ -292,6 +294,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -301,6 +304,7 @@ require ( github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/_integration-tests/go.sum b/_integration-tests/go.sum index ffa27b93..ea17e1c9 100644 --- a/_integration-tests/go.sum +++ b/_integration-tests/go.sum @@ -1150,6 +1150,7 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -2391,6 +2392,7 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -2429,6 +2431,7 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/go.mod b/go.mod index c9a69721..ec196c22 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect + github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/IBM/sarama v1.43.3 // indirect github.com/Masterminds/goutils v1.1.1 // indirect @@ -253,12 +254,14 @@ require ( github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/redis/go-redis/v9 v9.1.0 // indirect + github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/go.sum b/go.sum index 059f2ac9..ddea9964 100644 --- a/go.sum +++ b/go.sum @@ -451,6 +451,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -485,6 +486,7 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -1297,6 +1299,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -1332,6 +1336,7 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/samples/go.mod b/samples/go.mod index 25d8833e..96d4a992 100644 --- a/samples/go.mod +++ b/samples/go.mod @@ -55,6 +55,7 @@ require ( github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect github.com/DataDog/go-sqllexer v0.0.14 // indirect github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect + github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect @@ -163,6 +164,7 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-licenses/v2 v2.0.0-alpha.1 // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect + github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/google/wire v0.6.0 // indirect @@ -247,6 +249,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -255,6 +258,7 @@ require ( github.com/sergi/go-diff v1.3.1 // indirect github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/samples/go.sum b/samples/go.sum index 3e05a09e..2ceb4eb3 100644 --- a/samples/go.sum +++ b/samples/go.sum @@ -442,6 +442,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -475,6 +476,7 @@ github.com/google/go-replayers/grpcreplay v1.3.0/go.mod h1:v6NgKtkijC0d3e3RW8il6 github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk= github.com/google/go-replayers/httpreplay v1.2.0/go.mod h1:WahEFFZZ7a1P4VM1qEeHy+tME4bwyqPcwWbNlUI1Mcg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA= @@ -1282,6 +1284,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw= @@ -1317,6 +1321,8 @@ gorm.io/driver/sqlserver v1.4.2 h1:nMtEeKqv2R/vv9FoHUFWfXfP6SskAgRar0TPlZV1stk= gorm.io/driver/sqlserver v1.4.2/go.mod h1:XHwBuB4Tlh7DqO0x7Ema8dmyWsQW7wi38VQOAFkrbXY= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From d5e6859b8c1c8ff0e6a4e7947e5134ef92c93c80 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 15:30:46 +0200 Subject: [PATCH 7/8] Restore all tests --- internal/injector/aspect/advice/inject.go | 2 +- main_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/injector/aspect/advice/inject.go b/internal/injector/aspect/advice/inject.go index e2cd4d8c..b4bc831e 100644 --- a/internal/injector/aspect/advice/inject.go +++ b/internal/injector/aspect/advice/inject.go @@ -64,7 +64,7 @@ func (a injectDeclarations) AsCode() jen.Code { } func (a injectDeclarations) AddedImports() []string { - return a.Links + return append(a.Template.AddedImports(), a.Links...) } func init() { diff --git a/main_test.go b/main_test.go index c58ea754..a0294f79 100644 --- a/main_test.go +++ b/main_test.go @@ -30,11 +30,11 @@ type testCase interface { } var testCases = map[string]func(b *testing.B) testCase{ - // "DataDog:orchestrion": benchmarkOrchestrion, - "traefik:traefik": benchmarkGithub("traefik", "traefik", "./..."), - // "go-delve:delve": benchmarkGithub("go-delve", "delve", "./..."), - // "jlegrone:tctx": benchmarkGithub("jlegrone", "tctx", "./..."), - // "tinylib:msgp": benchmarkGithub("tinylib", "msgp", "./..."), + "DataDog:orchestrion": benchmarkOrchestrion, + "traefik:traefik": benchmarkGithub("traefik", "traefik", "./..."), + "go-delve:delve": benchmarkGithub("go-delve", "delve", "./..."), + "jlegrone:tctx": benchmarkGithub("jlegrone", "tctx", "./..."), + "tinylib:msgp": benchmarkGithub("tinylib", "msgp", "./..."), } func Benchmark(b *testing.B) { From ed224ab4a344f9ff3c7bdf8d5beb87e0958ee7b9 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 3 Oct 2024 15:50:30 +0200 Subject: [PATCH 8/8] chore: update generated files --- internal/injector/builtin/generated.go | 2 ++ internal/injector/builtin/generated_deps.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 50c8ed04..07d9618d 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -949,8 +949,10 @@ var InjectedPaths = [...]string{ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec", "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig", "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema", + "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry", "gopkg.in/DataDog/dd-trace-go.v1/profiler", "k8s.io/client-go/transport", + "log", "math", "net/http", "os", diff --git a/internal/injector/builtin/generated_deps.go b/internal/injector/builtin/generated_deps.go index be89d537..e4fc0ba5 100644 --- a/internal/injector/builtin/generated_deps.go +++ b/internal/injector/builtin/generated_deps.go @@ -56,8 +56,10 @@ import ( _ "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" _ "gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema" + _ "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry" _ "gopkg.in/DataDog/dd-trace-go.v1/profiler" _ "k8s.io/client-go/transport" + _ "log" _ "math" _ "net/http" _ "os"