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

[BUG] Azure.Monitor.OpenTelemetry.AspNetCore v1.2.0-beta.4 not using service.version resource attribute #44502

Closed
bgelens opened this issue Jun 11, 2024 · 6 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.

Comments

@bgelens
Copy link

bgelens commented Jun 11, 2024

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore v1.2.0-beta.4

Describe the bug

Azure.Monitor.OpenTelemetry.Exporter version 1.3.0 now supports providing the Application Version to Application Insights by making use of the service.version resource attribute #42174

Azure.Monitor.OpenTelemetry.AspNetCore v1.2.0-beta.4 has the correct dependency to make use of this however, no matter what I try to setup the service.version, it is in the end ignored when exported to application insights

Expected behavior

Application_Version to be populated for traces based on service.version resource attribute

Actual behavior

it is not

Reproduction Steps

add service.version to OTEL_RESOURCE_ATTRIBUTES environment variable or handle via a dictionary like:

var resourceAttributes = new Dictionary<string, object>
             {
                 { "service.name", "my-service" },
                 { "service.namespace", "my-namespace" },
                 { "service.instance.id", "my-instance" },
                 { "service.version", "1.0.0-demo" },
             };

var resourceBuilder = ResourceBuilder.CreateDefault().AddAttributes(resourceAttributes);

hook up normally with something like builder.Services.AddOpenTelemetry().UseAzureMonitor();

observe that application_version is never part of any traces.

Environment

.NET SDK:
Version: 8.0.301
Commit: 1a0e9c0300
Workload version: 8.0.300-manifests.011fccd5
MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.5
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.301/

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.6
Architecture: arm64
Commit: 3b8b000a0e

.NET SDKs installed:
6.0.422 [/usr/local/share/dotnet/sdk]
7.0.409 [/usr/local/share/dotnet/sdk]
8.0.205 [/usr/local/share/dotnet/sdk]
8.0.301 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.30 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.19 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.30 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@bgelens bgelens changed the title [BUG] [BUG] Azure.Monitor.OpenTelemetry.AspNetCore v1.2.0-beta.4 not using service.version resource attribute Jun 11, 2024
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 11, 2024
@jsquire jsquire added Service Attention This issue is responsible by Azure service team. Client This issue points to a problem in the data-plane of the library. needs-team-attention This issue needs attention from Azure service team or SDK team Monitor - Distro Monitor OpenTelemetry Distro and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jun 11, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra @vishweshbankwar.

@TimothyMothra
Copy link
Contributor

Hi @bgelens , can you share your full config? How are you setting resourceBuilder to the AddOpenTelemetry() ?

My code sample works:

<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0-beta.4" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
builder.Services.AddOpenTelemetry()
    .ConfigureResource(x => x.AddAttributes(new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("service.version", "someValue") }))
    .UseAzureMonitor(o => o.ConnectionString = connectionString);

@bgelens
Copy link
Author

bgelens commented Jun 12, 2024

Hi @TimothyMothra

I've adjusted my config to match yours and the end result is the same for me (nothing to see in application insights).

See my config.

<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0-beta.4" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
private static void ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{
  builder.Configuration["OTEL_SERVICE_NAME"] ??= Assembly.GetEntryAssembly()!.GetName().Name!;
  builder.Configuration["OTEL_RESOURCE_ATTRIBUTES"] ??= $"service.instance.id={Environment.MachineName}";

  builder.Logging.AddOpenTelemetry(logging =>
  {
    logging.IncludeFormattedMessage = true;
    logging.IncludeScopes = true;
  });

  builder.Services.AddOpenTelemetry()
    .ConfigureResource(x => x.AddAttributes([new KeyValuePair<string, object>("service.version", _applicationVersion)]))
    .WithMetrics(metrics =>
    {
      metrics.AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddRuntimeInstrumentation();
    })
    .WithTracing(tracing =>
    {
      if (builder.Environment.IsDevelopment())
      {
        // We want to view all traces in development
        tracing.SetSampler(new AlwaysOnSampler());
      }

      tracing.AddAspNetCoreInstrumentation(o =>
        {
          o.Filter = httpContext =>
          {
            // do not trace health checks when they return 200
            if (httpContext.Request.Path.HasValue &&
                httpContext.Request.Path.Value.StartsWith("/health", StringComparison.OrdinalIgnoreCase) &&
                httpContext.Response.StatusCode == (int)HttpStatusCode.OK)
            {
              return false;
            }

            // do not trace dapr config
            if (httpContext.Request.Path.HasValue &&
                httpContext.Request.Path.Value.StartsWith("/dapr/config", StringComparison.OrdinalIgnoreCase))
            {
              return false;
            }

            return true;
          };
          o.RecordException = true;
          o.EnrichWithHttpResponse = (activity, httpResponse) =>
          {
            var user = httpResponse.HttpContext.User;
            var preferredUserName = user.Claims.FirstOrDefault(x => x.Type == "preferred_username");
            if (preferredUserName is null) return;

            activity.AddTag("enduser.id", preferredUserName.Value);
            activity.AddTag("enduser.scope", string.Join(',', user.Claims.Select(x => x.ToString())));
          };
        })
        .AddHttpClientInstrumentation();
    });

  builder.AddOpenTelemetryExporters();

  // change it after we call UseAzureMonitor so it is not overwritten
  builder.ConfigureHttpClientTraceInstrumentationOptions();
}

private static void AddOpenTelemetryExporters(this IHostApplicationBuilder builder)
{
  if (!string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]))
  {
    builder.Services.AddOpenTelemetry().UseOtlpExporter();
  }

  if (!string.IsNullOrEmpty(builder.Configuration["ApplicationInsights:ConnectionString"]))
  {
    // the environment variable name required by the exporter is different from the normal configuration key
    builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] =
      builder.Configuration["ApplicationInsights:ConnectionString"];
  }

  if (string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) return;

  builder.Services.AddOpenTelemetry().UseAzureMonitor();
}

private static void ConfigureHttpClientTraceInstrumentationOptions(this IHostApplicationBuilder builder)
{
  // ignore dapr health checks
  builder.Services.Configure<HttpClientTraceInstrumentationOptions>(o => o.FilterHttpRequestMessage = request =>
    request.RequestUri?.AbsolutePath.StartsWith("/v1.0/healthz", StringComparison.OrdinalIgnoreCase) is not true);
}

In the aspire dashboard I can see everything is in place (the version unknown is used when starting locally, when running on aks, the version is a semantic version string):

image

Looking at the same trace event in application insights, the application_version is not there:

image

@TimothyMothra
Copy link
Contributor

I'll need some time to test your sample.

Just some observations:

  • if the value of _applicationVersion is string.Empty, that value won't be sent to Application Insights.

  • The telemetry you shared doesn't fully match your config.
    Your config shows:
    <PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
    But your telemetry shows Exporter version "1.3.0-beta2"
    image

    Beta2 does support the "service.version" so this is not the root cause.
    I'm calling attention to this because the config you're sharing may not match the application you're testing.


Here's my end to end example:

csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
  </ItemGroup>

</Project>

Program.cs

namespace WebApplication10
{
    using Azure.Monitor.OpenTelemetry.AspNetCore;
    using OpenTelemetry.Resources;

    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            var connectionString = "<YOUR CONNECTION STRING>";
            builder.Services.AddOpenTelemetry()
                .ConfigureResource(x => x.AddAttributes(new List<KeyValuePair<string, object>> { new("service.version", "someValue") }))
                .UseAzureMonitor(x => x.ConnectionString = connectionString);

            var app = builder.Build();

            app.MapGet("/", () => "Hello World!");

            app.Run();
        }
    }
}

Application Insights

image

@bgelens
Copy link
Author

bgelens commented Jun 13, 2024

Hi @TimothyMothra

I fixed the exporter version to match up with expectations, was an oversight.

_applicationVersion was not string.Empty but had value unknown In the above screenshot from Aspire dashboard, the actual value can be seen in the service.version entry.

This pointer however got me tinkering and I replaced unknown with unknownVersion and now it actually is present in application insights 😮 So I'm guessing unknown as a value is filtered out on application insights end maybe?

Thanks for your support!

@bgelens bgelens closed this as completed Jun 13, 2024
@TimothyMothra
Copy link
Contributor

I confirmed that the value "unknown" is being filtered. This wasn't a known limitation. I'll follow up with the service team to get more information.

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. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants