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

Azure Monitor OTel Exporter does not support array attributes on metrics #47262

Open
lmolkova opened this issue Nov 20, 2024 · 1 comment · May be fixed by #47300
Open

Azure Monitor OTel Exporter does not support array attributes on metrics #47262

lmolkova opened this issue Nov 20, 2024 · 1 comment · May be fixed by #47300
Labels
Client This issue points to a problem in the data-plane of the library. Monitor - Exporter Monitor OpenTelemetry Exporter

Comments

@lmolkova
Copy link
Member

lmolkova commented Nov 20, 2024

Try

using Azure.Monitor.OpenTelemetry.AspNetCore;
using System.Diagnostics;
using System.Diagnostics.Metrics;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddOpenTelemetry()
    .WithTracing(tp => tp.AddSource("test"))
    .WithMetrics(mp => mp.AddMeter("test"))
    .UseAzureMonitor(o => o.ConnectionString = "secret");

var app = builder.Build();

var test = new ActivitySource("test");
var testMeter = new Meter("test");
var testCounter = testMeter.CreateCounter<int>("this.is.a.test.counter");

app.MapGet("/", async () =>
{
    using var act = test.StartActivity("test me");
    act?.AddTag("array.attribute", new[] { 1, 2, 3 });
    testCounter.Add(1, new KeyValuePair<string, object?>("array.attribute", new[] { 1, 2, 3 }));
});

app.Run();

Array attribute on spans works fine, but is converted to string with ToString() on metrics here

Properties.Add(new KeyValuePair<string, string>(tag.Key, tag.Value.ToString().Truncate(SchemaConstants.MetricsData_Properties_MaxValueLength) ?? "null"));

Image

The suggestion is to do it consistently (comma separated list).

context: open-telemetry/semantic-conventions#1525
use-case: as a user I might want to filter my metrics checking if array attribute contains a specific value among others.

@lmolkova lmolkova added the Monitor - Exporter Monitor OpenTelemetry Exporter label Nov 20, 2024
@lmolkova
Copy link
Member Author

Seems to violate common schema mappings:

Mapping OpenTelemetry Attributes to properties: If attribute value is of primitive type array, then the property value should be a comma-separated array elements.

https://msazure.visualstudio.com/One/_git/CommonSchema?path=/v4.0/Mappings/AzureMonitor-AI.md&version=GBmain&line=50&lineEnd=53&lineStartColumn=1&lineEndColumn=69&lineStyle=plain&_a=contents

@jsquire jsquire added the Client This issue points to a problem in the data-plane of the library. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Monitor - Exporter Monitor OpenTelemetry Exporter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants