Skip to content

feat: Add WithStackTrace option for tracer#8094

Open
AkselAllas wants to merge 3 commits intoopen-telemetry:mainfrom
AkselAllas:feat/add-withstacktrace-option-to-tracer
Open

feat: Add WithStackTrace option for tracer#8094
AkselAllas wants to merge 3 commits intoopen-telemetry:mainfrom
AkselAllas:feat/add-withstacktrace-option-to-tracer

Conversation

@AkselAllas
Copy link
Copy Markdown

@AkselAllas AkselAllas commented Mar 24, 2026

For me use case is that in order to be able to use error tracking software based off stackTraces, I want to be able to set stackTraces for all spans via a shared library, which does not need an additional callsite via e.g. http instrumentation via opentelemetry-go-contrib.

Extra context from here: https://cloud-native.slack.com/archives/C01NPAXACKT/p1765159082954469

@AkselAllas AkselAllas force-pushed the feat/add-withstacktrace-option-to-tracer branch from 39c68b1 to 9580f43 Compare March 24, 2026 14:11
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 72.22222% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.7%. Comparing base (e9449e3) to head (e35fbc6).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
sdk/trace/provider.go 70.5% 10 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8094     +/-   ##
=======================================
- Coverage   81.7%   81.7%   -0.1%     
=======================================
  Files        308     308             
  Lines      23655   23684     +29     
=======================================
+ Hits       19342   19358     +16     
- Misses      3930    3943     +13     
  Partials     383     383             
Files with missing lines Coverage Δ
sdk/trace/span.go 85.4% <100.0%> (ø)
sdk/trace/provider.go 84.0% <70.5%> (-2.5%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

Should we propose this at the spec level?

Comment thread sdk/trace/provider.go Outdated
})
}

// WithStackTrace configures the TracerProvider to capture a stack trace
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe something like WithAlwaysStackTrace() or something could make it clearer what this does.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Makes sense. Will do.

Comment thread sdk/trace/provider.go Outdated

// WithStackTrace configures the TracerProvider to capture a stack trace
// for all recorded errors and panics.
func WithStackTrace(b bool) TracerProviderOption {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking out loud: Do we want to be able to support anything else related to this? NeverStackTrace?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't see the benefit of NeverStackTrace.

This would not allow the user to set the stackTrace on some important code path 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some possible use-cases:

  • Your backend doesn't support stack traces
  • An instrumentation library you don't control is collecting too many stack traces and you want to disable it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added NeverStackTrace

@AkselAllas
Copy link
Copy Markdown
Author

Should we propose this at the spec level?

Perhaps. I know we will need something like this for Typescript and C# as well as we will want Datadog Error Tracking to work for that as well.

@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Can we ignore these 2 uncovered test lines?

image

These were uncovered before as well 🤔

Comment thread sdk/trace/trace_test.go Outdated
)
}

func TestProviderRecordErrorWithStackTrace(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this and the other test are mostly the same as the tests above them. If it makes sense, make these table-driven instead of separate tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried. Let's see.

@dashpole
Copy link
Copy Markdown
Contributor

Yes, don't worry about lines that weren't previously covered.

@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Can you re-approve CICD?

@AkselAllas AkselAllas requested a review from dashpole March 24, 2026 14:40
@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Fixed lint. Need CICD reapprove.

@AkselAllas AkselAllas force-pushed the feat/add-withstacktrace-option-to-tracer branch from 891812c to e35fbc6 Compare March 24, 2026 15:16
@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Sorry for lint issues. Was using wrong local golingci-lint instead of make lint. Should work now.

@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Seems ready for hopefully final review.

@AkselAllas
Copy link
Copy Markdown
Author

@dashpole What's the next step with this PR?

@dashpole
Copy link
Copy Markdown
Contributor

Everyone is at kubecon EU, so getting feedback from others will be slow. Given you intend to add this across languages, I would like to see this added to the specification (for agreement on naming and structure), stabilized, and added to the declarative configuration format before we add it to the public API for this repo.

If you need something sooner, we should change this PR to not make any public api changes, and use "feature" environment variables to enable the behavior (search the repository for "x.go" for examples).

@AkselAllas
Copy link
Copy Markdown
Author

@dashpole Thanks for the response!

I personally don't have a plan to implement this in all the languages.

I fully prefer getting this out asap, so I will go with the feature env vars approach 🙇

@dashpole
Copy link
Copy Markdown
Contributor

If it is implemented in more than one language, it is good to add it to the spec. Note that the env vars approach is designed for features that are experimental in the specification. If we add this to this repo as experimental, and there isn't interest in adding it to the specification and stabilizing it, then it will likely be removed in a future version.

@AkselAllas
Copy link
Copy Markdown
Author

AkselAllas commented Mar 31, 2026

On second thought, I think I would prefer to take the spec route.

Who submits this to spec? And how does the process look like?

@dashpole
Copy link
Copy Markdown
Contributor

Anyone can submit changes to the spec. Start with an issue in opentelemetry-specification describing your use-case. Propose a high level solution (what you would change in the spec) and list some alternatives you considered. The issue will get assigned a spec sponsor who can help you progress. Open a PR with the proposed spec change, and point to this PR (in otel-go) as your prototype. Make sure it is marked as in development, and has a row in the spec compliance matrix.

It can help to raise it at the Specification SIG meeting, but that isn't strictly necessary. You just need two approvals on the spec PR for it to merge. After that, we need experimental implementations in 3 languages, and wait for feedback. Then we stabilize the spec, and try to implement it everywhere.

@AkselAllas
Copy link
Copy Markdown
Author

Thanks for the response!

open-telemetry/opentelemetry-specification#5001

Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

@AkselAllas
Copy link
Copy Markdown
Author

@pellared Even with deprecation, the tracing events api will be usable for multiple years I assume? I would be fine with being able to use this feature for that amount of time.

@pellared
Copy link
Copy Markdown
Member

pellared commented Apr 8, 2026

@AkselAllas, we are not removing the Span Events API. However, since we are actively deprecating this area, it’s unlikely that OTel maintainers will support introducing new features related to it.

@AkselAllas
Copy link
Copy Markdown
Author

it’s unlikely that OTel maintainers will support introducing new features related to it

I still think it's a useful and simple feature to have. I am still in favor of continuing with this PR.

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.

3 participants