[API] Skip exception formatting on unrecorded spans - #7669
Conversation
b9db024 to
c6e98ad
Compare
Pull request dashboard statusMerged · refreshed 2026-08-20 16:07 UTC Status above doesn't look right?
|
| return this; | ||
| } | ||
|
|
||
| if (!this.IsRecording) |
There was a problem hiding this comment.
Could this cause data to be lost if the value of Activity.IsAllDataRequested is changed later?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
Ah OK, if it's being thrown away by the things it calls anyway then I guess it's fine.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
….0 (#1316) Updated [OpenTelemetry.Exporter.OpenTelemetryProtocol](https://github.com/open-telemetry/opentelemetry-dotnet) from 1.17.0 to 1.18.0. <details> <summary>Release notes</summary> _Sourced from [OpenTelemetry.Exporter.OpenTelemetryProtocol's releases](https://github.com/open-telemetry/opentelemetry-dotnet/releases)._ ## 1.18.0 For highlights and announcements pertaining to this release see: [Release Notes > 1.18.0](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/RELEASENOTES.md#1180). The following changes are from the previous release [1.17.0](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/core-1.17.0). * NuGet: [OpenTelemetry v1.18.0](https://www.nuget.org/packages/OpenTelemetry/1.18.0) * Fixed self-diagnostics log lines being silently dropped when an event message or parameter contained enough 3-byte UTF-8 characters to overflow the internal buffer estimate. Such content is now truncated. ([#7543](open-telemetry/opentelemetry-dotnet#7543)) * Fixed activity creation throwing when multiple tracer providers return a sampler attribute with the same key. ([#7558](open-telemetry/opentelemetry-dotnet#7558)) * Added the `otel.sdk.processor.log.processed` SDK self-observability metric. ([#7486](open-telemetry/opentelemetry-dotnet#7486)) * Added the `otel.sdk.processor.span.processed` SDK self-observability metric. ([#7598](open-telemetry/opentelemetry-dotnet#7598)) * `BatchActivityExportProcessor` and `SimpleActivityExportProcessor` no longer forward spans to the exporter once `Shutdown` has been called, and `BatchActivityExportProcessor.Shutdown` now waits for in-flight `OnEnd` calls to finish enqueueing before flushing. ([#7598](open-telemetry/opentelemetry-dotnet#7598)) * Fix logger, meter and tracer providers leaking background threads if an exception is thrown by their constructor after resource creation. ([#7615](open-telemetry/opentelemetry-dotnet#7615)) * `CircularBufferBuckets.Copy` optimized to use bulk array copies. ([#7670](open-telemetry/opentelemetry-dotnet#7670)) * Restored configured `MaxScale` after delta exponential histogram collection. ([#7671](open-telemetry/opentelemetry-dotnet#7671)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0/src/OpenTelemetry/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api v1.18.0](https://www.nuget.org/packages/OpenTelemetry.Api/1.18.0) * Avoid formatting exceptions and creating exception attributes when `RecordException` is called on a span that is not recorded. ([#7669](open-telemetry/opentelemetry-dotnet#7669)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0/src/OpenTelemetry.Api/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api.ProviderBuilderExtensions v1.18.0](https://www.nuget.org/packages/OpenTelemetry.Api.ProviderBuilderExtensions/1.18.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0/src/OpenTelemetry.Api.ProviderBuilderExtensions/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.Console v1.18.0](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console/1.18.0) * Added support for serializing attribute values that are key/value lists (`IEnumerable<KeyValuePair<string, object?>>`). These attributes will be serialized as JSON objects. ([#7015](open-telemetry/opentelemetry-dotnet#7015)) ... (truncated) ## 1.18.0-rc.1 The following changes are from the previous release [1.17.0](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/core-1.17.0). * NuGet: [OpenTelemetry v1.18.0-rc.1](https://www.nuget.org/packages/OpenTelemetry/1.18.0-rc.1) * Fixed self-diagnostics log lines being silently dropped when an event message or parameter contained enough 3-byte UTF-8 characters to overflow the internal buffer estimate. Such content is now truncated. ([#7543](open-telemetry/opentelemetry-dotnet#7543)) * Fixed activity creation throwing when multiple tracer providers return a sampler attribute with the same key. ([#7558](open-telemetry/opentelemetry-dotnet#7558)) * Added the `otel.sdk.processor.log.processed` SDK self-observability metric. ([#7486](open-telemetry/opentelemetry-dotnet#7486)) * Added the `otel.sdk.processor.span.processed` SDK self-observability metric. ([#7598](open-telemetry/opentelemetry-dotnet#7598)) * `BatchActivityExportProcessor` and `SimpleActivityExportProcessor` no longer forward spans to the exporter once `Shutdown` has been called, and `BatchActivityExportProcessor.Shutdown` now waits for in-flight `OnEnd` calls to finish enqueueing before flushing. ([#7598](open-telemetry/opentelemetry-dotnet#7598)) * Fix logger, meter and tracer providers leaking background threads if an exception is thrown by their constructor after resource creation. ([#7615](open-telemetry/opentelemetry-dotnet#7615)) * `CircularBufferBuckets.Copy` optimized to use bulk array copies. ([#7670](open-telemetry/opentelemetry-dotnet#7670)) * Restored configured `MaxScale` after delta exponential histogram collection. ([#7671](open-telemetry/opentelemetry-dotnet#7671)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0-rc.1/src/OpenTelemetry/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api v1.18.0-rc.1](https://www.nuget.org/packages/OpenTelemetry.Api/1.18.0-rc.1) * Avoid formatting exceptions and creating exception attributes when `RecordException` is called on a span that is not recorded. ([#7669](open-telemetry/opentelemetry-dotnet#7669)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0-rc.1/src/OpenTelemetry.Api/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api.ProviderBuilderExtensions v1.18.0-rc.1](https://www.nuget.org/packages/OpenTelemetry.Api.ProviderBuilderExtensions/1.18.0-rc.1) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0-rc.1/src/OpenTelemetry.Api.ProviderBuilderExtensions/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.Console v1.18.0-rc.1](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console/1.18.0-rc.1) * Added support for serializing attribute values that are key/value lists (`IEnumerable<KeyValuePair<string, object?>>`). These attributes will be serialized as JSON objects. ([#7015](open-telemetry/opentelemetry-dotnet#7015)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.18.0-rc.1/src/OpenTelemetry.Exporter.Console/CHANGELOG.md) for details. ... (truncated) ## 1.18.0-beta.1 The following changes are from the previous release [1.17.0-beta.1](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/coreunstable-1.17.0-beta.1). * NuGet: [OpenTelemetry.Exporter.Prometheus.AspNetCore v1.18.0-beta.1](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.AspNetCore/1.18.0-beta.1) * Fix concurrent scrapes returning an empty response under contention. Now the exporter will return an HTTP 500 error instead. ([#7571](open-telemetry/opentelemetry-dotnet#7571)) * Waiting for concurrent scrapes to finish before collecting no longer blocks, which could stall concurrent scrapes being waited on. ([#7571](open-telemetry/opentelemetry-dotnet#7571)) * Fixed the interaction between `PrometheusAspNetCoreOptions.TranslationStrategy` and content negotiation. The configured strategy is now applied before content negotiation, instead of the negotiated escaping scheme replacing the strategy's, and the `Content-Type` header now reports the escaping scheme that was applied rather than the one that was negotiated. ([#7610](open-telemetry/opentelemetry-dotnet#7610)) * Fixed metric values and histogram bucket bounds being written with 17 significant digits instead of their shortest round-trippable representation. ([#7589](open-telemetry/opentelemetry-dotnet#7589)) * Fixed the canonical representation used for histogram `le` and summary `quantile` label values falling back to 17 significant digits incorrectly. ([#7589](open-telemetry/opentelemetry-dotnet#7589)) * Fixed a race where a slow scrape could return an HTTP 200 instead of 408. ([#7615](open-telemetry/opentelemetry-dotnet#7615)) * Updated OpenTelemetry core component version(s) to `1.18.0`. ([#7674](open-telemetry/opentelemetry-dotnet#7674)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/coreunstable-1.18.0-beta.1/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.Prometheus.HttpListener v1.18.0-beta.1](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.HttpListener/1.18.0-beta.1) * Fix concurrent scrapes returning an empty response under contention. Now the exporter will return an HTTP 500 error instead. ([#7571](open-telemetry/opentelemetry-dotnet#7571)) * Waiting for concurrent scrapes to finish before collecting no longer blocks, which could stall concurrent scrapes being waited on. ([#7571](open-telemetry/opentelemetry-dotnet#7571)) * A scrape which is still collecting when the listener is disposed now returns an HTTP 503 response. ([#7587](open-telemetry/opentelemetry-dotnet#7587)) * Shutting down the listener no longer waits indefinitely for its request processing loop to stop, and no longer throws if the loop faulted. ([#7587](open-telemetry/opentelemetry-dotnet#7587)) * Fixed the interaction between `PrometheusHttpListenerOptions.TranslationStrategy` and content negotiation. The configured strategy is now applied before content negotiation, instead of the negotiated escaping scheme replacing the strategy's, and the `Content-Type` header now reports the escaping scheme that was applied rather than the one that was negotiated. ([#7610](open-telemetry/opentelemetry-dotnet#7610)) * Fixed metric values and histogram bucket bounds being written with 17 significant digits instead of their shortest round-trippable representation. ([#7589](open-telemetry/opentelemetry-dotnet#7589)) * Fixed the canonical representation used for histogram `le` and summary `quantile` label values falling back to 17 significant digits incorrectly. ([#7589](open-telemetry/opentelemetry-dotnet#7589)) ... (truncated) Commits viewable in [compare view](open-telemetry/opentelemetry-dotnet@core-1.17.0...core-1.18.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Changes
Skips extracting and formatting exception fields, generating a stack trace, and creating span attributes when the span is not recorded.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes