Skip to content

feat: Propagate process context to profiles#66

Open
nsavoire wants to merge 5 commits into
datadogfrom
nsavoire/context_propagation
Open

feat: Propagate process context to profiles#66
nsavoire wants to merge 5 commits into
datadogfrom
nsavoire/context_propagation

Conversation

@nsavoire

@nsavoire nsavoire commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Propagate OTel ProcessContext resource attributes (per OTEP #4719) to the OTLP profile output so profiles can be correlated with the rest of the telemetry from the same service instance.

Changes

processcontext:

  • Info.Resource is now a *pcommon.Resource (was *resourcepb.Resource), so resource attributes flow directly into the OTLP reporter without re-conversion. convertAnyValue handles all AnyValue variants including
    nested arrays/maps.
  • WithMergedEnvVars(info, envVars) enriches an Info with OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES. Per the OTel resource SDK spec: keys and values are percent-encoded; on any decoding error the entire OTEL_RESOURCE_ATTRIBUTES value is discarded; duplicate keys within it resolve last-writer-wins; OTEL_SERVICE_NAME overrides service.name if both are set; values from the proto resource win over env-var-derived ones on collision.
  • ResourceToContextKey(resource) returns a stable key from the (service.namespace, service.name, service.instance.id) triplet — described as globally unique by the semantic conventions. Used in ResourceKey for trace deduplication grouping.
  • Info is documented as immutable after publication; the embedded *pcommon.Resource is shared by pointer across the process-manager writer, the tracer event loop, and the reporter, and must be treated as read-only by all holders.

processmanager:

  • SynchronizeProcess defers the processcontext.Read until after GetProcessMeta, so env vars are available to merge in the same sync. readProcessContext returns (Info, publish bool): false preserves the previously-published context on transient ErrNoUpdate/ErrConcurrentUpdate, true publishes a new context.

Behaviour notes

  • Processes without an OTEL_CTX mapping are unchanged: Info.Resource stays nil, ContextKey == NullString, and bucketing falls back to the existing PID/container/executable keys.
  • Env-var-only fallback: a process that sets OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES but doesn't publish a ProcessContext mapping still gets a Resource derived from those env vars.
  • setResourceAttributes copies the process context attributes onto the emitted ResourceProfiles. eBPF-derived process.pid, container.id, and process.executable.* are added on top. APMServiceName, when set, takes precedence over the process context supplied service.name. This override is transitional and APMServiceName should be removed once ProcessContext is the canonical source of service identity.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d31f5fdb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread processmanager/processinfo.go Outdated
Comment thread processcontext/processcontext.go Outdated
@nsavoire nsavoire force-pushed the nsavoire/context_propagation branch from 5d31f5f to 777db74 Compare April 7, 2026 16:45
@nsavoire nsavoire requested a review from a team April 7, 2026 16:50
@nsavoire nsavoire changed the title Propagate process context to profiles feat: Propagate process context to profiles Apr 7, 2026
@nsavoire nsavoire force-pushed the nsavoire/context_propagation branch from 777db74 to 4075fdb Compare April 10, 2026 20:22
@nsavoire nsavoire changed the base branch from nsavoire/otel_thread_context_dd to nsavoire/otel_process_context_dd April 10, 2026 20:22
@nsavoire nsavoire force-pushed the nsavoire/context_propagation branch from 4075fdb to e13e762 Compare May 5, 2026 22:01
@nsavoire nsavoire changed the base branch from nsavoire/otel_process_context_dd to datadog May 5, 2026 22:11
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 14 days.

nsavoire added 5 commits June 29, 2026 11:40
Also refactor function to make it more readable and merge env variables
in even when there is an error reading the process context.

(cherry picked from commit 82d2fda)
…anager.New always add them to

includeEnvVars

(cherry picked from commit b4d8816)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant