-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zipkin] Switch to TagWriter for handling of tags/attributes (#5590)
- Loading branch information
1 parent
ac0d1d1
commit 2fe54ee
Showing
4 changed files
with
75 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinTagTransformer.cs
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinTagWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#nullable enable | ||
|
||
using System.Buffers.Text; | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Exporter.Zipkin.Implementation; | ||
|
||
internal sealed class ZipkinTagWriter : JsonStringArrayTagWriter<Utf8JsonWriter> | ||
{ | ||
public const int StackallocByteThreshold = 256; | ||
|
||
private ZipkinTagWriter() | ||
{ | ||
} | ||
|
||
public static ZipkinTagWriter Instance { get; } = new(); | ||
|
||
protected override void WriteIntegralTag(ref Utf8JsonWriter writer, string key, long value) | ||
{ | ||
Span<byte> destination = stackalloc byte[StackallocByteThreshold]; | ||
if (Utf8Formatter.TryFormat(value, destination, out int bytesWritten)) | ||
{ | ||
writer.WriteString(key, destination.Slice(0, bytesWritten)); | ||
} | ||
else | ||
{ | ||
writer.WriteString(key, value.ToString(CultureInfo.InvariantCulture)); | ||
} | ||
} | ||
|
||
protected override void WriteFloatingPointTag(ref Utf8JsonWriter writer, string key, double value) | ||
{ | ||
Span<byte> destination = stackalloc byte[StackallocByteThreshold]; | ||
if (Utf8Formatter.TryFormat(value, destination, out int bytesWritten)) | ||
{ | ||
writer.WriteString(key, destination.Slice(0, bytesWritten)); | ||
} | ||
else | ||
{ | ||
writer.WriteString(key, value.ToString(CultureInfo.InvariantCulture)); | ||
} | ||
} | ||
|
||
protected override void WriteBooleanTag(ref Utf8JsonWriter writer, string key, bool value) | ||
=> writer.WriteString(key, value ? "true" : "false"); | ||
|
||
protected override void WriteStringTag(ref Utf8JsonWriter writer, string key, string value) | ||
=> writer.WriteString(key, value); | ||
|
||
protected override void WriteArrayTag(ref Utf8JsonWriter writer, string key, ArraySegment<byte> arrayUtf8JsonBytes) | ||
{ | ||
writer.WritePropertyName(key); | ||
writer.WriteStringValue(arrayUtf8JsonBytes); | ||
} | ||
|
||
protected override void OnUnsupportedTagDropped( | ||
string tagKey, | ||
string tagValueTypeFullName) | ||
{ | ||
ZipkinExporterEventSource.Log.UnsupportedAttributeType( | ||
tagValueTypeFullName, | ||
tagKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters