Skip to content

[API] Skip exception formatting on unrecorded spans - #7669

Merged
martincostello merged 3 commits into
open-telemetry:mainfrom
matt-hensley:matt-hensley/exception-record-check
Aug 20, 2026
Merged

martincostello merged 3 commits into
open-telemetry:mainfrom
matt-hensley:matt-hensley/exception-record-check

Conversation

@matt-hensley

@matt-hensley matt-hensley commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Skips extracting and formatting exception fields, generating a stack trace, and creating span attributes when the span is not recorded.

IsRecording = false Before After
RecordException(Exception) with deep stack 69.58 µs / 100,263 B 0.80 ns / 0 B
RecordException(string, string, string) 42.26 ns / 144 B 0.98 ns / 0 B

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions Bot added the pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package label Aug 20, 2026
@matt-hensley
matt-hensley force-pushed the matt-hensley/exception-record-check branch from b9db024 to c6e98ad Compare August 20, 2026 14:44
@matt-hensley
matt-hensley marked this pull request as ready for review August 20, 2026 14:44
@matt-hensley
matt-hensley requested a review from a team as a code owner August 20, 2026 14:44
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-20 16:07 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

return this;
}

if (!this.IsRecording)

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.

Could this cause data to be lost if the value of Activity.IsAllDataRequested is changed later?

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.

Though I did just spot this

The best practice for the library authors is not try to set this property. This property is automatically set when creating the Activity. The setter is useful only in the case of Activity objects created using the Activity constructor and want to override the default value. Activity objects created using StartActivity automatically have this property set to the right value.

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.

Yes, data could be lost, but that is already happening in some cases.

RecordException always attempts to set some attributes and following by a call to AddEvent - which does respect IsRecording.

https://github.com/open-telemetry/opentelemetry-dotnet/blob/coreunstable-1.17.0-beta.1/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs#L322

The wrapper already is checking IsRecording ater calling SetAttribute, AddEvent, or AddLink.

Terminal methods for each of those:
https://github.com/open-telemetry/opentelemetry-dotnet/blob/coreunstable-1.17.0-beta.1/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs#L355

In theory this aligns RecordException with the other methods, but it's possible the difference in handling is intentional.

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.

Ah OK, if it's being thrown away by the things it calls anyway then I guess it's fine.

@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.41%. Comparing base (c016b77) to head (900bc65).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry.Api/Trace/TelemetrySpan.cs 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7669      +/-   ##
==========================================
- Coverage   91.42%   91.41%   -0.01%     
==========================================
  Files         318      318              
  Lines       17707    17711       +4     
==========================================
+ Hits        16188    16190       +2     
- Misses       1519     1521       +2     
Flag Coverage Δ
unittests-Project-Experimental 91.49% <75.00%> (-0.04%) ⬇️
unittests-Project-Stable 91.40% <75.00%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry.Api/Trace/TelemetrySpan.cs 88.75% <75.00%> (-0.73%) ⬇️

... and 1 file with indirect coverage changes

@martincostello martincostello added this to the v1.18.0 milestone Aug 20, 2026
@martincostello
martincostello added this pull request to the merge queue Aug 20, 2026
Merged via the queue into open-telemetry:main with commit 551f6eb Aug 20, 2026
78 checks passed
This was referenced Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants