# Exporters

LLMS index: [llms.txt](/llms.txt)

---


将遥测数据发送到 [OpenTelemetry Collector](/docs/collector/)，以确保其被正确导出。
在生产环境中使用 Collector 是最佳实践。若要可视化你的遥测数据，可将其导出到后端系统，例如
[Jaeger](https://jaegertracing.io/)、[Zipkin](https://zipkin.io/)、
[Prometheus](https://prometheus.io/)，或某个[特定厂商的](/ecosystem/vendors/)后端。



## 可用的导出器 {#available-exporters}

镜像仓库中包含一份 [Ruby 可用导出器的列表][reg]。





在所有导出器中，[OpenTelemetry 协议 (OTLP)][OTLP] 导出器是以 OpenTelemetry 数据模型为基础设计的，
能够无信息丢失地输出 OTel 数据。此外，许多处理遥测数据的工具都支持 OTLP
（例如 [Prometheus][]、[Jaeger][] 和大多数[厂商][vendors]），在你需要时为你提供高度的灵活性。
若要了解更多关于 OTLP 的信息，请参阅 [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=ruby>
[vendors]: /ecosystem/vendors/



本页面介绍了主要的 OpenTelemetry Ruby 导出器以及如何进行配置。






{{__hugo_ctx/}}


## OTLP endpoint

To send trace data to an OTLP endpoint (like the [collector](/docs/collector) or
Jaeger) you'll want to use an exporter package, such as
`opentelemetry-exporter-otlp`:

   <ul class="nav nav-tabs" id="tabs-1" role="tablist">
  <li class="nav-item">
      <button class="nav-link active"
          id="tabs-01-00-tab" data-bs-toggle="tab" data-bs-target="#tabs-01-00" role="tab"
          data-td-tp-persist="bundler" aria-controls="tabs-01-00" aria-selected="true">
        bundler
      </button>
    </li><li class="nav-item">
      <button class="nav-link"
          id="tabs-01-01-tab" data-bs-toggle="tab" data-bs-target="#tabs-01-01" role="tab"
          data-td-tp-persist="gem" aria-controls="tabs-01-01" aria-selected="false">
        gem
      </button>
    </li>
</ul>

<div class="tab-content" id="tabs-1-content">
    <div class="tab-body tab-pane fade show active"
        id="tabs-01-00" role="tabpanel" aria-labelled-by="tabs-01-00-tab" tabindex="1">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">bundle add opentelemetry-exporter-otlp
</span></span></code></pre></div>
    </div>
    <div class="tab-body tab-pane fade"
        id="tabs-01-01" role="tabpanel" aria-labelled-by="tabs-01-01-tab" tabindex="1">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">gem install opentelemetry-exporter-otlp
</span></span></code></pre></div>
    </div>
</div>


Next, configure the exporter to point at an OTLP endpoint. For example, you can
update `config/initializers/opentelemetry.rb` from the
[Getting Started](../getting-started/) by adding
`require 'opentelemetry-exporter-otlp'` to the code:

```ruby
# config/initializers/opentelemetry.rb
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry-exporter-otlp'
OpenTelemetry::SDK.configure do |c|
  c.service_name = 'dice-ruby'
  c.use_all() # enables all instrumentation!
end
```

If you now run your application, it will use OTLP to export traces:

```sh
rails server -p 8080
```

By default, traces are sent to an OTLP endpoint listening on localhost:4318. You
can change the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT`
accordingly:

```sh
env OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" rails server -p 8080
```

To try out the OTLP exporter quickly and see your traces visualized at the
receiving end, you can run Jaeger in a Docker container:

```shell
docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:latest
```

You can visualize the traces via the Jaeger trace UI by visiting
`localhost:16686` in your browser.

## Zipkin

To set up Zipkin as quickly as possible, run it in a Docker container:

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

Install the exporter package as a dependency for your application:

   <ul class="nav nav-tabs" id="tabs-2" role="tablist">
  <li class="nav-item">
      <button class="nav-link active"
          id="tabs-02-00-tab" data-bs-toggle="tab" data-bs-target="#tabs-02-00" role="tab"
          data-td-tp-persist="bundle" aria-controls="tabs-02-00" aria-selected="true">
        bundle
      </button>
    </li><li class="nav-item">
      <button class="nav-link"
          id="tabs-02-01-tab" data-bs-toggle="tab" data-bs-target="#tabs-02-01" role="tab"
          data-td-tp-persist="gem" aria-controls="tabs-02-01" aria-selected="false">
        gem
      </button>
    </li>
</ul>

<div class="tab-content" id="tabs-2-content">
    <div class="tab-body tab-pane fade show active"
        id="tabs-02-00" role="tabpanel" aria-labelled-by="tabs-02-00-tab" tabindex="2">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">bundle add opentelemetry-exporter-zipkin
</span></span></code></pre></div>
    </div>
    <div class="tab-body tab-pane fade"
        id="tabs-02-01" role="tabpanel" aria-labelled-by="tabs-02-01-tab" tabindex="2">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">gem install opentelemetry-exporter-zipkin
</span></span></code></pre></div>
    </div>
</div>


Update your OpenTelemetry configuration to use the exporter and to send data to
your Zipkin backend:

```ruby
# config/initializers/opentelemetry.rb
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'

require 'opentelemetry-exporter-zipkin'
OpenTelemetry::SDK.configure do |c|
  c.service_name = 'dice-ruby'
  c.use_all() # enables all instrumentation!
end
```

If you now run your application, set the environment variable
`OTEL_TRACES_EXPORTER` to Zipkin:

```sh
env OTEL_TRACES_EXPORTER=zipkin rails server
```

By default, traces are sent to a Zipkin endpoint listening on port
localhost:9411. You can change the endpoint by setting the
`OTEL_EXPORTER_ZIPKIN_ENDPOINT` accordingly:

```sh
env OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:9411" rails server
```
