Skip to content

Conversation

@kakkoyun
Copy link
Member

Signed-off-by: Kemal Akkoyun [email protected]

Consolidates stacktrace capture and formatting logic into the internal/stacktrace package, eliminating duplicate implementations across the codebase.

No functional behavior changes are intended. This is purely a refactoring effort.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Oct 22, 2025

Benchmarks

Benchmark execution time: 2025-10-22 16:06:51

Comparing candidate commit 8ba9e8b in PR branch kakkoyun/use_stacktrace_package with baseline commit d6f7d92 in branch main.

Found 1 performance improvements and 3 performance regressions! Performance is the same for 11 metrics, 0 unstable metrics.

scenario:BenchmarkCaptureStackTrace/10-24

  • 🟩 allocated_mem [-417 bytes; -409 bytes] or [-6.378%; -6.257%]

scenario:BenchmarkCaptureStackTrace/100-24

  • 🟥 allocated_mem [+4.030KB; +4.080KB] or [+9.269%; +9.386%]

scenario:BenchmarkCaptureStackTrace/200-24

  • 🟥 allocated_mem [+9.099KB; +9.267KB] or [+10.349%; +10.540%]

scenario:BenchmarkCaptureStackTrace/50-24

  • 🟥 allocated_mem [+1.793KB; +1.826KB] or [+7.954%; +8.097%]

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Oct 22, 2025

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8ba9e8b | Docs | Was this helpful? Give us feedback!

@kakkoyun kakkoyun force-pushed the kakkoyun/use_stacktrace_package branch from 22e894f to dfb0b1a Compare October 22, 2025 14:29
@kakkoyun
Copy link
Member Author

BenchmarkCaptureStackTrace

I will introduce subsequent PRs to improve this.

@kakkoyun kakkoyun marked this pull request as ready for review October 22, 2025 15:55
@kakkoyun kakkoyun requested review from a team as code owners October 22, 2025 15:55
Copy link
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

LGTM

}
// Use SkipAndCaptureUnfiltered to capture all frames including internal DD frames.
// +4 to account for: runtime.Callers, iterator, SkipAndCaptureUnfiltered, and this WrapN function
stack := stacktrace.CaptureRaw(int(skip) + 2)
Copy link
Member

Choose a reason for hiding this comment

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

@kakkoyun Are the comment and the actual value out of sync?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to update the comment, good catch. SkipAndCaptureUnfiltered doesn't exist anymore.

@kakkoyun
Copy link
Member Author

@codex review

Copy link

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

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.

ℹ️ 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 on lines +59 to +61
// Use SkipAndCaptureUnfiltered to capture all frames including internal DD frames.
// +4 to account for: runtime.Callers, iterator, SkipAndCaptureUnfiltered, and this WrapN function
stack := stacktrace.CaptureRaw(int(skip) + 2)

Choose a reason for hiding this comment

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

P1 Badge Honor skip parameter when wrapping errors

The new WrapN implementation always calls stacktrace.CaptureRaw(int(skip) + 2) before symbolication. Because the stack collection now has an extra wrapper (CaptureRaw) compared to the old direct runtime.Callers call, the caller’s requested skip is now off by one: skip=1 returns a stack that still starts at the first helper rather than the helper’s caller. This regresses behaviour for any code that relies on skip to remove wrapper functions (e.g. WrapN(err, 1) should report the frame that invoked the helper). The inline comment even says “+4 … and this WrapN function” but only +2 is applied, confirming the mismatch. To preserve existing semantics, the capture should skip WrapN itself as well (skip+3 or skip+4 as documented) so the first frame corresponds to the requested depth.

Useful? React with 👍 / 👎.

@kakkoyun kakkoyun marked this pull request as draft October 23, 2025 13:05
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.

4 participants