Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OpenTelemetry.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<File Path="docs/diagnostics/experimental-apis/OTEL1000.md" />
<File Path="docs/diagnostics/experimental-apis/OTEL1001.md" />
<File Path="docs/diagnostics/experimental-apis/OTEL1004.md" />
<File Path="docs/diagnostics/experimental-apis/OTEL1005.md" />
<File Path="docs/diagnostics/experimental-apis/README.md" />
</Folder>
<Folder Name="/docs/logs/">
Expand Down
2 changes: 1 addition & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<NuGetAuditMode>all</NuGetAuditMode>
<NuGetAuditLevel>low</NuGetAuditLevel>
<!-- Suppress warnings for repo code using experimental features -->
<NoWarn>$(NoWarn);OTEL1000;OTEL1001;OTEL1002;OTEL1004</NoWarn>
<NoWarn>$(NoWarn);OTEL1000;OTEL1001;OTEL1002;OTEL1004;OTEL1005</NoWarn>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

Expand Down
18 changes: 18 additions & 0 deletions docs/diagnostics/experimental-apis/OTEL1005.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# OpenTelemetry .NET Diagnostic: OTEL1005

## Overview

This is an experimental API for allowing spans to always be recorded.

### Details

#### AlwaysRecordSampler

TODO: Explanation.
Copy link
Member

Choose a reason for hiding this comment

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

Needs some real data here.


**Parameters:**

* TODO: Details
* `span` - a read/write span object for the span which is about to be ended.

**Returns:** `TODO`
6 changes: 6 additions & 0 deletions docs/diagnostics/experimental-apis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Description: ExemplarReservoir Support

Details: [OTEL1004](./OTEL1004.md)

### OTEL1005

Description: AlwaysRecordSampler implementation for recording all spans

Details: [OTEL1005](./OTEL1005.md)

## Inactive

Experimental APIs which have been released stable or removed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ OpenTelemetry.Metrics.MetricStreamConfiguration.ExemplarReservoirFactory.set ->
[OTEL1000]static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.UseOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, System.Action<OpenTelemetry.Logs.LoggerProviderBuilder!>? configureBuilder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>? configureOptions) -> Microsoft.Extensions.Logging.ILoggingBuilder!
[OTEL1001]static OpenTelemetry.Sdk.CreateLoggerProviderBuilder() -> OpenTelemetry.Logs.LoggerProviderBuilder!
[OTEL1004]virtual OpenTelemetry.Metrics.FixedSizeExemplarReservoir.OnCollected() -> void
[OTEL1005]OpenTelemetry.Trace.AlwaysRecordSampler
[OTEL1005]static OpenTelemetry.Trace.AlwaysRecordSampler.Create(OpenTelemetry.Trace.Sampler! rootSampler) -> OpenTelemetry.Trace.AlwaysRecordSampler!
[OTEL1005]override OpenTelemetry.Trace.AlwaysRecordSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Notes](../../RELEASENOTES.md).
* Added support for `Meter.TelemetrySchemaUrl` property.
([#6714](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6714))

* Added `AlwaysRecordSampler`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Added `AlwaysRecordSampler`.
* **Experimental (pre-release builds only):** Added `AlwaysRecordSampler`.

([#6732](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6732))

## 1.14.0

Released 2025-Nov-12
Expand Down
70 changes: 70 additions & 0 deletions src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Includes work from:
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#if EXPOSE_EXPERIMENTAL_FEATURES
using System.Diagnostics.CodeAnalysis;
#endif
using OpenTelemetry.Internal;

namespace OpenTelemetry.Trace;

#if EXPOSE_EXPERIMENTAL_FEATURES
/// <summary>
/// This sampler will return the sampling result of the provided rootSampler, unless the
/// sampling result contains the sampling decision <see cref="SamplingDecision.Drop"/>, in which case, a
/// new sampling result will be returned that is functionally equivalent to the original, except that
/// it contains the sampling decision <see cref="SamplingDecision.RecordOnly"/>. This ensures that all
/// spans are recorded, with no change to sampling.
///
/// The intended use case of this sampler is to provide a means of sending all spans to a
/// processor without having an impact on the sampling rate. This may be desirable if a user wishes
/// to count or otherwise measure all spans produced in a service, without incurring the cost of 100%
/// sampling.
/// </summary>
[Experimental(DiagnosticDefinitions.AlwaysRecordSamplerExperimentalApi, UrlFormat = DiagnosticDefinitions.ExperimentalApiUrlFormat)]
public
#else
internal
#endif
sealed class AlwaysRecordSampler : Sampler
{
private readonly Sampler rootSampler;

private AlwaysRecordSampler(Sampler rootSampler)
{
this.rootSampler = rootSampler;
this.Description = "AlwaysRecordSampler{" + rootSampler.Description + "}";
}

/// <summary>
/// Method to create an AlwaysRecordSampler.
/// </summary>
/// <param name="rootSampler"><see cref="Sampler"/>rootSampler to create AlwaysRecordSampler from.</param>
/// <returns>Created AlwaysRecordSampler.</returns>
public static AlwaysRecordSampler Create(Sampler rootSampler)
{
Guard.ThrowIfNull(rootSampler);
return new AlwaysRecordSampler(rootSampler);

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (ubuntu-22.04-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check warning on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'.

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-11-arm, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-solution / build-test (windows-latest, net9.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net8.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net10.0)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

Check failure on line 51 in src/OpenTelemetry/Trace/Sampler/AlwaysRecordSampler.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-11-arm, net462)

In externally visible method 'AlwaysRecordSampler AlwaysRecordSampler.Create(Sampler rootSampler)', validate parameter 'rootSampler' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

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

The same problem we have in the ParentBasedSample

Suggested change
Guard.ThrowIfNull(rootSampler);
return new AlwaysRecordSampler(rootSampler);
Guard.ThrowIfNull(rootSampler);
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
return new AlwaysRecordSampler(rootSampler);
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1

}

/// <inheritdoc/>
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
SamplingResult result = this.rootSampler.ShouldSample(samplingParameters);
if (result.Decision == SamplingDecision.Drop)
{
result = WrapResultWithRecordOnlyResult(result);
}

return result;
}

private static SamplingResult WrapResultWithRecordOnlyResult(SamplingResult result)
{
return new SamplingResult(SamplingDecision.RecordOnly, result.Attributes, result.TraceStateString);
}
}
1 change: 1 addition & 0 deletions src/Shared/DiagnosticDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal static class DiagnosticDefinitions
public const string LoggerProviderExperimentalApi = "OTEL1000";
public const string LogsBridgeExperimentalApi = "OTEL1001";
public const string ExemplarReservoirExperimentalApi = "OTEL1004";
public const string AlwaysRecordSamplerExperimentalApi = "OTEL1005";

/* Definitions which have been released stable:
public const string ExemplarExperimentalApi = "OTEL1002";
Expand Down
95 changes: 95 additions & 0 deletions test/OpenTelemetry.Tests/Trace/AlwaysRecordSamplerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Includes work from:
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using OpenTelemetry.Tests;
using Xunit;

namespace OpenTelemetry.Trace.Tests;

/// <summary>
/// AlwaysRecordSamplerTest test class.
/// </summary>
public class AlwaysRecordSamplerTests
{
/// <summary>
/// Tests Description is set properly with AlwaysRecordSampler keyword.
/// </summary>
[Fact]
public void TestGetDescription()
{
var testSampler = new TestSampler();
var sampler = AlwaysRecordSampler.Create(testSampler);
Assert.Equal("AlwaysRecordSampler{TestSampler}", sampler.Description);
}

/// <summary>
/// Test RECORD_AND_SAMPLE sampling decision.
/// </summary>
[Fact]
public void TestRecordAndSampleSamplingDecision()
{
ValidateShouldSample(SamplingDecision.RecordAndSample, SamplingDecision.RecordAndSample);
}

/// <summary>
/// Test RECORD_ONLY sampling decision.
/// </summary>
[Fact]
public void TestRecordOnlySamplingDecision()
{
ValidateShouldSample(SamplingDecision.RecordOnly, SamplingDecision.RecordOnly);
}

/// <summary>
/// Test DROP sampling decision.
/// </summary>
[Fact]
public void TestDropSamplingDecision()
{
ValidateShouldSample(SamplingDecision.Drop, SamplingDecision.RecordOnly);
}

private static SamplingResult BuildRootSamplingResult(SamplingDecision samplingDecision)
{
ActivityTagsCollection? attributes = new ActivityTagsCollection
{
{ "key", samplingDecision.GetType().Name },
};
string traceState = samplingDecision.GetType().Name;
#pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
return new SamplingResult(samplingDecision, attributes, traceState);
#pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
}

private static void ValidateShouldSample(
SamplingDecision rootDecision, SamplingDecision expectedDecision)
{
SamplingResult rootResult = BuildRootSamplingResult(rootDecision);
var testSampler = new TestSampler { SamplingAction = _ => rootResult };
var sampler = AlwaysRecordSampler.Create(testSampler);

SamplingParameters samplingParameters = new SamplingParameters(
default, default, "name", ActivityKind.Client, new ActivityTagsCollection(), new List<ActivityLink>());

SamplingResult actualResult = sampler.ShouldSample(samplingParameters);

if (rootDecision.Equals(expectedDecision))
{
Assert.True(actualResult.Equals(rootResult));
Assert.True(actualResult.Decision.Equals(rootDecision));
}
else
{
Assert.False(actualResult.Equals(rootResult));
Assert.True(actualResult.Decision.Equals(expectedDecision));
}

Assert.Equal(rootResult.Attributes, actualResult.Attributes);
Assert.Equal(rootDecision.GetType().Name, actualResult.TraceStateString);
}
}
Loading