func main()
The entry point of a Go program.
Start Datadog Tracer and Profiler
All of
- Package name
main
- Function body
- Function declaration
- Function name
main
- Signature matches
- Arguments None
- Results None
Introduce new declarations:
// Using the following synthetic imports:
import (
testing "testing"
tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
//go:linkname __dd_civisibility_isCiVisibilityEnabled gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/integrations/gotesting.isCiVisibilityEnabled
func __dd_civisibility_isCiVisibilityEnabled() bool
func init() {
// Only initialize if is not a test process and if CI Visibility has not been disabled (by the kill switch).
// For a test process the ci visibility instrumentation will initialize the tracer
if !testing.Testing() || !__dd_civisibility_isCiVisibilityEnabled() {
tracer.Start(tracer.WithOrchestrion(map[string]string{"version": {{printf "%q" Version}}}))
}
}
Record link-time dependencies on:
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"
testing "testing"
tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// Only finalize if is not a test process and if CI Visibility has not been disabled (by the kill switch).
// For a test process the ci visibility instrumentation will finalize the tracer
if !testing.Testing() || !__dd_civisibility_isCiVisibilityEnabled() {
defer tracer.Stop()
}
defer profiler.Stop()