Watch Aspire live streams文档试用 Aspire

OpenTelemetry Collector integration

此内容尚不支持你的语言。

⭐ Community Toolkit

The OpenTelemetry Collector receives, processes, and exports telemetry. The Community Toolkit integration adds a Collector container to an Aspire AppHost and routes telemetry from selected resources, or from all compatible resources, to it.

Use the integration to run a Collector alongside your application during development and manage telemetry routing from the AppHost. Configure the Collector with your own receivers, processors, and exporters, then choose which Aspire resources send telemetry to it.

The package provides two routing options:

  • Route one resource with WithOpenTelemetryCollectorRouting.
  • Use WithAppForwarding to route all resources that have an OpenTelemetry exporter annotation.
  • An Aspire AppHost project with the Community Toolkit package installed. See the hosting integration reference for installation instructions.
  • Docker or another configured container runtime for running the Collector container.
  • A Collector configuration file that defines the OTLP receiver and the exporters you want to use.

The hosting integration creates the Collector container and exposes its OTLP gRPC and HTTP endpoints. Routing configures OTEL_EXPORTER_OTLP_ENDPOINT on each selected resource and waits for the Collector’s health check before starting it.

architecture-beta

  group apphost(server)[AppHost]
  group telemetry(server)[Telemetry]

  service collector(server)[OpenTelemetry Collector] in apphost
  service app(server)[Application] in apphost
  service backend(server)[Telemetry backend] in telemetry

  app:R --> L:collector
  collector:R --> L:backend

Add a Collector resource and route an application to it. This example assumes the AppHost has an Api project and an otel-collector-config.yaml file:

apphost.mts
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const collector = await builder.addOpenTelemetryCollector('otel-collector');
await collector.withConfig('./otel-collector-config.yaml');
const api = await builder.addProject('api', '../Api/Api.csproj');
await api.withOpenTelemetryCollectorRouting(collector);
// After adding all resources, run the app...
await builder.build().run();

The OpenTelemetry Collector hosting integration documents installation, automatic forwarding, settings, endpoints, and health checks. See the OpenTelemetry Collector configuration documentation for pipeline configuration options.

Set up the Collector in the AppHost