feat: Add eBPF prctl monitor to detect late OTEL_CTX publication#1399
feat: Add eBPF prctl monitor to detect late OTEL_CTX publication#1399nsavoire wants to merge 3 commits into
Conversation
96b8db1 to
bdecf40
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bdecf40d60
ℹ️ 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".
| SEC("tracepoint/syscalls/sys_enter_prctl") | ||
| int tracepoint__sys_enter_prctl(struct sys_enter_prctl_ctx *ctx) |
There was a problem hiding this comment.
Move the resync trigger after prctl completes
When the target thread is preempted after this sys_enter_prctl hook sends the generic PID event, the agent can process the immediate trigger and re-read /proc/<pid>/maps before the kernel has actually applied PR_SET_VMA_ANON_NAME. In that case SynchronizeProcess still won't see [anon:OTEL_CTX], and report_pid has already ratelimited the PID, so the late context publication can be missed until some unrelated resync happens. Hooking syscall exit or otherwise deferring/retrying the resync avoids racing the VMA rename that this feature depends on.
Useful? React with 👍 / 👎.
Summary
Adds an eBPF tracepoint on
sys_enter_prctlthat detects when a tracked process names an anonymous VMA OTEL_CTX viaprctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, "OTEL_CTX"), and triggers a PID resynchronization so the newly-published process context mapping is observed without waiting for the nextSynchronizeProcess.Without this hook, a process that publishes its OTEL_CTX mapping after the profiler has already synchronized might never have its resource attributes attached to profiles since
SynchronizeProcessonly re-runs when the unwinder hits an unknown executable mapping, and OTEL_CTX is neither executable nor reachable from a stack.Implementation notes
op == PR_SET_VMAandarg2 == PR_SET_VMA_ANON_NAMEand checks that passed string is "OTEL_CTX".bpf.num_prctl_set_vma_otel_ctxcounts how often the resync hook fires./proc/PID/mapsto locate the OTEL_CTX mapping. Since the tracepoint already has the mapping's address and length, a future optimization could introduce a dedicated event type that hands those values directly toreadProcessContext, skipping the full/proc/PID/mapsre-parse.Note: this PR includes the commits from #1343 as a base, only the last commit (Add prctl monitor) is new to this PR. Reviewers should focus on that commit, the rest will go away once #1343 lands.