Skip to content

Instantly share code, notes, and snippets.

@yonkeltron
Last active February 22, 2019 08:30
Show Gist options
  • Save yonkeltron/ceb500d5f3a19c1a9ce1bed4e6298817 to your computer and use it in GitHub Desktop.
Save yonkeltron/ceb500d5f3a19c1a9ce1bed4e6298817 to your computer and use it in GitHub Desktop.
OpenTracing in Elixir with Otter
defmodule Ot.Mixfile do
use Mix.Project
def project do
[app: :ot,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end
def application do
# Specify extra applications you'll use from Erlang/Elixir
[extra_applications: [:logger]]
end
defp deps do
[{:otter, "~> 0.2.0"},
{:ibrowse, "~> 4.4"},
{:cowboy, "~> 1.1"}]
end
end
defmodule Ot do
@moduledoc "Basic OpenTracing demo using the otter library"
require Logger
alias :otter, as: Otter
@spec log_span_to_zipkin(String.t(), integer()) :: no_return()
@spec log_span_to_zipkin(String.t()) :: no_return()
def log_span_to_zipkin(span_name, sleep_time \\ 1000) do
Logger.info("Constructing OT span...")
span = span_name |> Otter.start() |> Otter.tag("OpenTracing", "Demo") |> Otter.log("Before sleep")
Logger.info("Sleeping...")
:timer.sleep(sleep_time)
Logger.info("Finishing up span...")
span |> Otter.log("After sleep") |> Otter.finish()
end
end
@gmile
Copy link

gmile commented Feb 22, 2019

If anyone stumbles upon this – the example it works perfectly with elixir 1.8, and jaeger:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment