-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[console] Switch to TagWriter for handling of tags/attributes (#5596)
- Loading branch information
1 parent
ee5e1e0
commit 49d70e0
Showing
7 changed files
with
104 additions
and
65 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
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
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
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
39 changes: 0 additions & 39 deletions
39
src/OpenTelemetry.Exporter.Console/Implementation/ConsoleTagTransformer.cs
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
src/OpenTelemetry.Exporter.Console/Implementation/ConsoleTagWriter.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,79 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#nullable enable | ||
|
||
using System.Diagnostics; | ||
using System.Text; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Exporter; | ||
|
||
internal sealed class ConsoleTagWriter : JsonStringArrayTagWriter<ConsoleTagWriter.ConsoleTag> | ||
{ | ||
private readonly Action<string, string> onUnsupportedTagDropped; | ||
|
||
public ConsoleTagWriter(Action<string, string> onUnsupportedTagDropped) | ||
{ | ||
Debug.Assert(onUnsupportedTagDropped != null, "onUnsupportedTagDropped was null"); | ||
|
||
this.onUnsupportedTagDropped = onUnsupportedTagDropped!; | ||
} | ||
|
||
public bool TryTransformTag(KeyValuePair<string, object?> tag, out KeyValuePair<string, string> result) | ||
{ | ||
ConsoleTag consoleTag = default; | ||
if (this.TryWriteTag(ref consoleTag, tag)) | ||
{ | ||
result = new KeyValuePair<string, string>(consoleTag.Key!, consoleTag.Value!); | ||
return true; | ||
} | ||
|
||
result = default; | ||
return false; | ||
} | ||
|
||
protected override void WriteIntegralTag(ref ConsoleTag consoleTag, string key, long value) | ||
{ | ||
consoleTag.Key = key; | ||
consoleTag.Value = value.ToString(); | ||
} | ||
|
||
protected override void WriteFloatingPointTag(ref ConsoleTag consoleTag, string key, double value) | ||
{ | ||
consoleTag.Key = key; | ||
consoleTag.Value = value.ToString(); | ||
} | ||
|
||
protected override void WriteBooleanTag(ref ConsoleTag consoleTag, string key, bool value) | ||
{ | ||
consoleTag.Key = key; | ||
consoleTag.Value = value ? "true" : "false"; | ||
} | ||
|
||
protected override void WriteStringTag(ref ConsoleTag consoleTag, string key, string value) | ||
{ | ||
consoleTag.Key = key; | ||
consoleTag.Value = value; | ||
} | ||
|
||
protected override void WriteArrayTag(ref ConsoleTag consoleTag, string key, ArraySegment<byte> arrayUtf8JsonBytes) | ||
{ | ||
consoleTag.Key = key; | ||
consoleTag.Value = Encoding.UTF8.GetString(arrayUtf8JsonBytes.Array!, 0, arrayUtf8JsonBytes.Count); | ||
} | ||
|
||
protected override void OnUnsupportedTagDropped( | ||
string tagKey, | ||
string tagValueTypeFullName) | ||
{ | ||
this.onUnsupportedTagDropped(tagKey, tagValueTypeFullName); | ||
} | ||
|
||
internal struct ConsoleTag | ||
{ | ||
public string? Key; | ||
|
||
public string? Value; | ||
} | ||
} |
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