-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AzureMonitorExporter] Fix how arrays stored in Activity Tags are ser…
…ialized. (#34086) * fix array tostring * cleanup
- Loading branch information
1 parent
94dd3d8
commit 5db3f5b
Showing
6 changed files
with
125 additions
and
26 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ArrayExtensions.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,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Text; | ||
|
||
namespace Azure.Monitor.OpenTelemetry.Exporter.Internals | ||
{ | ||
internal static class ArrayExtensions | ||
{ | ||
/// <summary> | ||
/// Builds a comma delimited string of the components of an array. | ||
/// </summary> | ||
/// <remarks> | ||
/// For example: new int[] { 1, 2, 3 } would be returned as "1,2,3". | ||
/// </remarks> | ||
/// <param name="input">An array to be evaluated.</param> | ||
/// <returns>A comma delimited string of the components of the input array.</returns> | ||
[return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] | ||
public static string? ToCommaDelimitedString(this Array? input) | ||
{ | ||
if (input == null) | ||
{ | ||
return null; | ||
} | ||
|
||
StringBuilder sb = new(input.Length); | ||
foreach (var item in input) | ||
{ | ||
// TODO: Consider changing it to JSon array. | ||
if (item != null) | ||
{ | ||
sb.Append(item); | ||
sb.Append(','); | ||
} | ||
} | ||
|
||
// remove trailing comma | ||
if (sb.Length > 0) | ||
{ | ||
sb.Length--; | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
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
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