Can I get all of my Aspire projects to sent telemetry to the same dataset?

45 Views Asked by At

Here is my Aspire app code

using Projects;

IDistributedApplicationBuilder builder = DistributedApplication.CreateBuilder(args);

var telegramBroadcastService = 
    builder.
        AddProject<Netizen_TelegramBroadcastService>("TelegramBroadcastService");

var campaignSystemApi =
    builder
        .AddProject<CampaignSystem_Api>("CampaignSystem.Api");

builder
    .Build()
    .Run();

And here is the telemetry registration code

                .WithTracing(tracing =>
                {
                    if (isDevelopment)
                    {
                        // We want to view all traces in development
                        tracing.SetSampler(new AlwaysOnSampler());
                    }

                    tracing
                        .AddSource("MyProduct.*")
                        .AddAspNetCoreInstrumentation()
                        .AddGrpcClientInstrumentation()
                        .AddHttpClientInstrumentation()
                        .AddOtlpExporter(otlpOptions =>
                        {
                            otlpOptions.Endpoint = new Uri($"https://api.honeycomb.io:443");
                            otlpOptions.Headers = string.Join(
                                ",",
                               new List<string>
                                {
                                    "x-otlp-version=0.16.0",
                                    $"x-honeycomb-team=-----omitted-----"
                                });
                        });

                });

When I run this code, Aspire sends telemetry to Honecomb but it creates multiple datasets (one for each name in builder.AddProject).

Is there a way to have them all go to a single dataset? Otherwise, I get the same telemetry in multiple datasets with (missing) nodes at the top.

1

There are 1 best solutions below

0
dotnetstep On

As per my understanding of Aspire and How it register project.

  • When project register with Aspire App Host and when it run from there, It send s it to Aspire otel receiver.

  • The way you registered, It will send it to honeycomb and Aspire will not comes in between. (I used to send it to Grafana cloud)

  • In Api Project and Web Project you have to add following things.

  • Add Environment variable with OTEL_SERVICE_NAME.

"profiles": {
  "http": {
    "commandName": "Project",
    "dotnetRunMessages": true,
    "launchBrowser": true,
    "launchUrl": "weatherforecast",
    "applicationUrl": "http://localhost:5414",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development",
      "OTEL_SERVICE_NAME": "ONE"
    }
  }
}
  • You can also set this env. variable in Aspire host but as it will extension method and there are some processing so it will give different name to each service. (If you configure ONE then ONE-{somerandomnumber}.
builder.AddProject<Projects.eight_Web>("webfrontend")
    .WithReference(apiService).WithEnvironment("OTEL_SERVICE_NAME","ONE");

Update

As per discussion over X, there is alternative solution. This will make in easy when you have to set one name ( Just like case mention over here in question).

builder.Services.AddOpenTelemetry().ConfigureResource(configureResource =>
{
    configureResource.AddService("One")
});