diff --git a/profiler/profiler_test.go b/profiler/profiler_test.go index 844078948b..a52feb96dd 100644 --- a/profiler/profiler_test.go +++ b/profiler/profiler_test.go @@ -30,6 +30,7 @@ import ( "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" "gopkg.in/DataDog/dd-trace-go.v1/internal/httpmem" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" + "gopkg.in/DataDog/dd-trace-go.v1/internal/orchestrion" "gopkg.in/DataDog/dd-trace-go.v1/internal/traceprof" "gopkg.in/DataDog/dd-trace-go.v1/internal/version" @@ -748,3 +749,17 @@ func TestUDSDefault(t *testing.T) { <-profiles } + +func TestOrchestrionProfileInfo(t *testing.T) { + t.Setenv("DD_PROFILING_ENABLED", "auto") + p := doOneShortProfileUpload(t) + info := p.event.Info.Profiler + t.Logf("%+v", info) + if got := info.Activation; got != "auto" { + t.Errorf("wanted profiler activation \"auto\", got %s", got) + } + want := orchestrion.Enabled() + if got := info.Injected; got != want { + t.Errorf("wanted profiler injected = %v, got %v", want, got) + } +} diff --git a/profiler/upload.go b/profiler/upload.go index 29160ee040..c057f0c112 100644 --- a/profiler/upload.go +++ b/profiler/upload.go @@ -16,10 +16,12 @@ import ( "mime/multipart" "net/http" "net/textproto" + "os" "strings" "time" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" + "gopkg.in/DataDog/dd-trace-go.v1/internal/orchestrion" ) // maxRetries specifies the maximum number of retries to have when an error occurs. @@ -144,6 +146,21 @@ type uploadEvent struct { Version string `json:"version"` EndpointCounts map[string]uint64 `json:"endpoint_counts,omitempty"` CustomAttributes []string `json:"custom_attributes,omitempty"` + Info profilerInfo `json:"info"` +} + +// profilerInfo holds profiler-specific information which should be attached to +// the event for backend consumption +type profilerInfo struct { + Profiler struct { + // Injected should be true if profiling was added using + // Orchestrion. The term "injection" comes from other + // languages/runtimes where profiling can be injected into the + // process at run time. + Injected bool `json:"library_injected"` + // Activation ... (TODO: explain) + Activation string `json:"activation"` + } `json:"profiler"` } // encode encodes the profile as a multipart mime request. @@ -167,6 +184,16 @@ func encode(bat batch, tags []string) (contentType string, body io.Reader, err e CustomAttributes: bat.customAttributes, } + if orchestrion.Enabled() { + event.Info.Profiler.Injected = orchestrion.Enabled() + } + // TODO: comment + if os.Getenv("DD_PROFILING_ENABLED") == "auto" { + event.Info.Profiler.Activation = "auto" + } else { + event.Info.Profiler.Activation = "manual" + } + for _, p := range bat.profiles { event.Attachments = append(event.Attachments, p.name) f, err := mw.CreateFormFile(p.name, p.name)