I have a sample ASP.NET Core 6 web service, which is configured to use OpenTelemetry and Azure Monitor like So:
// Program.cs.
using Azure.Monitor.OpenTelemetry.AspNetCore;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var resourceAttributes = new Dictionary<string, object> {
{ "service.name", "my-service" },
{ "service.namespace", "my-namespace" },
{ "service.instance.id", "my-instance" }};
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
options.ConnectionString = "<my-connection-string>";
});
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => {
builder.ConfigureResource(resourceBuilder => resourceBuilder.AddAttributes(resourceAttributes));
});
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// The rest of the logic.
Then here is my controller's method:
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
_logger.LogInformation($"my-weather-{(Random.Shared.Next(1, 99)):00}");
using (var activity = WeatherActivities.MainSource.StartActivity("Weather.Random"))
{
_logger.LogInformation("my-weather-inside-activity!");
activity?.SetTag("my-tag", Random.Shared.Next(1, 99));
activity?.AddEvent(new ActivityEvent("my-activity-event"));
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
When I hit the service, the information emitted by calls to _logger.LogInformation()
is landing in Azure Monitor and can be queried. I cannot find the logged information from activity?.SetTag()
and activity.AddEvent()
calls. I am also not sure how to find the activity source name or resource attributes. It feels like they are not sent for some reason.
I tried the following queries unsuccessfully:
union dependencies, traces | where customDimensions["my-tag"] != ""
customEvents | where name == "my-activity-event"
What am I missing? Thanks in advance!
Unfortunately,
Custom Event
currently does not support forOpenTelemetry
, onlycustom metric
,dependency
,Exception
andResquest
are supported. For reference check this Microsoft Document.I Followed this Microsoft document for
Opentelemetry
in application Insights and it worked for me.I have created a sample
ASP.NET Core Web App
in VS 2022.Program.cs
:OUTPUT
: