Skip to content

Commit 907dd97

Browse files
authored
feat(reporter): default service to Comm (#205)
while looking at profiles, there seems to be a lot of very-short lived processes from cilium, ctr, or crictl, for which traces contain a valid Comm (since it is set as the profile root frame), but service is not detected. default the service name to `Comm` to further increase the number of process for which the service is successfully detected. in theory, comm should always be equivalent to path.Base(execPath).
1 parent f96b70e commit 907dd97

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

reporter/datadog_reporter.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,27 +452,27 @@ func (r *DatadogReporter) addProcessMetadata(trace *libpf.Trace, meta *samples.T
452452
}
453453

454454
inferredService := false
455-
if service == "" && execPath != "" {
455+
switch {
456+
case service != "":
457+
// containerd shim injects an OTEL_SERVICE_NAME environment variable that contains a hash of the container ID
458+
// see https://github.com/containerd/containerd/blob/1ce8e1ca0e43ae5942c6b60906b653107c442ce9/cmd/containerd-shim-runc-v2/manager/manager_linux.go#L106
459+
// to avoid polluting the interface with multiple service names, we replace it with "containerd-shim"
460+
if strings.HasPrefix(service, "containerd-shim-") {
461+
service = "containerd-shim"
462+
}
463+
case execPath != "":
456464
service = path.Base(execPath)
457465
inferredService = true
458-
}
459-
460-
if service == "" && rsamples.IsKernel(trace.Frames) {
466+
case rsamples.IsKernel(trace.Frames):
461467
service = "system"
462-
}
463-
464-
if service == "" {
468+
case meta.Comm != "":
469+
service = meta.Comm
470+
inferredService = true
471+
default:
465472
service = unknownServiceStr
466473
inferredService = true
467474
}
468475

469-
// containerd shim injects an OTEL_SERVICE_NAME environment variable that contains a hash of the container ID
470-
// see https://github.com/containerd/containerd/blob/1ce8e1ca0e43ae5942c6b60906b653107c442ce9/cmd/containerd-shim-runc-v2/manager/manager_linux.go#L106
471-
// to avoid polluting the interface with multiple service names, we replace it with "containerd-shim"
472-
if strings.HasPrefix(service, "containerd-shim-") {
473-
service = "containerd-shim"
474-
}
475-
476476
var containerMetadata containermetadata.ContainerMetadata
477477
if meta.ContainerID != "" && r.config.EnableSplitByService {
478478
// Use containerID when found by the eBPF profiler and not other container metadata is needed

0 commit comments

Comments
 (0)