Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metrics example #413

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/roll_dice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ To generate and view traces:

For more information on the OpenTelemetry instrumentation in this example, check out the guide for getting started with [OpenTelemetry](https://opentelemetry.io/docs/instrumentation/erlang/getting-started/)

## No OpenTelemetry Metrics exported

How to reproduce:

Use Elixir 1.14.3 (compiled with Erlang/OTP 25)

1. Start OTEL Collector `docker-compose up`
2. `mix deps.get`
3. `mix phx.server`
4. `curl -X GET http://localhost:4000/api/rolldice`

Notice that no metrics reach the OTEL Collector

## How did we get here?

To begin, use the `phx` generator to create a new project. To keep things simple we'll leave out the database and html for now with the `--no-ecto` and `--no-html` flags.
Expand Down
10 changes: 10 additions & 0 deletions examples/roll_dice/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

config :opentelemetry,
resource: %{service: %{name: "roll_dice_app"}},
span_processor: :batch,
traces_exporter: :otlp,
metrics_exporter: :otlp

config :opentelemetry_exporter,
otlp_protocol: :grpc,
otlp_endpoint: "http://localhost:4317"

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
13 changes: 1 addition & 12 deletions examples/roll_dice/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
otel:
image: otel/opentelemetry-collector-contrib:0.76.1
image: otel/opentelemetry-collector-contrib:0.86.0
command: ["--config=/conf/otel-collector-config.yaml"]
privileged: true
ports:
Expand All @@ -10,14 +10,3 @@ services:
- 55679:55679
volumes:
- ./otel-collector-config.yaml:/conf/otel-collector-config.yaml
links:
- jaeger-all-in-one

jaeger-all-in-one:
image: jaegertracing/all-in-one:1.45
restart: always
environment:
COLLECTOR_OTLP_ENABLED: true
ports:
- "16686:16686"
- "4317"
3 changes: 3 additions & 0 deletions examples/roll_dice/lib/roll_dice/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ defmodule RollDice.Application do
@moduledoc false

use Application
require OpenTelemetryAPIExperimental.Counter, as: Counter

@impl true
def start(_type, _args) do
:opentelemetry_cowboy.setup()
OpentelemetryPhoenix.setup(adapter: :cowboy2)

Counter.create(:number_of_messages, %{unit: "1", description: "some counter lusooo"})

children = [
# Start the Telemetry supervisor
RollDiceWeb.Telemetry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
defmodule RollDiceWeb.DiceController do
use RollDiceWeb, :controller
require OpenTelemetry.Tracer, as: Tracer
require OpenTelemetryAPIExperimental.Counter, as: Counter

def roll(conn, _params) do
send_resp(conn, 200, roll_dice())
end

defp roll_dice do
Counter.add(:number_of_requests, 1)

Tracer.with_span "roll_dice" do
roll = Enum.random(1..6)

Expand Down
12 changes: 7 additions & 5 deletions examples/roll_dice/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ defmodule RollDice.MixProject do
{:gettext, "~> 0.20"},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"},
{:opentelemetry_exporter, "~> 1.5"},
{:opentelemetry, "~> 1.3"},
{:opentelemetry_api, "~> 1.2"},
{:opentelemetry_phoenix, "~> 1.1"},
{:opentelemetry_cowboy, "~> 0.2"},
{:opentelemetry_exporter, "~> 1.8"},
{:opentelemetry, "~> 1.5"},
{:opentelemetry_api, "~> 1.4"},
{:opentelemetry_api_experimental, "~> 0.5.1"},
{:opentelemetry_experimental, "~> 0.5.1"},
{:opentelemetry_phoenix, "~> 1.2"},
{:opentelemetry_cowboy, "~> 0.3"}
]
end

Expand Down
38 changes: 20 additions & 18 deletions examples/roll_dice/mix.lock

Large diffs are not rendered by default.

32 changes: 7 additions & 25 deletions examples/roll_dice/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
# OpenTelemetry Collector config that receives OTLP and exports to Zipkin
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
endpoint: 0.0.0.0:4317
http:
cors:
allowed_origins:
- "http://localhost:4000"
endpoint: "0.0.0.0:4318"
endpoint: 0.0.0.0:4318

processors:
batch:
send_batch_size: 1024
timeout: 5s
exporters:
otlp:
endpoint: jaeger-all-in-one:4317
tls:
insecure: true

exporters:
debug:
verbosity: detailed
sampling_initial: 1
sampling_thereafter: 1

extensions:
zpages: {}

service:
telemetry:
logs:
level: "debug"
extensions: [zpages]
pipelines:
traces:
logs:
receivers: [otlp]
processors: [batch]
exporters: [debug, otlp]
exporters: [debug]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [debug]
logs:
traces:
receivers: [otlp]
processors: [batch]
exporters: [debug]
Loading