Skip to content

[instrumentation/errortrace] Improve error stack traces#3709

Merged
dd-mergequeue[bot] merged 24 commits into
mainfrom
hannahkm/errortrace
Jul 18, 2025
Merged

[instrumentation/errortrace] Improve error stack traces#3709
dd-mergequeue[bot] merged 24 commits into
mainfrom
hannahkm/errortrace

Conversation

@hannahkm

@hannahkm hannahkm commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Introduces a new errortrace package, which will set up the foundation for improving our error stack traces.

Motivation

Currently, errors on spans trace back to the SetTag and setTagError functions in the tracer, since that is where we identify the error and put it onto the span as a tag and/or metric. However, the error does not originate from those functions. To avoid confusion and to improve debugging in the Datadog UI, we want to fix our error stack traces to accurately represent where errors are coming from.

This PR is the second step in a series of PRs to fix stack traces. Previous PRs include work to set up new join points in Orchestrion.

LANGPLAT-160

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 golangci-lint run 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

pr-commenter Bot commented Jun 30, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-07-18 12:31:04

Comparing candidate commit 97e8988 in PR branch hannahkm/errortrace with baseline commit 1ed6164 in branch main.

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

Comment thread ddtrace/tracer/span.go
Comment thread instrumentation/errortrace/errortrace.go
Comment thread ddtrace/tracer/span_test.go
Comment thread ddtrace/tracer/span.go Outdated
Comment thread instrumentation/errortrace/errortrace.go
Comment thread instrumentation/errortrace/errortrace.go
return New(format)
case 1:
if _, ok := a[0].(*TracerError); ok {
format = strings.Replace(format, "%w", "%v", 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to the fmt documentation, "%w" is synonymous with "%v" aside from providing wrapping around errors.

@hannahkm hannahkm mentioned this pull request Jul 14, 2025
7 tasks
@hannahkm
hannahkm marked this pull request as ready for review July 16, 2025 14:34
@hannahkm
hannahkm requested review from a team as code owners July 16, 2025 14:34
@hannahkm hannahkm changed the title [WIP] Improve error stack traces [instrumentation/errortrace] Improve error stack traces Jul 16, 2025

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking great!

I have added some suggestions.

Comment thread ddtrace/tracer/span.go
case *errortrace.TracerError:
// instrumentation/errortrace approach
s.setMeta(ext.ErrorDetails, fmt.Sprintf("%+v", v))
if !cfg.noDebugStack {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[No need to handle in this PR] We need to propagate this flag to the instrumentation/errortrace, so that we don't attempt any stack capture.

Comment thread instrumentation/errortrace/errortrace.go Outdated
Comment thread instrumentation/errortrace/errortrace.go Outdated
Comment thread instrumentation/errortrace/errortrace.go
hannahkm and others added 2 commits July 17, 2025 09:31
Comment thread instrumentation/errortrace/errortrace.go Outdated
@kakkoyun

Copy link
Copy Markdown
Member

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Jul 18, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-07-18 13:36:36 UTC ℹ️ Start processing command /merge


2025-07-18 13:36:49 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 13m (p90).


2025-07-18 13:46:27 UTC ℹ️ MergeQueue: This merge request was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants