Skip to content

Commit 7fcc552

Browse files
committed
Add :telemetry events for callback start and stop
1 parent a9b052d commit 7fcc552

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

lib/membrane/bin.ex

+4
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ defmodule Membrane.Bin do
348348

349349
Membrane.Core.Child.PadsSpecs.ensure_default_membrane_pads()
350350

351+
@doc false
352+
@spec membrane_component_type() :: :pipeline | :bin | :element
353+
def membrane_component_type, do: :bin
354+
351355
@doc false
352356
@spec membrane_bin?() :: true
353357
def membrane_bin?, do: true

lib/membrane/core/callback_handler.ex

+17-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,23 @@ defmodule Membrane.Core.CallbackHandler do
136136

137137
callback_result =
138138
try do
139-
apply(module, callback, args)
139+
telemetry_metadata = %{
140+
callback_args: args,
141+
parent_pid: state[:parent_pid],
142+
type: state.module.membrane_component_type()
143+
}
144+
145+
:telemetry.execute([:membrane, callback, :start], %{}, telemetry_metadata)
146+
147+
{duration, result} = :timer.tc(module, callback, args)
148+
149+
:telemetry.execute(
150+
[:membrane, callback, :stop],
151+
%{duration: duration},
152+
telemetry_metadata
153+
)
154+
155+
result
140156
rescue
141157
e in UndefinedFunctionError ->
142158
_ignored =

lib/membrane/element/base.ex

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ defmodule Membrane.Element.Base do
263263

264264
unquote(bring_pad)
265265

266+
@doc false
267+
@spec membrane_component_type() :: :pipeline | :bin | :element
268+
def membrane_component_type, do: :element
269+
266270
@doc false
267271
@spec membrane_element?() :: true
268272
def membrane_element?, do: true

lib/membrane/pipeline.ex

+4
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ defmodule Membrane.Pipeline do
512512
}
513513
end
514514

515+
@doc false
516+
@spec membrane_component_type() :: :pipeline | :bin | :element
517+
def membrane_component_type, do: :pipeline
518+
515519
@doc false
516520
@spec membrane_pipeline?() :: true
517521
def membrane_pipeline?, do: true

0 commit comments

Comments
 (0)