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

NewRelic.Instrumented.HTTPoison.Error.__struct__/0 is undefined, cannot expand struct NewRelic.Instrumented.HTTPoison.Error #26

Closed
brunozrk opened this issue Sep 25, 2018 · 5 comments · Fixed by #27
Labels
bug Something isn't working

Comments

@brunozrk
Copy link

brunozrk commented Sep 25, 2018

When using the Pre-Instrumented Modules - HTTPoison and doing pattern matching in HttpPoison response, eg.:

{:error, %HTTPoison.Error{reason: reason}} = response

it raises an error at compilation time:

NewRelic.Instrumented.HTTPoison.Error.__struct__/0 is undefined, cannot expand struct NewRelic.Instrumented.HTTPoison.Error

I don't know if there is a trick to do in NewRelic.Instrumented.HTTPoison to solve this error, I solved the problem using a different alias:

alias NewRelic.Instrumented.HTTPoison, as: NRHTTPoison

and then: NRHTTPoison.post(...)

but it looks ugly 😢

Environment

  • Elixir & Erlang version (elixir -v):
    Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
    Elixir 1.7.3 (compiled with Erlang/OTP 20)

  • Agent version (mix deps | grep new_relic_agent):
    new_relic_agent 1.0.2 (Hex package) (mix)
    locked at 1.0.2 (new_relic_agent) 4528c139

@binaryseed
Copy link
Contributor

Thanks we'll look into how to solve this

@binaryseed binaryseed added the bug Something isn't working label Sep 25, 2018
@binaryseed
Copy link
Contributor

Do you have to pattern match on the exception name? HTTPoison only has one exception type. This would also work...

{:error, %{reason: reason}} = response

I'll look into mirroring the Error struct but this ^ might fix it for you too

@binaryseed
Copy link
Contributor

One thing you can do is reference the top level module via Elixir. like this:

{:error, %Elixir.HTTPoison.Error{}} = HTTPoison.get("localhost:12345")

@brunozrk
Copy link
Author

summarizing, we have 3 options:

  • first
alias NewRelic.Instrumented.HTTPoison, as: NRHTTPoison

and then: NRHTTPoison.post(...)
  • second
case response do
   {:error, {reason: reason}} ->
           ...
   {:ok, {status_code: status, body: body}} ->
      case status do
            200 ->
              ...
            _ ->
              ...
      end
end
  • third
case response do
   {:error, %Elixir.HTTPoison.Error{reason: reason}} ->
           ...
   {:ok, %Elixir.HTTPoison.Response{status_code: status, body: body}} ->
      case status do
            200 ->
              ...
            _ ->
              ...
      end
end

I liked the third option, modifying the documentation should help, and I think mirroring the struts won't be necessary, what do you think?

@binaryseed
Copy link
Contributor

I'll update the docs to point folks to the 2nd and 3rd option based on their preferences.

Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants