Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/opencensus-beam/opencensus_elixir
https://github.com/opencensus-beam/opencensus_elixir
apm elixir opencensus tracing
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/opencensus-beam/opencensus_elixir
- Owner: opencensus-beam
- License: apache-2.0
- Created: 2018-12-14T01:39:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T21:53:49.000Z (over 2 years ago)
- Last Synced: 2024-09-16T09:16:09.766Z (4 months ago)
- Topics: apm, elixir, opencensus, tracing
- Language: Elixir
- Size: 59.6 KB
- Stars: 40
- Watchers: 6
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-beam-monitoring - Elixir
README
# Opencensus
[![CircleCI](https://circleci.com/gh/opencensus-beam/opencensus_elixir.svg?style=svg)](https://circleci.com/gh/opencensus-beam/opencensus_elixir)
[![Hex version badge](https://img.shields.io/hexpm/v/opencensus_elixir.svg)](https://hex.pm/packages/opencensus_elixir)Wraps some [`:opencensus`][:opencensus] capabilities for Elixir users so
they don't have to [learn them some Erlang][lyse] in order to get
[OpenCensus] distributed tracing.[opencensus]: http://opencensus.io
[:opencensus]: https://hex.pm/packages/opencensus
[lyse]: https://learnyousomeerlang.com## Installation
Add `opencensus_elixir` to your `deps` in `mix.exs`:
```elixir
def deps do
[
{:opencensus, "~> 0.9"},
{:opencensus_elixir, "~> 0.3.0"}
]
end
```## Usage
Wrap your code with the
[`Opencensus.Trace.with_child_span/3`][oce-with_child_span-3] macro to
execute it in a fresh span:```elixir
import Opencensus.Tracedef traced_fn(arg) do
with_child_span "traced" do
:YOUR_CODE_HERE
end
end
```## Alternatives
If you prefer driving Erlang packages directly (see also `:telemetry`), copy
what you need from `lib/opencensus/trace.ex` and call
`Logger.set_logger_metadata/0` if there's any chance of Logger use within
the span.```elixir
def traced_fn() do
try do
:ocp.with_child_span("name", %{fn: :traced_fn, mod: __MODULE__})
Logger.set_logger_metadata():YOUR_CODE_HERE
after
:ocp.finish_span()
Logger.set_logger_metadata()
end
end
```If `try .. after .. end` feels too bulky and you're _sure_ you won't need
Logger, try [`:ocp.with_child_span/3`][ocp-with_child_span-3]:```elixir
def traced_fn() do
:ocp.with_child_span("traced", %{fn: :traced_fn, mod: __MODULE__}, fn () ->
:YOUR_CODE_HERE
end)
end
```## Troubleshooting
To see your spans, use the `:oc_reporter_stdout` reporter, either in config:
```elixir
config :opencensus, reporters: [{:oc_reporter_stdout, []}]
```... or at the `iex` prompt:
```plain
iex> :oc_reporter.register(:oc_reporter_stdout)
```[oce-with_child_span-3]: https://hexdocs.pm/opencensus_elixir/Opencensus.Trace.html#with_child_span/3
[ocp-with_child_span-3]: https://hexdocs.pm/opencensus/ocp.html#with_child_span-3