Skip to content

fix(profiling): require --time-hint for flamegraph and profile-types trace scoping - #878

Draft
AlexJF wants to merge 3 commits into
DataDog:mainfrom
AlexJF:fix/profiling-trace-time-hint
Draft

AlexJF wants to merge 3 commits into
DataDog:mainfrom
AlexJF:fix/profiling-trace-time-hint

Conversation

@AlexJF

@AlexJF AlexJF commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes --trace-id scoping for pup profiling explore flamegraph and pup profiling profile-types list.

The backend's traceContext requires traceId, spanId and timeHint (epoch seconds) together, and rejects a null timeHint with a 400. Since #819, pup sent timeHint: null and didn't require --span-id, so both commands failed whenever they were scoped by trace.

Motivation

Found while adding call graph (#876) and timeline (#877) exploration. Both have the same traceContext contract, and #876 applies this fix for call graph.

Additional Notes

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

Fixes trace scoping from #819. Depends on #876.

Plan
# Fix: require --time-hint for profiling trace scoping (flamegraph, profile-types)

Spun off from PROF-16039 (timeline exploration). Full cross-repo plan:
/home/bits/.claude/plans/lets-work-on-https-datadoghq-atlassian-n-nested-dragon.md

## Context

prof-viz-java's `TraceContext` record marks `traceId`, `spanId` and `timeHint` as `@NotEmpty`, and
`FlameGraphExplorationRequest`/`ProfileTypesRequest` validate it (`@Valid`). pup (since #819) sent
`timeHint: null` and didn't require `--span-id`, so `pup profiling explore flamegraph --trace-id`
and `pup profiling profile-types list --trace-id` were rejected with a 400. The backend parses
`timeHint` as epoch seconds (or millis), matching the MCP tool contract.

The same fix landed for callgraph in #876, which introduced the shared `trace_context_json`
helper (validates the three flags together, converts `--time-hint` from any pup time format to
epoch seconds). This branch is **stacked on #876** to reuse that helper.

## Changes

- `src/commands/profiling.rs`: `profile_types_list` and `explore_flamegraph` take `time_hint` and
  build `traceContext` via `trace_context_json`.
- `src/main.rs`: `--time-hint` on `profiling profile-types list` and `profiling explore flamegraph`.
- Tests: profile-types trace-context test now asserts `timeHint`; new flamegraph trace-context
  body test; existing call sites updated.
- `docs/EXAMPLES.md`: profile-types trace example passes `--time-hint`.

## Status

- [x] Worktree `.claude/worktrees/fix-profiling-trace-time-hint`, branch
      `fix/profiling-trace-time-hint` stacked on `feat/callgraph-exploration`
- [x] Implementation + tests + docs
- [x] fmt / clippy / `cargo test profiling::` — 40 pass
- [x] Commit + push to `origin`, draft PR into DataDog/pup:main
Prompts
# Prompts log — profiling trace time-hint fix (spun off from PROF-16039)

1. (PROF-16039 context) "Lets work on https://datadoghq.atlassian.net/browse/PROF-16039, following
   similar patterns to https://github.com/ddoghq/profiling-backend/pull/9070 and
   https://github.com/ddoghq/dd-source/pull/102914"
2. "Can't we sign with my personal SSH key, open a PR against my fork AlexJF/pup and open a draft PR
   from there to upstream?"
3. "try again"
4. Asked whether to open a separate fix PR for the same timeHint bug in merged flamegraph /
   profile-types trace scoping: "yes do"

🤖 Generated with Claude Code

AlexJF and others added 3 commits October 1, 2026 12:06
Add `pup profiling explore callgraph`, calling the new prof-gateway
/api/unstable/profiling/pup/explore/callgraph endpoint (PROF-16038).

- explore_callgraph in src/commands/profiling.rs, mirroring explore_flamegraph
  (query/trace/profile scoping, profile-id+event-id pairing validation)
- ProfilingExploreActions::Callgraph clap variant and dispatch in src/main.rs
- Tests for happy path, scoping/pairing validation, null optional fields,
  validation errors, and missing auth
- Call graph examples in docs/EXAMPLES.md and command listing in docs/COMMANDS.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backend's traceContext requires traceId, spanId and timeHint (epoch
seconds) together and rejects requests with a null timeHint, so
`--trace-id` scoping could never succeed.

- Add a shared trace_context_json helper that validates the three flags
  together and converts --time-hint (any pup time format) to epoch seconds
- Add --time-hint to `pup profiling explore callgraph`
- Tests for the helper and for the callgraph traceContext request body

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…trace scoping

The backend's traceContext requires traceId, spanId and timeHint (epoch
seconds) together and rejects a null timeHint, so `--trace-id` scoping on
`explore flamegraph` and `profile-types list` always failed validation.

- Build traceContext via the shared trace_context_json helper, which
  validates the three flags together and converts --time-hint to epoch
  seconds
- Add --time-hint to `profiling explore flamegraph` and
  `profiling profile-types list`
- Assert timeHint in the profile-types trace test; add a flamegraph
  trace-context request body test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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