Skip to content

Commit

Permalink
Merge branch 'main' into remove-redundant-isDisposing-pattern-in-Stre…
Browse files Browse the repository at this point in the history
…ssTest
  • Loading branch information
rajkumar-rangaraj authored Feb 6, 2025
2 parents d8da66c + c99f9a1 commit fffeeab
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private IEnumerable<string> ExtractTraceContextFromBasicProperties(IBasicPropert
{
if (props.Headers.TryGetValue(key, out var value))
{
var bytes = value as byte[];
var bytes = (byte[])value;
return new[] { Encoding.UTF8.GetString(bytes) };
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Notes](../../RELEASENOTES.md).
exports are correctly marked as successful.
([#6099](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6099))

* Fixed an issues causing trace exports to fail when
`Activity.StatusDescription` exceeds 127 bytes.
([#6119](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6119))

## 1.11.1

Released 2025-Jan-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ internal static int WriteSpanStatus(byte[] buffer, int position, Activity activi
{
var descriptionSpan = description.AsSpan();
var numberOfUtf8CharsInString = ProtobufSerializer.GetNumberOfUtf8CharsInString(descriptionSpan);
position = ProtobufSerializer.WriteTagAndLength(buffer, position, numberOfUtf8CharsInString + 4, ProtobufOtlpTraceFieldNumberConstants.Span_Status, ProtobufWireType.LEN);
var serializedLengthSize = ProtobufSerializer.ComputeVarInt64Size((ulong)numberOfUtf8CharsInString);

// length = numberOfUtf8CharsInString + Status_Message tag size + serializedLengthSize field size + Span_Status tag size + Span_Status length size.
position = ProtobufSerializer.WriteTagAndLength(buffer, position, numberOfUtf8CharsInString + 1 + serializedLengthSize + 2, ProtobufOtlpTraceFieldNumberConstants.Span_Status, ProtobufWireType.LEN);
position = ProtobufSerializer.WriteStringWithTag(buffer, position, ProtobufOtlpTraceFieldNumberConstants.Status_Message, numberOfUtf8CharsInString, descriptionSpan);
}
else
Expand Down
11 changes: 4 additions & 7 deletions src/OpenTelemetry/Logs/LoggerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

// Wait for up to 5 seconds grace period
this.Processor?.Shutdown(5000);
this.Processor?.Dispose();
Expand Down
11 changes: 4 additions & 7 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

// Wait for up to 5 seconds grace period
this.reader?.Shutdown(5000);
this.reader?.Dispose();
Expand Down
25 changes: 9 additions & 16 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,14 @@ internal bool OnForceFlush(int timeoutMilliseconds)
internal bool OnShutdown(int timeoutMilliseconds)
{
// TO DO Put OnShutdown logic in a task to run within the user provider timeOutMilliseconds
bool? result;
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

result = this.processor?.Shutdown(timeoutMilliseconds);
this.instrumentations.Clear();

bool? result = this.processor?.Shutdown(timeoutMilliseconds);
this.listener?.Dispose();
return result ?? true;
}
Expand All @@ -374,16 +370,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

(this.sampler as IDisposable)?.Dispose();

// Wait for up to 5 seconds grace period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1;
using OtlpCommon = OpenTelemetry.Proto.Common.V1;
using OtlpTrace = OpenTelemetry.Proto.Trace.V1;
using Status = OpenTelemetry.Trace.Status;

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;

Expand Down Expand Up @@ -500,7 +499,7 @@ public void ToOtlpSpanTest()

Assert.NotNull(childActivity);

childActivity.SetStatus(ActivityStatusCode.Error);
childActivity.SetStatus(ActivityStatusCode.Error, new string('a', 150));

var childEvents = new List<ActivityEvent> { new("e0"), new("e1", default, new ActivityTagsCollection(attributes)) };
childActivity.AddEvent(childEvents[0]);
Expand All @@ -521,7 +520,7 @@ public void ToOtlpSpanTest()
Assert.NotNull(otlpSpan.Status);
Assert.Equal(OtlpTrace.Status.Types.StatusCode.Error, otlpSpan.Status.Code);

Assert.Equal(Status.Error.Description ?? string.Empty, otlpSpan.Status.Message);
Assert.Equal(childActivity.StatusDescription ?? string.Empty, otlpSpan.Status.Message);
Assert.Empty(otlpSpan.Attributes);

Assert.Equal(childEvents.Count, otlpSpan.Events.Count);
Expand Down Expand Up @@ -572,6 +571,7 @@ public void ToOtlpSpanActivitiesWithNullArrayTest()
[InlineData(ActivityStatusCode.Unset, "Description will be ignored if status is Unset.")]
[InlineData(ActivityStatusCode.Ok, "Description will be ignored if status is Okay.")]
[InlineData(ActivityStatusCode.Error, "Description will be kept if status is Error.")]
[InlineData(ActivityStatusCode.Error, "150 Character String - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
public void ToOtlpSpanNativeActivityStatusTest(ActivityStatusCode expectedStatusCode, string statusDescription)
{
using var activitySource = new ActivitySource(nameof(this.ToOtlpSpanTest));
Expand Down Expand Up @@ -645,6 +645,7 @@ void RunTest(SdkLimitOptions sdkOptions, Batch<Activity> batch)
[InlineData(StatusCode.Unset, "Unset", "Description will be ignored if status is Unset.")]
[InlineData(StatusCode.Ok, "Ok", "Description must only be used with the Error StatusCode.")]
[InlineData(StatusCode.Error, "Error", "Error description.")]
[InlineData(StatusCode.Error, "Error", "150 Character String - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
[Obsolete("Remove when ActivityExtensions status APIs are removed")]
public void ToOtlpSpanStatusTagTest(StatusCode expectedStatusCode, string statusCodeTagValue, string statusDescription)
{
Expand Down

0 comments on commit fffeeab

Please sign in to comment.