You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让所有Aspire项目将遥测数据发送至同一Honeycomb数据集?

用户提供的Aspire应用代码
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();
用户提供的遥测注册代码
.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-----"
                });
        });

});
问题

运行上述代码后,Aspire会为每个builder.AddProject()指定的项目创建单独的Honeycomb数据集,导致同一链路的遥测数据分散,还出现(missing)节点,需要将所有项目的遥测数据统一发送至单个数据集。

解决方案

在OtlpExporter的请求头中添加x-honeycomb-dataset字段,指定统一的数据集名称即可。修改后的遥测注册代码如下:

.WithTracing(tracing =>
{
    if (isDevelopment)
    {
        // 开发环境下采集所有追踪数据
        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-----",
                    // 指定统一的数据集名称,替换为你的目标数据集
                    "x-honeycomb-dataset=your-unified-dataset"
                });
        });
});
原理

Honeycomb的OTLP exporter通过x-honeycomb-dataset请求头确定数据归属的数据集。Aspire默认未为所有项目统一设置该字段,因此每个项目会使用自身服务名作为数据集名称。手动添加统一的x-honeycomb-dataset头后,所有服务的遥测数据都会被发送到指定的同一个数据集,链路追踪将完整聚合,不会再出现数据分散和(missing)节点问题。

内容的提问来源于stack exchange,提问作者Peter Morris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 14:00:24