[otlp] Update changelog / Remove OtlpExporter resource modification code (#6015)

Co-authored-by: Mikel Blanchard <mblanchard@macrosssoftware.com>
This commit is contained in:
Rajkumar Rangaraj 2024-12-10 13:23:31 -08:00 committed by GitHub
parent be8209987b
commit 75a683eab7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 28 deletions

View File

@ -7,6 +7,32 @@ Notes](../../RELEASENOTES.md).
## Unreleased
* Removed the following package references:
* `Google.Protobuf`
* `Grpc`
* `Grpc.Net.Client`
These changes were made to streamline dependencies and reduce the footprint of
the exporter.
([#6005](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6005))
* Switched from using the `Google.Protobuf` library for serialization to a
custom manual implementation of protobuf serialization.
([#6005](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6005))
* Fixed an issue where a `service.name` was added to the resource if it was
missing. The exporter now respects the resource data provided by the SDK
without modifications.
([#6015](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6015))
* Removed the peer service resolver, which was based on earlier experimental
semantic conventions that are not part of the stable specification. This
change ensures that the exporter no longer modifies or assumes the value of
peer service attributes, aligning it more closely with OpenTelemetry protocol
specifications.
([#6005](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6005))
## 1.10.0
Released 2024-Nov-12

View File

@ -9,9 +9,6 @@ internal static class ProtobufOtlpResourceSerializer
{
private const int ReserveSizeForLength = 4;
private static readonly string DefaultServiceName = ResourceBuilder.CreateDefault().Build().Attributes.FirstOrDefault(
kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName).Value as string ?? "unknown_service";
internal static int WriteResource(byte[] buffer, int writePosition, Resource? resource)
{
ProtobufOtlpTagWriter.OtlpTagWriterState otlpTagWriterState = new ProtobufOtlpTagWriter.OtlpTagWriterState
@ -24,41 +21,24 @@ internal static class ProtobufOtlpResourceSerializer
int resourceLengthPosition = otlpTagWriterState.WritePosition;
otlpTagWriterState.WritePosition += ReserveSizeForLength;
bool isServiceNamePresent = false;
if (resource != null && resource != Resource.Empty)
{
if (resource.Attributes is IReadOnlyList<KeyValuePair<string, object>> resourceAttributesList)
{
for (int i = 0; i < resourceAttributesList.Count; i++)
{
var attribute = resourceAttributesList[i];
if (attribute.Key == ResourceSemanticConventions.AttributeServiceName)
{
isServiceNamePresent = true;
}
ProcessResourceAttribute(ref otlpTagWriterState, attribute);
ProcessResourceAttribute(ref otlpTagWriterState, resourceAttributesList[i]);
}
}
else
{
foreach (var attribute in resource.Attributes)
{
if (attribute.Key == ResourceSemanticConventions.AttributeServiceName)
{
isServiceNamePresent = true;
}
ProcessResourceAttribute(ref otlpTagWriterState, attribute);
}
}
}
if (!isServiceNamePresent)
{
ProcessResourceAttribute(ref otlpTagWriterState, new KeyValuePair<string, object>(ResourceSemanticConventions.AttributeServiceName, DefaultServiceName));
}
var resourceLength = otlpTagWriterState.WritePosition - (resourceLengthPosition + ReserveSizeForLength);
ProtobufSerializer.WriteReservedLength(otlpTagWriterState.Buffer, resourceLengthPosition, resourceLength);

View File

@ -173,7 +173,7 @@ public class OtlpHttpTraceExportClientTests
}
else
{
Assert.Contains(resourceSpan.Resource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:"));
Assert.DoesNotContain(resourceSpan.Resource.Attributes, kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName);
}
}
}

View File

@ -207,7 +207,7 @@ public class OtlpMetricsExporterTests : IDisposable
}
else
{
Assert.Contains(otlpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:"));
Assert.DoesNotContain(otlpResource.Attributes, kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName);
}
Assert.Single(resourceMetric.ScopeMetrics);
@ -943,9 +943,6 @@ public class OtlpMetricsExporterTests : IDisposable
Assert.Single(request.ResourceMetrics);
var resourceMetric = request.ResourceMetrics.First();
var otlpResource = resourceMetric.Resource;
Assert.Contains(otlpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:"));
Assert.Single(resourceMetric.ScopeMetrics);
var instrumentationLibraryMetrics = resourceMetric.ScopeMetrics.First();

View File

@ -43,7 +43,7 @@ public class OtlpResourceTests
}
else
{
Assert.Contains(otlpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:"));
Assert.DoesNotContain(otlpResource.Attributes, kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName);
}
}
}

View File

@ -184,7 +184,7 @@ public class OtlpTraceExporterTests
}
else
{
Assert.Contains(otlpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:"));
Assert.DoesNotContain(otlpResource.Attributes, kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName);
}
var scopeSpans = request.ResourceSpans.First().ScopeSpans;