Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions ddtrace/tracer/otelprocesscontext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025 Datadog, Inc.
package tracer

// OtelProcessContext represents the OTEL context for the process.
//
//go:generate go run github.com/tinylib/msgp -unexported -marshal=true -o=otelprocesscontext_msgp.go -tests=false
type otelProcessContext struct {
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/deployment/#deployment-environment-name
DeploymentEnvironmentName string `msg:"deployment.environment.name"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/host/#host-name
HostName string `msg:"host.name"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-instance-id
ServiceInstanceID string `msg:"service.instance.id"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-name
ServiceName string `msg:"service.name"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-version
ServiceVersion string `msg:"service.version"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/telemetry/#telemetry-sdk-language
TelemetrySDKLanguage string `msg:"telemetry.sdk.language"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/telemetry/#telemetry-sdk-version
TelemetrySDKVersion string `msg:"telemetry.sdk.version"`
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/telemetry/#telemetry-sdk-name
TelemetrySdkName string `msg:"telemetry.sdk.name"`
}
285 changes: 285 additions & 0 deletions ddtrace/tracer/otelprocesscontext_msgp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,20 @@ func Start(opts ...StartOption) error {
// DD_INSTRUMENTATION_TELEMETRY_ENABLED env var
t.telemetry = startTelemetry(t.config)

// store the configuration in an in-memory file, allowing it to be read to
// determine if the process is instrumented with a tracer and to retrive
// relevant tracing information.
// store the configuration in an in-memory file and in a named anonymous mapping,
// allowing it to be read to determine if the process is instrumented with a tracer
// and to retrieve relevant tracing information.
storeConfig(t.config)

globalinternal.SetTracerInitialized(true)
return nil
}

// storeConfig stores the process level tracing context both in an in-memory file and
// in a named anonymous mapping.
// This allows an external process, such as the Datadog Agent or fullhost profiler,
// to determine if the process is instrumented with a tracer and to retrieve the process
// level tracing context.
func storeConfig(c *config) {
uuid, _ := uuid.NewRandom()
name := fmt.Sprintf("datadog-tracer-info-%s", uuid.String()[0:8])
Expand All @@ -308,6 +313,23 @@ func storeConfig(c *config) {
if err != nil {
log.Error("failed to store the configuration: %s", err.Error())
}

processContext := otelProcessContext{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a doc that explains why were are not using the Memfd solution for OpenTelemetry? IIRC we had some good reason, but I forgot what it was. We should probably link to that doc here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reasons were:

  • memfd_create syscall might be blocked by some seccomp profiles
  • it requires more syscalls / IO since all symlinks in /proc/<pid>/fd/ need to be resolved until datadog-tracer-info-<id> file is found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "not inherited by fork" is also a nice bonus, and connects back to the discussions happening internally on the meaning of "runtime-id" -- the anonymous mapping mechanism, because it's not inherited by forks won't have any issues with stale information (such as a runtime-id) being carried from parent to child process.

DeploymentEnvironmentName: c.env,
HostName: c.hostname,
ServiceInstanceID: globalconfig.RuntimeID(),
ServiceName: c.serviceName,
ServiceVersion: c.version,
TelemetrySDKLanguage: "go",
TelemetrySDKVersion: version.Tag,
TelemetrySdkName: "dd-trace-go",
}

data, _ = processContext.MarshalMsg(nil)
err = globalinternal.CreateOtelProcessContextMapping(data)
if err != nil {
log.Error("failed to store the OTEL process context: %s", err.Error())
}
}

// Stop stops the started tracer. Subsequent calls are valid but become no-op.
Expand Down
12 changes: 12 additions & 0 deletions internal/otelcontextmapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025 Datadog, Inc.

//go:build !linux

package internal

func CreateOtelProcessContextMapping(data []byte) error {
return nil
}
Loading
Loading