func main()
The entry point of a Go program.
Start Datadog Tracer and Profiler
All of
- Package name
main
- Synthetic main package No
- Function body
- Function declaration
- Function name
main
- Signature matches
- Arguments None
- Results None
Introduce new declarations:
// Using the following synthetic imports:
import (
tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
func init() {
tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}}))
}
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 tracer.Stop()
defer profiler.Stop()