profiler
Those integration are enabled by having the
following import
in the project’s orchestrion.tool.go
file:
import (
_ "github.com/DataDog/orchestrion"
_ "gopkg.in/DataDog/dd-trace-go.v1/profiler" // integration
//...
)
The entry point of a Go program.
func main()
All of
- Package name
main
- Is test main
false
- Function body
- Function declaration
- Function name
main
- Signature matches
- Arguments None
- Results None
Introduce new declarations:
// Using the following synthetic imports:
import (
log "log"
os "os"
profiler "gopkg.in/DataDog/dd-trace-go.v1/profiler"
)
func init() {
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)
}
}
}
Prepend statements produced by the following template:
// Using the following synthetic imports:
import (
profiler "gopkg.in/DataDog/dd-trace-go.v1/profiler"
tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
defer profiler.Stop()