Skip to content

Commit

Permalink
Merge branch 'main' into col-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mhausenblas authored May 10, 2023
2 parents da022db + 30e21c5 commit a12bda1
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 70 deletions.
6 changes: 3 additions & 3 deletions content/en/docs/instrumentation/python/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Create a file `app.py` and add the following code to it:

```python
from random import randint
from flask import Flask, request
from flask import Flask

app = Flask(__name__)

Expand Down Expand Up @@ -274,7 +274,7 @@ create a trace that's a child of the one that's automatically generated:
from opentelemetry import trace

from random import randint
from flask import Flask, request
from flask import Flask

# Acquire a tracer
tracer = trace.get_tracer("diceroller.tracer")
Expand Down Expand Up @@ -400,7 +400,7 @@ from opentelemetry import trace
from opentelemetry import metrics

from random import randint
from flask import Flask, request
from flask import Flask

tracer = trace.get_tracer("diceroller.tracer")
# Acquire a meter.
Expand Down
125 changes: 125 additions & 0 deletions content/en/docs/instrumentation/ruby/exporters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: Exporters
weight: 5
spelling: cSpell:ignore Zipkin jaegertracing openzipkin zipkin
---

In order to visualize and analyze your traces, you will need to export them to a
backend such as [Jaeger](https://www.jaegertracing.io/) or
[Zipkin](https://zipkin.io/). OpenTelemetry Ruby provides exporters for some
common open source backends.

Below you will find some introductions on how to set up backends and the
matching exporters.

## OTLP endpoint

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

{{< tabpane lang=shell persistLang=false >}}

{{< tab bundler >}} bundle add opentelemetry-exporter-otlp {{< /tab >}}

{{< tab gem >}} gem install opentelemetry-exporter-otlp {{< /tab >}}

{{< /tabpane>}}

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/v1/traces" 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
```

## 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:

{{< tabpane lang=shell persistLang=false >}}

{{< tab bundle >}} bundle add opentelemetry-exporter-zipkin {{< /tab >}}

{{< tab gem >}} gem install opentelemetry-exporter-zipkin {{< /tab >}}

{{< /tabpane>}}

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
```
Loading

0 comments on commit a12bda1

Please sign in to comment.