opentelemetry-erlang-contrib icon indicating copy to clipboard operation
opentelemetry-erlang-contrib copied to clipboard

Handler {OpentelemetryPhoenix, _} has failed and has been detached

Open enilsen16 opened this issue 3 years ago • 5 comments

No matter which handler I try to use with Opentelemetry they all aren't able to attach (OpentelemetryPhoenix, OpentelemetryEcto, etc...) . I followed and made sure that Plug.Telemetry exists. Any ideas why things won't attach?

 Handler {OpentelemetryPhoenix, :endpoint_stop} has failed and has been detached. Class=:error
Reason={:badmatch, :undefined}
Stacktrace=[
  {:otel_telemetry, :end_telemetry_span, 2,
   [file: 'src/otel_telemetry.erl', line: 59]},
  {:telemetry, :"-execute/3-fun-0-", 4,
   [
     file: '',
     line: 150
   ]},
  {:lists, :foreach, 2, [file: 'lists.erl', line: 1342]},
  {Plug.Telemetry, :"-call/2-fun-0-", 4,
   [file: 'lib/plug/telemetry.ex', line: 76]},
  {Enum, :"-reduce/3-lists^foldl/2-0-", 3, [file: 'lib/enum.ex', line: 2385]},
  {Plug.Conn, :run_before_send, 2, [file: 'lib/plug/conn.ex', line: 1690]},
  {Plug.Conn, :send_resp, 1, [file: 'lib/plug/conn.ex', line: 399]},
  {Web.LivestreamController, :action, 2,
   [file: 'lib/web/controllers/livestream_controller.ex', line: 1]},
  {Web.LivestreamController, :phoenix_controller_pipeline, 2,
   [file: 'lib/web/controllers/livestream_controller.ex', line: 1]},
  {Phoenix.Router, :__call__, 2, [file: 'lib/phoenix/router.ex', line: 355]},
  {Web.Endpoint, :plug_builder_call, 2,
   [file: 'endpoint.ex', line: 1]},
  {Web.Endpoint, :"call (overridable 3)", 2,
   [file: 'lib/web/endpoint.ex', line: 1]},
  {Web.Endpoint, :call, 2,
   [file: 'endpoint.ex', line: 1]},
  {Phoenix.Endpoint.Cowboy2Handler, :init, 4,
   [file: 'lib/phoenix/endpoint/cowboy2_handler.ex', line: 43]},
  {:cowboy_handler, :execute, 2,
   [
     file: '',
     line: 37
   ]},
  {:cowboy_stream_h, :execute, 3,
   [
     file: '',
     line: 306
   ]},
  {:cowboy_stream_h, :request_process, 3,
   [
     file: '',
     line: 295
   ]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}
]

enilsen16 avatar Nov 05 '21 15:11 enilsen16

Forgot to mention this is using the latest version of all packages

enilsen16 avatar Nov 05 '21 16:11 enilsen16

Looks like it assumes there is a context to pop but it your case it is undefined, https://github.com/opentelemetry-beam/opentelemetry_telemetry/blob/main/src/otel_telemetry.erl#L59

It should probably handle the context not existing even if it should only be called after one has been created. I'm not sure how you'd get to a case that there isn't one, but this is a start at figuring it out at least :)

tsloughter avatar Nov 05 '21 18:11 tsloughter

Interesting. Wonder why this would happen? I haven't tried manually creating the spans without these libraries, so I'll try that next and see if the results are different.

enilsen16 avatar Nov 05 '21 18:11 enilsen16

Not sure, could be related to the use of the pdict, maybe ending isn't being done in the same process as it was started.

tsloughter avatar Nov 05 '21 19:11 tsloughter

This should be resolved by #59. Let us know if this is still an issue.

bryannaegele avatar Mar 18 '22 19:03 bryannaegele