Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
26 changes: 26 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
rajkumar-rangaraj marked this conversation as resolved.
Show resolved Hide resolved

* Removed the peer service resolver, which was based on earlier experimental
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,41 +21,24 @@ internal static int WriteResource(byte[] buffer, int writePosition, Resource? re
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void RunTest(Batch<Activity> batch)
}
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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void ToOtlpResourceMetricsTest(bool includeServiceNameInResource)
}
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);
Expand Down Expand Up @@ -943,9 +943,6 @@ public void MetricsSerialization_ExpandsBufferForMetricsAndSerializes()

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ToOtlpResourceTest(bool includeServiceNameInResource)
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void RunTest(SdkLimitOptions sdkOptions, Batch<Activity> batch)
}
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;
Expand Down
Loading