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

create unique processor name in otel_tracer_server #646

Merged
merged 2 commits into from
Nov 18, 2023
Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Attributes module `otel_attributes` moved to
API](https://github.com/open-telemetry/opentelemetry-erlang/pull/618)

### Fixes

- [Fix leak of atoms/persistent terms by creating unique processor name in `otel_tracer_server`](https://github.com/open-telemetry/opentelemetry-erlang/pull/646)

## Experimental API

### Changes

- [Allow to create observable instruments without passing callback arguments](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
- [Allow to create observable instruments without passing callback
arguments](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
- [Allow to give `advisory_params` to instrument creation functions](https://github.com/open-telemetry/opentelemetry-erlang/pull/628)

## Experimental SDK
Expand Down
16 changes: 5 additions & 11 deletions apps/opentelemetry/src/otel_batch_processor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,11 @@ current_tab_to_list(RegName) ->
ets:tab2list(?CURRENT_TABLE(RegName)).
-endif.

start_link(Config) ->
Name = case maps:find(name, Config) of
{ok, N} ->
N;
error ->
%% use a unique reference to distiguish multiple batch processors while
%% still having a single name, instead of a possibly changing pid, to
%% communicate with the processor
erlang:ref_to_list(erlang:make_ref())
end,

%% require a unique name to distiguish multiple batch processors while
%% still having a single name, instead of a possibly changing pid, to
%% communicate with the processor
-spec start_link(#{name := atom() | list()}) -> {ok, pid(), map()}.
start_link(Config=#{name := Name}) ->
RegisterName = ?REG_NAME(Name),
Config1 = Config#{reg_name => RegisterName},
{ok, Pid} = gen_statem:start_link({local, RegisterName}, ?MODULE, [Config1], []),
Expand Down
16 changes: 5 additions & 11 deletions apps/opentelemetry/src/otel_simple_processor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,11 @@
-define(DEFAULT_EXPORTER_TIMEOUT_MS, timer:minutes(5)).
-define(NAME_TO_ATOM(Name, Unique), list_to_atom(lists:concat([Name, "_", Unique]))).

start_link(Config) ->
Name = case maps:find(name, Config) of
{ok, N} ->
N;
error ->
%% use a unique reference to distiguish multiple batch processors while
%% still having a single name, instead of a possibly changing pid, to
%% communicate with the processor
erlang:ref_to_list(erlang:make_ref())
end,

%% require a unique name to distiguish multiple simple processors while
%% still having a single name, instead of a possibly changing pid, to
%% communicate with the processor
-spec start_link(#{name := atom() | list()}) -> {ok, pid(), map()}.
start_link(Config=#{name := Name}) ->
RegisterName = ?NAME_TO_ATOM(?MODULE, Name),
Config1 = Config#{reg_name => RegisterName},
{ok, Pid} = gen_statem:start_link({local, RegisterName}, ?MODULE, [Config1], []),
Expand Down
9 changes: 8 additions & 1 deletion apps/opentelemetry/src/otel_tracer_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ init_processor(SpanProcessorSup, ProcessorModule, Config) ->
%% start_link is an optional callback for processors
case lists:member({start_link, 1}, ProcessorModule:module_info(exports)) of
true ->
try supervisor:start_child(SpanProcessorSup, [ProcessorModule, Config]) of
try supervisor:start_child(SpanProcessorSup,
[ProcessorModule,
%% use a unique reference to distiguish multiple processors of the same type while
%% still having a single name, instead of a possibly changing pid, to
%% communicate with the processor
maps:merge(#{name => erlang:ref_to_list(erlang:make_ref())},
Config)])
of
{ok, _Pid, Config1} ->
{true, {ProcessorModule, Config1}};
{error, Reason} ->
Expand Down
Loading