Skip to content

Commit

Permalink
Merge pull request #646 from tsloughter/limit-processor-pterm
Browse files Browse the repository at this point in the history
create unique processor name in otel_tracer_server
  • Loading branch information
tsloughter authored Nov 18, 2023
2 parents a258bbc + e878a9a commit f0021c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
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

0 comments on commit f0021c8

Please sign in to comment.