Skip to content

Commit

Permalink
[otlp] Custom serialzer resource tweaks (open-telemetry#5947)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Nov 4, 2024
1 parent 47aff62 commit 53b85ce
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static int WriteResource(byte[] buffer, int writePosition, Resource? re
isServiceNamePresent = true;
}

otlpTagWriterState = ProcessResourceAttribute(ref otlpTagWriterState, attribute);
ProcessResourceAttribute(ref otlpTagWriterState, attribute);
}
}
else
Expand All @@ -49,14 +49,14 @@ internal static int WriteResource(byte[] buffer, int writePosition, Resource? re
isServiceNamePresent = true;
}

otlpTagWriterState = ProcessResourceAttribute(ref otlpTagWriterState, attribute);
ProcessResourceAttribute(ref otlpTagWriterState, attribute);
}
}
}

if (!isServiceNamePresent)
{
otlpTagWriterState = ProcessResourceAttribute(ref otlpTagWriterState, new KeyValuePair<string, object>(ResourceSemanticConventions.AttributeServiceName, DefaultServiceName));
ProcessResourceAttribute(ref otlpTagWriterState, new KeyValuePair<string, object>(ResourceSemanticConventions.AttributeServiceName, DefaultServiceName));
}

var resourceLength = otlpTagWriterState.WritePosition - (resourceLengthPosition + ReserveSizeForLength);
Expand All @@ -65,7 +65,7 @@ internal static int WriteResource(byte[] buffer, int writePosition, Resource? re
return otlpTagWriterState.WritePosition;
}

private static ProtobufOtlpTagWriter.OtlpTagWriterState ProcessResourceAttribute(ref ProtobufOtlpTagWriter.OtlpTagWriterState otlpTagWriterState, KeyValuePair<string, object> attribute)
private static void ProcessResourceAttribute(ref ProtobufOtlpTagWriter.OtlpTagWriterState otlpTagWriterState, KeyValuePair<string, object> attribute)
{
otlpTagWriterState.WritePosition = ProtobufSerializer.WriteTag(otlpTagWriterState.Buffer, otlpTagWriterState.WritePosition, ProtobufOtlpTraceFieldNumberConstants.Resource_Attributes, ProtobufWireType.LEN);
int resourceAttributesLengthPosition = otlpTagWriterState.WritePosition;
Expand All @@ -75,6 +75,5 @@ private static ProtobufOtlpTagWriter.OtlpTagWriterState ProcessResourceAttribute

var resourceAttributesLength = otlpTagWriterState.WritePosition - (resourceAttributesLengthPosition + ReserveSizeForLength);
ProtobufSerializer.WriteReservedLength(otlpTagWriterState.Buffer, resourceAttributesLengthPosition, resourceAttributesLength);
return otlpTagWriterState;
}
}

0 comments on commit 53b85ce

Please sign in to comment.