# Exporters


Envie dados de telemetria para o [OpenTelemetry Collector](/docs/collector/)
para garantir que estes dados sejam exportados corretamente. A utilização de um
Collector em ambientes de produção é a melhor prática. Para visualizar os dados
de telemetria que foram gerados, exporte-os para um _backend_ como
[Jaeger](https://jaegertracing.io/), [Zipkin](https://zipkin.io/),
[Prometheus](https://prometheus.io/), ou um _backend_
[específico de um fornecedor](/ecosystem/vendors/).



## Exportadores disponíveis {#available-exporters}

O registro oferece uma [lista de exportadores para .NET][reg].





Entre os exportadores, os exportadores do [OpenTelemetry Protocol (OTLP)][OTLP]
são projetados tendo em mente o modelo de dados do OpenTelemetry, emitindo dados
OTel sem qualquer perda de informação. Além disso, muitas ferramentas que operam
com dados de telemetria suportam o formato OTLP (como [Prometheus][], [Jaeger][]
e a maioria dos [fornecedores][]), proporcionando um alto grau de flexibilidade
quando necessário. Para saber mais sobre o OTLP, consulte a [Especificação do
OTLP][OTLP].

[Jaeger]: /blog/2022/jaeger-native-otlp/
[OTLP]: /docs/specs/otlp/
[Prometheus]:
  https://prometheus.io/docs/prometheus/2.55/feature_flags/#otlp-receiver
[reg]: </ecosystem/registry/?component=exporter&language=dotnet>
[fornecedores]: /ecosystem/vendors/



Esta página reúne informações sobre os principais exportadores do OpenTelemetry
.NET e como configurá-los.





<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Nota</div>



Caso você esteja utilizando
[instrumentação sem código](</docs/zero-code/dotnet>), você poderá
aprender a configurar os exporters através do
[Guia de Configurações](</docs/zero-code/dotnet/configuration/>).

</div>






## OTLP

### Configuração do Collector {#collector-setup}

<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Nota</div>



Caso já possua um coletor ou _backend_ OTLP configurado, poderá pular para
[configurar as dependências do exportador OTLP](#otlp-dependencies) para a sua
aplicação.

</div>


Para testar e validar os seus exportadores OTLP, é possível executar o Collector
em um contêiner Docker que escreve os dados diretamente no console.

Em uma pasta vazia, crie um arquivo chamado `collector-config.yaml` e adicione o
seguinte conteúdo:

```yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
exporters:
  debug:
    verbosity: detailed
service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [debug]
    metrics:
      receivers: [otlp]
      exporters: [debug]
    logs:
      receivers: [otlp]
      exporters: [debug]
```

Em seguida, execute o Collector em um contêiner Docker através do seguinte
comando:

```shell
docker run -p 4317:4317 -p 4318:4318 --rm -v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml otel/opentelemetry-collector
```

Este Collector agora é capaz receber dados de telemetria via OTLP. Mais tarde,
você também poderá [configurar o Collector](/docs/collector/configuration) para
enviar os seus dados de telemetria para o seu _backend_ de observabilidade.

{{__hugo_ctx/}}


## Dependencies {#otlp-dependencies}

If you want to send telemetry data to an OTLP endpoint (like the
[OpenTelemetry Collector](#collector-setup), [Jaeger](#jaeger) or
[Prometheus](#prometheus)), you can choose between two different protocols to
transport your data:

- HTTP/protobuf
- gRPC

Start by installing the
[`OpenTelemetry.Exporter.OpenTelemetryProtocol`](https://www.nuget.org/packages/OpenTelemetry.Exporter.OpenTelemetryProtocol/)
package as a dependency for your project:

```sh
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
```

If you're using ASP.NET Core install the
[`OpenTelemetry.Extensions.Hosting`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting)
package as well:

```sh
dotnet add package OpenTelemetry.Extensions.Hosting
```

## Usage

### ASP.NET Core

Configure the exporters in your ASP.NET Core services:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        // The rest of your setup code goes here
        .AddOtlpExporter())
    .WithMetrics(metrics => metrics
        // The rest of your setup code goes here
        .AddOtlpExporter());

builder.Logging.AddOpenTelemetry(logging => {
    // The rest of your setup code goes here
    logging.AddOtlpExporter();
});
```

This will, by default, send telemetry using gRPC to <http://localhost:4317>, to
customize this to use HTTP and the protobuf format, you can add options like
this:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        // The rest of your setup code goes here
        .AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("your-endpoint-here/v1/traces");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        }))
    .WithMetrics(metrics => metrics
        // The rest of your setup code goes here
        .AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("your-endpoint-here/v1/metrics");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        }));

builder.Logging.AddOpenTelemetry(logging => {
    // The rest of your setup code goes here
    logging.AddOtlpExporter(options =>
    {
        options.Endpoint = new Uri("your-endpoint-here/v1/logs");
        options.Protocol = OtlpExportProtocol.HttpProtobuf;
    });
});
```

### Non-ASP.NET Core

Configure the exporter when creating a `TracerProvider`, `MeterProvider` or
`LoggerFactory`:

```csharp
var tracerProvider = Sdk.CreateTracerProviderBuilder()
    // Other setup code, like setting a resource goes here too
    .AddOtlpExporter(options =>
    {
        options.Endpoint = new Uri("your-endpoint-here/v1/traces");
        options.Protocol = OtlpExportProtocol.HttpProtobuf;
    })
    .Build();

var meterProvider = Sdk.CreateMeterProviderBuilder()
    // Other setup code, like setting a resource goes here too
    .AddOtlpExporter(options =>
    {
        options.Endpoint = new Uri("your-endpoint-here/v1/metrics");
        options.Protocol = OtlpExportProtocol.HttpProtobuf;
    })
    .Build();

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(logging =>
    {
        logging.AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("your-endpoint-here/v1/logs");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        })
    });
});
```

Use environment variables to set values like headers and an endpoint URL for
production.

## Console

## Dependencies

The console exporter is useful for development and debugging tasks, and is the
simplest to set up. Start by installing the
[`OpenTelemetry.Exporter.Console`](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console/)
package as a dependency for your project:

```sh
dotnet add package OpenTelemetry.Exporter.Console
```

If you're using ASP.NET Core install the
[`OpenTelemetry.Extensions.Hosting`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting)
package as well:

```sh
dotnet add package OpenTelemetry.Extensions.Hosting
```

## Usage {#console-usage}

### ASP.NET Core {#console-usage-asp-net-core}

Configure the exporter in your ASP.NET Core services:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        // The rest of your setup code goes here
        .AddConsoleExporter()
    )
    .WithMetrics(metrics => metrics
        // The rest of your setup code goes here
        .AddConsoleExporter()
    );

builder.Logging.AddOpenTelemetry(logging => {
    // The rest of your setup code goes here
    logging.AddConsoleExporter();
});
```

### Non-ASP.NET Core {#console-usage-non-asp-net-core}

Configure the exporter when creating a `TracerProvider`, `MeterProvider` or
`LoggerFactory`:

```csharp
var tracerProvider = Sdk.CreateTracerProviderBuilder()
    // The rest of your setup code goes here
    .AddConsoleExporter()
    .Build();

var meterProvider = Sdk.CreateMeterProviderBuilder()
    // The rest of your setup code goes here
    .AddConsoleExporter()
    .Build();

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(logging =>
    {
        logging.AddConsoleExporter();
    });
});
```


## Jaeger

### Configuração do Backend {#jaeger-backend-setup}

O [Jaeger](https://www.jaegertracing.io/) suporta nativamente o OTLP para
receber dados de rastros. O Jaeger pode ser executado através de um contêiner
Docker com uma UI acessível através da porta 16686 e OTLP habilitados nas portas
4317 e 4318:

```shell
docker run --rm \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 9411:9411 \
  jaegertracing/all-in-one:latest
```

### Uso {#jaeger-usage}

Siga as instruções para configurar os [exportadores OTLP](#otlp-dependencies).
{{__hugo_ctx/}}



## Prometheus

Para enviar dados de métricas para o [Prometheus](https://prometheus.io/), você
pode
[ativar o OTLP Receiver do Prometheus](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver)
e utilizar o [exportador OTLP](#otlp) ou você pode utilizar o exportador do
Prometheus, um `MetricReader` que inicia um servidor HTTP e coleta métricas,
serializando para o formato de texto do Prometheus sob demanda.

### Configuração do Backend {#prometheus-setup}

<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Nota</div>



Caso já possua o Prometheus ou um _backend_ compatível com Prometheus
configurado, poderá pular esta seção e configurar as dependências do exportador
[Prometheus](#prometheus-dependencies) ou [OTLP](#otlp-dependencies) para a sua
aplicação.

</div>


É possível executar o [Prometheus](https://prometheus.io) em um contêiner Docker
acessível na porta `9090` através das seguintes instruções:

Em uma pasta vazia, crie um arquivo chamado `prometheus.yml` e adicione o
seguinte conteúdo:

```yaml
scrape_configs:
  - job_name: dice-service
    scrape_interval: 5s
    static_configs:
      - targets: [host.docker.internal:9464]
```

Em seguida, execute o Prometheus em um contêiner Docker que ficará acessível na
porta `9090` através do seguinte comando:

```shell
docker run --rm -v ${PWD}/prometheus.yml:/prometheus/prometheus.yml -p 9090:9090 prom/prometheus --web.enable-otlp-receiver
```

<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Nota</div>



Ao utilizar o OTLP Receiver do Prometheus, certifique-se de definir o endpoint
OTLP das métricas em sua aplicação para `http://localhost:9090/api/v1/otlp`.

Nem todos os ambientes Docker suportam `host.docker.internal`. Em alguns casos,
será necessário alterar o valor `host.docker.internal` para `localhost` ou o
endereço de IP de sua máquina.

</div>

{{__hugo_ctx/}}


The following sections provide detailed, .NET-specific instructions for
configuring the Prometheus exporter.

There are two approaches for exporting metrics to Prometheus:

1. **Using OTLP Exporter (Push)**: Push metrics to Prometheus using the OTLP
   protocol. This requires
   [Prometheus' OTLP Receiver](https://prometheus.io/docs/prometheus/latest/feature_flags/#otlp-receiver)
   to be enabled. This is the recommended approach for production environments
   as it supports exemplars and is stable.

2. **Using Prometheus Exporter (Pull/Scrape)**: Expose a scraping endpoint in
   your application that Prometheus can scrape. This is the traditional
   Prometheus approach.

#### Using OTLP Exporter (Push) {#prometheus-otlp}

This approach uses the OTLP exporter to push metrics directly to Prometheus'
OTLP receiver endpoint. This is recommended for production environments because
it supports exemplars and uses the stable OTLP protocol.

##### Dependencies {#prometheus-otlp-dependencies}

Install the
[`OpenTelemetry.Exporter.OpenTelemetryProtocol`](https://www.nuget.org/packages/OpenTelemetry.Exporter.OpenTelemetryProtocol/)
package as a dependency for your project:

```sh
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
```

If you're using ASP.NET Core install the
[`OpenTelemetry.Extensions.Hosting`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting)
package as well:

```sh
dotnet add package OpenTelemetry.Extensions.Hosting
```

##### Usage {#prometheus-otlp-usage}

###### ASP.NET Core {#prometheus-otlp-asp-net-core-usage}

Configure the OTLP exporter to send metrics to Prometheus OTLP receiver:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics => metrics
        // The rest of your setup code goes here
        .AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("http://localhost:9090/api/v1/otlp/v1/metrics");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        }));
```

###### Non-ASP.NET Core {#prometheus-otlp-non-asp-net-core-usage}

Configure the exporter when creating a `MeterProvider`:

```csharp
var meterProvider = Sdk.CreateMeterProviderBuilder()
    // Other setup code, like setting a resource goes here too
    .AddOtlpExporter(options =>
    {
        options.Endpoint = new Uri("http://localhost:9090/api/v1/otlp/v1/metrics");
        options.Protocol = OtlpExportProtocol.HttpProtobuf;
    })
    .Build();
```

<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Note</div>



Make sure Prometheus is started with the OTLP receiver enabled:

```sh
./prometheus --web.enable-otlp-receiver
```

Or when using Docker:

```sh
docker run -p 9090:9090 prom/prometheus --web.enable-otlp-receiver
```

</div>


#### Using Prometheus Exporter (Pull/Scrape) {#prometheus-exporter}

This approach exposes a metrics endpoint in your application (e.g., `/metrics`)
that Prometheus scrapes at regular intervals.

<div class="alert alert-warning" role="alert"><div class="h4 alert-heading" role="heading">Warning</div>



This exporter is still under development and doesn't support exemplars. For
production environments, consider using the
[OTLP exporter approach](#prometheus-otlp) instead.

</div>


##### Dependencies {#prometheus-dependencies}

Install the
[exporter package](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.AspNetCore)
as a dependency for your application:

```shell
dotnet add package OpenTelemetry.Exporter.Prometheus.AspNetCore --version 1.15.1-beta.1
```

If you're using ASP.NET Core install the
[`OpenTelemetry.Extensions.Hosting`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting)
package as well:

```sh
dotnet add package OpenTelemetry.Extensions.Hosting
```

##### Usage {#prometheus-exporter-usage}

###### ASP.NET Core {#prometheus-exporter-asp-net-core-usage}

Configure the exporter in your ASP.NET Core services:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics => metrics.AddPrometheusExporter());
```

You'll then need to register the Prometheus scraping middleware so that
Prometheus can scrape your application. Use the
`UseOpenTelemetryPrometheusScrapingEndpoint` extension method on
`IApplicationBuilder`:

```csharp
var builder = WebApplication.CreateBuilder(args);

// ... Setup

var app = builder.Build();

app.UseOpenTelemetryPrometheusScrapingEndpoint();

await app.RunAsync();
```

By default, this exposes the metrics endpoint at `/metrics`. You can customize
the endpoint path or use a predicate function for more advanced configuration:

```csharp
app.UseOpenTelemetryPrometheusScrapingEndpoint(
    context => context.Request.Path == "/internal/metrics"
        && context.Connection.LocalPort == 5067);
```

###### Non-ASP.NET Core {#prometheus-exporter-non-asp-net-core-usage}

> [!WARNING]
>
> This component is intended for dev inner-loop, there is no plan to make it
> production ready. Production environments should use
> [`OpenTelemetry.Exporter.Prometheus.AspNetCore`](#prometheus-exporter-asp-net-core-usage),
> or a combination of
> [`OpenTelemetry.Exporter.OpenTelemetryProtocol`](#aspnet-core) and
> [OpenTelemetry Collector](/docs/collector).

For applications not using ASP.NET Core, you can use the `HttpListener` version
which is available in a
[different package](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.HttpListener):

```shell
dotnet add package OpenTelemetry.Exporter.Prometheus.HttpListener --version 1.15.1-beta.1
```

Then this is setup directly on the `MeterProviderBuilder`:

```csharp
var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddMeter(MyMeter.Name)
    .AddPrometheusHttpListener(
        options => options.UriPrefixes = new string[] { "http://localhost:9464/" })
    .Build();
```

##### Prometheus Configuration (Scrape)

When using the Prometheus exporter (pull/scrape approach), you need to configure
Prometheus to scrape your application. Add the following to your
`prometheus.yml`:

```yaml
scrape_configs:
  - job_name: 'your-app-name'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:5000'] # Your application's host:port
```

For more details on configuring the Prometheus exporter, see
[OpenTelemetry.Exporter.Prometheus.AspNetCore](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md).


## Zipkin

### Configuração do Backend {#zipkin-setup}

<div class="alert alert-primary" role="alert"><div class="h4 alert-heading" role="heading">Nota</div>



Caso já possua o Zipkin ou um _backend_ compatível com Zipkin configurado,
poderá pular esta seção e configurar as
[dependências do exportador Zipkin](#zipkin-dependencies) para a sua aplicação.

</div>


É possível executar o [Zipkin](https://zipkin.io/) em um contêiner Docker
através do seguinte comando:

```shell
docker run --rm -d -p 9411:9411 --name zipkin openzipkin/zipkin
```
{{__hugo_ctx/}}


## Dependencies {#zipkin-dependencies}

To send your trace data to [Zipkin](https://zipkin.io/), install the
[exporter package](https://www.nuget.org/packages/OpenTelemetry.Exporter.Zipkin)
as a dependency for your application:

```shell
dotnet add package OpenTelemetry.Exporter.Zipkin
```

If you're using ASP.NET Core install the
[`OpenTelemetry.Extensions.Hosting`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting)
package as well:

```sh
dotnet add package OpenTelemetry.Extensions.Hosting
```

## Usage {#zipkin-usage}

### ASP.NET Core {#zipkin-asp-net-core-usage}

Configure the exporter in your ASP.NET Core services:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        // The rest of your setup code goes here
        .AddZipkinExporter(options =>
        {
            options.Endpoint = new Uri("your-zipkin-uri-here");
        }));
```

### Non-ASP.NET Core {#zipkin-non-asp-net-core-usage}

Configure the exporter when creating a tracer provider:

```csharp
var tracerProvider = Sdk.CreateTracerProviderBuilder()
    // The rest of your setup code goes here
    .AddZipkinExporter(options =>
    {
        options.Endpoint = new Uri("your-zipkin-uri-here");
    })
    .Build();
```
