Skip to content

Commit

Permalink
Merge branch 'main' into remove-redundant-instrumentations-!=-null-ch…
Browse files Browse the repository at this point in the history
…ecks
  • Loading branch information
SimonCropp authored Jan 31, 2025
2 parents 220a6e5 + 0cfbf86 commit 4b34dbb
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ you're more than welcome to participate!

* [Alan West](https://github.com/alanwest), New Relic
* [Mikel Blanchard](https://github.com/CodeBlanch), Microsoft
* [Rajkumar Rangaraj](https://github.com/rajkumar-rangaraj), Microsoft

[Emeritus Maintainers](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#emeritus-maintainerapprovertriager):

Expand All @@ -248,7 +249,6 @@ you're more than welcome to participate!

* [Cijo Thomas](https://github.com/cijothomas), Microsoft
* [Piotr Kiełkowicz](https://github.com/Kielek), Splunk
* [Rajkumar Rangaraj](https://github.com/rajkumar-rangaraj), Microsoft

[Emeritus Approvers](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#emeritus-maintainerapprovertriager):

Expand Down
7 changes: 0 additions & 7 deletions examples/GrpcService/Services/GreeterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ namespace Examples.GrpcService;

public class GreeterService : Greeter.GreeterBase
{
private readonly ILogger<GreeterService> logger;

public GreeterService(ILogger<GreeterService> logger)
{
this.logger = logger;
}

public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
{
return Task.FromResult(new HelloReply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ namespace WebApi.Controllers;
[Route("[controller]")]
public class SendMessageController : ControllerBase
{
private readonly ILogger<SendMessageController> logger;
private readonly MessageSender messageSender;

public SendMessageController(ILogger<SendMessageController> logger, MessageSender messageSender)
public SendMessageController(MessageSender messageSender)
{
this.logger = logger;
this.messageSender = messageSender;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace OpenTelemetry.Exporter.Prometheus;
[ExportModes(ExportModes.Pull)]
internal sealed class PrometheusExporter : BaseExporter<Metric>, IPullMetricExporter
{
private Func<int, bool>? funcCollect;
private ExportFunc? funcExport;
private Resource? resource;
private bool disposed;

Expand All @@ -38,17 +36,9 @@ public PrometheusExporter(PrometheusExporterOptions options)
/// <summary>
/// Gets or sets the Collect delegate.
/// </summary>
public Func<int, bool>? Collect
{
get => this.funcCollect;
set => this.funcCollect = value;
}
public Func<int, bool>? Collect { get; set; }

internal ExportFunc? OnExport
{
get => this.funcExport;
set => this.funcExport = value;
}
internal ExportFunc? OnExport { get; set; }

internal Action? OnDispose { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ public void EnumerateTags(Activity activity)

private struct EventEnumerationState
{
public bool Created;

public PooledList<ZipkinAnnotation> Annotations;

public void EnumerateEvents(Activity activity)
Expand All @@ -257,7 +255,6 @@ public void EnumerateEvents(Activity activity)
if (enumerator.MoveNext())
{
this.Annotations = PooledList<ZipkinAnnotation>.Create();
this.Created = true;

do
{
Expand Down
6 changes: 2 additions & 4 deletions src/OpenTelemetry/Metrics/ExportModesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ namespace OpenTelemetry.Metrics;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ExportModesAttribute : Attribute
{
private readonly ExportModes supportedExportModes;

/// <summary>
/// Initializes a new instance of the <see cref="ExportModesAttribute"/> class.
/// </summary>
/// <param name="supported"><see cref="ExportModes"/>.</param>
public ExportModesAttribute(ExportModes supported)
{
this.supportedExportModes = supported;
this.Supported = supported;
}

/// <summary>
/// Gets the supported <see cref="ExportModes"/>.
/// </summary>
public ExportModes Supported => this.supportedExportModes;
public ExportModes Supported { get; }
}
5 changes: 2 additions & 3 deletions src/OpenTelemetry/ReadOnlyFilteredTagCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public readonly struct ReadOnlyFilteredTagCollection
private readonly HashSet<string>? excludedKeys;
#endif
private readonly KeyValuePair<string, object?>[] tags;
private readonly int count;

internal ReadOnlyFilteredTagCollection(
#if NET
Expand All @@ -38,7 +37,7 @@ internal ReadOnlyFilteredTagCollection(

this.excludedKeys = excludedKeys;
this.tags = tags;
this.count = count;
this.MaximumCount = count;
}

/// <summary>
Expand All @@ -48,7 +47,7 @@ internal ReadOnlyFilteredTagCollection(
/// Note: Enumerating the collection may return fewer results depending on
/// the filter.
/// </remarks>
internal int MaximumCount => this.count;
internal int MaximumCount { get; }

/// <summary>
/// Returns an enumerator that iterates through the tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,32 @@

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;

public class OtlpHttpTraceExportClientTests
public sealed class OtlpHttpTraceExportClientTests : IDisposable
{
private static readonly SdkLimitOptions DefaultSdkLimitOptions = new();

private readonly ActivityListener activityListener;

static OtlpHttpTraceExportClientTests()
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
}

var listener = new ActivityListener
public OtlpHttpTraceExportClientTests()
{
this.activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllDataAndRecorded,
};

ActivitySource.AddActivityListener(listener);
ActivitySource.AddActivityListener(this.activityListener);
}

public void Dispose()
{
this.activityListener.Dispose();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.Implementation.Serializer;

public class OtlpArrayTagWriterTests : IDisposable
public sealed class OtlpArrayTagWriterTests : IDisposable
{
private readonly ProtobufOtlpTagWriter.OtlpArrayTagWriter arrayTagWriter;
private readonly ActivityListener activityListener;

static OtlpArrayTagWriterTests()
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;

var listener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(listener);
}

public OtlpArrayTagWriterTests()
{
this.arrayTagWriter = new ProtobufOtlpTagWriter.OtlpArrayTagWriter();
this.activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllDataAndRecorded,
};

ActivitySource.AddActivityListener(this.activityListener);
}

[Fact]
Expand Down Expand Up @@ -265,6 +265,7 @@ public void Dispose()
{
// Clean up the thread buffer after each test
ProtobufOtlpTagWriter.OtlpArrayTagWriter.ThreadBuffer = null;
this.activityListener.Dispose();
}

private static OtlpTrace.Span? ToOtlpSpan(SdkLimitOptions sdkOptions, Activity activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void WriteStringWithTag_ASCIIString_WritesCorrectly()
Assert.Equal(10, buffer[0]); // Tag
Assert.Equal(5, buffer[1]); // Length

byte[] expectedContent = Encoding.ASCII.GetBytes("Hello");
byte[] expectedContent = "Hello"u8.ToArray();
byte[] actualContent = new byte[5];
Array.Copy(buffer, 2, actualContent, 0, 5);
Assert.True(expectedContent.SequenceEqual(actualContent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,35 @@
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;

[Collection("xUnitCollectionPreventingTestsThatDependOnSdkConfigurationFromRunningInParallel")]
public class OtlpTraceExporterTests
public sealed class OtlpTraceExporterTests : IDisposable
{
private static readonly SdkLimitOptions DefaultSdkLimitOptions = new();

private static readonly ExperimentalOptions DefaultExperimentalOptions = new();

private readonly ActivityListener activityListener;

static OtlpTraceExporterTests()
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
}

var listener = new ActivityListener
public OtlpTraceExporterTests()
{
this.activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => options.Parent.TraceFlags.HasFlag(ActivityTraceFlags.Recorded)
? ActivitySamplingResult.AllDataAndRecorded
: ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(listener);
ActivitySource.AddActivityListener(this.activityListener);
}

public void Dispose()
{
this.activityListener.Dispose();
}

[Fact]
Expand Down
23 changes: 13 additions & 10 deletions test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenTelemetry.Exporter.Zipkin.Tests;

public class ZipkinExporterTests : IDisposable
public sealed class ZipkinExporterTests : IDisposable
{
private const string TraceId = "e8ea7e9ac72de94e91fabc613f9686b2";
private static readonly ConcurrentDictionary<Guid, string> Responses = new();
Expand All @@ -32,14 +32,6 @@ static ZipkinExporterTests()
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;

var listener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(listener);
}

public ZipkinExporterTests()
Expand Down Expand Up @@ -68,7 +60,6 @@ static void ProcessServerRequest(HttpListenerContext context)
public void Dispose()
{
this.testServer.Dispose();
GC.SuppressFinalize(this);
}

[Fact]
Expand Down Expand Up @@ -455,6 +446,16 @@ internal static Activity CreateTestActivity(
string? statusDescription = null,
DateTime? dateTime = null)
{
using var activityListener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => options.Parent.TraceFlags.HasFlag(ActivityTraceFlags.Recorded)
? ActivitySamplingResult.AllDataAndRecorded
: ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(activityListener);

var startTimestamp = DateTime.UtcNow;
var endTimestamp = startTimestamp.AddSeconds(60);
var eventTimestamp = DateTime.UtcNow;
Expand Down Expand Up @@ -532,6 +533,8 @@ internal static Activity CreateTestActivity(
links,
startTime: startTimestamp)!;

Assert.NotNull(activity);

if (addEvents)
{
foreach (var evnt in events)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Fixture()
this.listener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllDataAndRecorded,
};

ActivitySource.AddActivityListener(this.listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_EnoughSpace()

// '\n' will be appended to the original string "abc" after EncodeInBuffer is called.
// The byte where '\n' will be placed should not be touched within EncodeInBuffer, so it stays as '\0'.
byte[] expected = Encoding.UTF8.GetBytes("abc\0");
byte[] expected = "abc\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand All @@ -204,7 +204,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEnoughSpaceForFullStr
// It's a quick estimate by assumption that most Unicode characters takes up to 2 16-bit UTF-16 chars,
// which can be up to 4 bytes when encoded in UTF-8.
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);
byte[] expected = Encoding.UTF8.GetBytes("ab...\0");
byte[] expected = "ab...\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand All @@ -214,7 +214,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEvenSpaceForTruncated
byte[] buffer = new byte[20];
int startPos = buffer.Length - Ellipses.Length; // Just enough space for "...\n".
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);
byte[] expected = Encoding.UTF8.GetBytes("...\0");
byte[] expected = "...\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand All @@ -233,7 +233,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_EnoughSpace(
byte[] buffer = new byte[20];
int startPos = buffer.Length - EllipsesWithBrackets.Length - 6; // Just enough space for "abc" even if "...\n" need to be added.
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
byte[] expected = Encoding.UTF8.GetBytes("{abc}\0");
byte[] expected = "{abc}\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand All @@ -243,7 +243,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEnoughSpa
byte[] buffer = new byte[20];
int startPos = buffer.Length - EllipsesWithBrackets.Length - 5; // Just not space for "...\n".
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
byte[] expected = Encoding.UTF8.GetBytes("{ab...}\0");
byte[] expected = "{ab...}\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand All @@ -253,7 +253,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpace
byte[] buffer = new byte[20];
int startPos = buffer.Length - EllipsesWithBrackets.Length; // Just enough space for "{...}\n".
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
byte[] expected = Encoding.UTF8.GetBytes("{...}\0");
byte[] expected = "{...}\0"u8.ToArray();
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
}

Expand Down
Loading

0 comments on commit 4b34dbb

Please sign in to comment.