Giter Club home page Giter Club logo

Comments (6)

TimothyMothra avatar TimothyMothra commented on June 24, 2024 1

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);

from azure-sdk-for-net.

TimothyMothra avatar TimothyMothra commented on June 24, 2024 1

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

from azure-sdk-for-net.

TimothyMothra avatar TimothyMothra commented on June 24, 2024 1

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.

from azure-sdk-for-net.

github-actions avatar github-actions commented on June 24, 2024

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

from azure-sdk-for-net.

bgelens avatar bgelens commented on June 24, 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

from azure-sdk-for-net.

bgelens avatar bgelens commented on June 24, 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!

from azure-sdk-for-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.