Skip to content

Commit

Permalink
split the API into a separate application
Browse files Browse the repository at this point in the history
This patch moves the API modules to another application, opentelemetry_api.

This repo is now the SDK implementation and when booted will start
the ot_tracer_server which is used to serialize configuration of
the tracer and set the default_tracer through the API.
  • Loading branch information
tsloughter committed Nov 10, 2019
1 parent 7b0ae7f commit ffe17f8
Show file tree
Hide file tree
Showing 29 changed files with 702 additions and 972 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@ Requires OTP 21.3 of above.

## Design

The [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification) defines a language library as having 2 components, the API and the SDK. The API must not only define the interfaces of any implementation in that language but also be able to function as a minimal implementation. The SDK is the default implementation of the API that must be optional.
The [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification) defines a language library as having 2 components, the API and the SDK. The API must not only define the interfaces of any implementation in that language but also be able to function as a noop implementation of the tracer. The SDK is the default implementation of the API that must be optional.

In this library the API is defined as the behaviours `ot_tracer`, `ot_span` and `ot_ctx`. It is not a separate Erlang application from the SDK, nor are there subdirectories following the [layout described in the spec](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/library-layout.md). Not using subdirectories as the spec's layout describes is simply because the OTP application structure has all source files directly under `src/`. There is no separation of API and SDK into distinct libraries because a) there is not yet support in rebar3 for using git repos with multiple applications as dependencies b) since Erlang has a flat namespace the same module naming strategy would be used whether they are separate applications or not. Additionally, a release can be configured to drop any part of an application the user chooses. So in the unlikely event there are users who wish to not include the SDK's default implementation it is possible.
If you are instrumenting a project your application should only depend on the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-erlang-api/) application.

### Default Tracer
This repository is the Erlang's SDK implementation and should be included in the final release and configured to setup the sampler, span processors and span exporters.

## Using

In an Erlang project add `opentelemetry` as the first element of the release's applications:

``` erlang
{relx, [{release, {<name>, <version>},
[{opentelemetry, temporary},
<your applications>]},
...]}.
```

In the above example `opentelemetry` is set to `temporary` so that if the `opentelemetry` application crashes, or is shutdown, it does not terminate the other applications in the project. This is optional, the `opentelemetry` application purposely sticks to `permanent` for the processes started by the root supervisor to leave it up to the end user whether they want the crash or shutdown or `opentelemetry` to be ignored or cause the shutdown of the rest of the applications in the release.

Doing the same for an Elixir project would be:

``` elixir
def project do
[
...
releases: [
<name>: [
applications: [opentelemetry: :temporary]
],

...
]
]
end
```

## Benchmarks

Expand Down
151 changes: 0 additions & 151 deletions include/opentelemetry.hrl

This file was deleted.

4 changes: 3 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{erl_opts, [debug_info]}.
{deps, [{wts, "~> 0.3"}]}.
{deps, [{wts, "~> 0.3"},
{opentelemetry_api, {git, "https://github.com/tsloughter/opentelemetry-erlang-api",
{branch, "initial-commit"}}}]}.

{shell, [{apps, [opentelemetry]}]}.

Expand Down
13 changes: 7 additions & 6 deletions src/opentelemetry.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
{applications,
[kernel,
stdlib,
wts
wts,
opentelemetry_api
]},
{env, [{tracer, {ot_tracer_default, #{span => {ot_span_ets, []},
ctx => {ot_ctx_pdict, []}}}},
{sampler, {always_on, #{}}},
{exporter, [{exporters, []},
{scheduled_delay_ms, 30000}]}]},
{env, [{sampler, {always_on, #{}}},
{processors, [%% #{id => my_processor,
%% module => ot_batch_processor,
%% config => #{}}
]}]},
{modules, []},

{licenses, ["Apache 2.0"]},
Expand Down
115 changes: 0 additions & 115 deletions src/opentelemetry.erl

This file was deleted.

13 changes: 1 addition & 12 deletions src/opentelemetry_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,7 @@

start(_StartType, _StartArgs) ->
Opts = application:get_all_env(opentelemetry),

{sampler, {Sampler, SamplerOpts}} = lists:keyfind(sampler, 1, Opts),
SamplerFun = ot_sampler:setup(Sampler, SamplerOpts),

%% The default sampler implementation must be passed to the tracer chosen.
%% Since the tracer is started after the rest of the supervision tree has started
%% and we only get its children, we must instantiate the sampler before anything else.
%% The sampler turns out to be instantiated before any supervision tree is started.
{tracer, {Tracer, TracerOpts}} = lists:keyfind(tracer, 1, Opts),
TracerChildren = ot_tracer:setup(Tracer, TracerOpts, SamplerFun),

opentelemetry_sup:start_link(TracerChildren, Opts).
opentelemetry_sup:start_link(Opts).

stop(_State) ->
ok.
Expand Down
Loading

0 comments on commit ffe17f8

Please sign in to comment.