Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"flag"
"fmt"
"os"
"strconv"
"time"

cebpf "github.com/cilium/ebpf"
Expand Down Expand Up @@ -91,6 +92,7 @@ type arguments struct {
saveCPUProfile bool
sendErrorFrames bool
serviceName string
symbolUpload bool
tags string
tracers string
verboseMode bool
Expand Down Expand Up @@ -162,6 +164,9 @@ func parseArgs() (*arguments, error) {

args.fs = fs

symbolUpload := os.Getenv("DD_EXPERIMENTAL_LOCAL_SYMBOL_UPLOAD")
args.symbolUpload, _ = strconv.ParseBool(symbolUpload)
Comment thread
nsavoire marked this conversation as resolved.
Outdated

return &args, ff.Parse(fs, os.Args[1:],
ff.WithEnvVarPrefix("OTEL_PROFILING_AGENT"),
ff.WithConfigFileFlag("config"),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/tklauser/numcpus v0.8.0
github.com/zeebo/xxh3 v1.0.2
golang.org/x/sync v0.7.0
golang.org/x/sys v0.21.0
)

Expand All @@ -32,7 +33,6 @@ require (
golang.org/x/arch v0.8.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func mainWithExitCode() exitCode {
IPAddress: sourceIP,
SaveCPUProfile: args.saveCPUProfile,
Tags: validatedTags,
UploadSymbols: args.symbolUpload,
})
if err != nil {
return failure("Failed to start reporting: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions reporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ type Config struct {
SaveCPUProfile bool
// Tags is a list of tags to be sent to the collection agent.
Tags Tags
// SymbolUpload defines whether the agent should upload debug symbols to the backend.
UploadSymbols bool
}
32 changes: 29 additions & 3 deletions reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf"
"github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf/xsync"
"github.com/open-telemetry/opentelemetry-ebpf-profiler/process"
"github.com/open-telemetry/opentelemetry-ebpf-profiler/reporter"
"github.com/open-telemetry/opentelemetry-ebpf-profiler/util"
)
Expand Down Expand Up @@ -110,7 +111,7 @@ type DatadogReporter struct {
// traceEvents stores reported trace events (trace metadata with frames and counts)
traceEvents xsync.RWMutex[map[traceAndMetaKey]*traceFramesCounts]

// execPathes stores the last known execPath for a PID.
// processes stores the metadata associated to a PID.
processes *lru.SyncedLRU[libpf.PID, processMetadata]

// samplesPerSecond is the number of samples per second.
Expand All @@ -133,6 +134,8 @@ type DatadogReporter struct {
saveCPUProfile bool

tags Tags

symbolUploader *DatadogSymbolUploader
}

// ReportTraceEvent enqueues reported trace events for the Datadog reporter.
Expand Down Expand Up @@ -211,11 +214,15 @@ func (r *DatadogReporter) ReportFallbackSymbol(frameID libpf.FrameID, symbol str
// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information.
func (r *DatadogReporter) ExecutableMetadata(fileID libpf.FileID, fileName, buildID string,
interp libpf.InterpreterType, open reporter.ExecutableOpener) {
interp libpf.InterpreterType, opener process.FileOpener) {
r.executables.Add(fileID, execInfo{
fileName: fileName,
buildID: buildID,
})

if interp == libpf.Native {
r.symbolUploader.UploadSymbols(fileID, fileName, buildID, opener)
Comment thread
nsavoire marked this conversation as resolved.
}
}

// FrameMetadata accepts metadata associated with a frame and caches this information.
Expand Down Expand Up @@ -317,6 +324,17 @@ func Start(mainCtx context.Context, cfg *Config) (reporter.Reporter, error) {
return nil, err
}

var symbolUploader *DatadogSymbolUploader
if cfg.UploadSymbols {
log.Infof("Enabling Datadog local symbol upload")
symbolUploader, err = NewDatadogSymbolUploader()
if err != nil {
log.Errorf(
"Failed to create Datadog symbol uploader, symbol upload will be disabled: %v",
err)
}
}

r := &DatadogReporter{
name: cfg.Name,
version: cfg.Version,
Expand All @@ -335,11 +353,20 @@ func Start(mainCtx context.Context, cfg *Config) (reporter.Reporter, error) {
agentAddr: cfg.CollAgentAddr,
saveCPUProfile: cfg.SaveCPUProfile,
tags: cfg.Tags,
symbolUploader: symbolUploader,
}

// Create a child context for reporting features
ctx, cancelReporting := context.WithCancel(mainCtx)

if r.symbolUploader != nil {
go func() {
if err := r.symbolUploader.Run(ctx); err != nil {
log.Errorf("Failed to run symbol uploader: %v", err)
}
}()
}

go func() {
tick := time.NewTicker(cfg.ReportInterval)
defer tick.Stop()
Expand All @@ -360,7 +387,6 @@ func Start(mainCtx context.Context, cfg *Config) (reporter.Reporter, error) {

// When Stop() is called and a signal to 'stop' is received, then:
// - cancel the reporting functions currently running (using context)
// - close the gRPC connection with collection-agent
go func() {
<-r.stopSignal
cancelReporting()
Expand Down
Loading