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

Elixir response time missing when using Bandit #489

Closed
sgessa opened this issue Feb 4, 2025 · 8 comments · Fixed by #498
Closed

Elixir response time missing when using Bandit #489

sgessa opened this issue Feb 4, 2025 · 8 comments · Fixed by #498

Comments

@sgessa
Copy link

sgessa commented Feb 4, 2025

Describe the bug

When using Bandit I am unable to see the Elixir response time in New Relic dashboard (I still see Postgres and total response time tho).
I started receiving crash reports that might be related:

KeyError: NewRelic.Transaction.Complete.report_transaction_event/1

key :host not found in: %{
  name: "Unknown/Unknown",
  pid: "#PID<0.155834.0>",
  priority: 0.799115,
  reductions: 21264818,
  status: 500,
  start_time: 1738663081850,
  guid: "213aea1b85585908",
  sampled: false,
  traceId: "d3f468594a6581f76f487d6998bb71c1",
  duration_s: 2.3400000000000002e-4,
  total_time_s: 0.0,
  memory_kb: 34.6640625,
  end_time: 1738663081850.234,
  duration_ms: 0.234,
  transactionType: :Web,
  process_spawns: -1,
  "nr.apdexPerfZone": "S",
  duration_us: 234
}

lib/new_relic/transaction/complete.ex in NewRelic.Transaction.Complete.report_transaction_event/1 at line 458
lib/new_relic/transaction/complete.ex in NewRelic.Transaction.Complete.run/2 at line 19
lib/new_relic/transaction/sidecar.ex in NewRelic.Transaction.Sidecar.handle_continue/2 at line 224
gen_server.erl in :gen_server.try_handle_continue/3 at line 1085
gen_server.erl in :gen_server.loop/7 at line 995
proc_lib.erl in :proc_lib.init_p_do_apply/3 at line 241

Environment

Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Elixir 1.17.3 (compiled with Erlang/OTP 26)

new_relic_agent 1.31.1

bandit 1.6.7

@binaryseed
Copy link
Collaborator

Thanks for the report. I don't think the two things are related. I have a hunch I'm already tracking down related to instrumenting bandit that might be related.

This error is interesting though, looks like the transition completed w/o setting a host attribute, which I'm not sure how that could happen since it always gets set when a web transaction is opened.

Are you doing anything out of the ordinary, perhaps trying to start a web transaction manually in your app?

@sgessa
Copy link
Author

sgessa commented Feb 5, 2025

Nope, I am not doing anything manually..
I also found a post on elixir forums from someone having the same issue...

@sgessa
Copy link
Author

sgessa commented Feb 5, 2025

Oh I'm calling NewRelic.ignore_transaction/0 in one my controller used for heartbeat, that's the only manual thing I do.
And the frequency of crash reports are similar to the interval of my heartbeat calls but it might just be a coincidence.

@binaryseed
Copy link
Collaborator

Will you share a link to that elixir forum post?

@sgessa
Copy link
Author

sgessa commented Feb 6, 2025

Sorry the issue wasn't related after all.

This is what I see in NewRelic by the way, Elixir response time is showing with Cowboy then disappeared with Bandit.

Image

@TylerWitt
Copy link
Contributor

This error is interesting though, looks like the transition completed w/o setting a host attribute, which I'm not sure how that could happen since it always gets set when a web transaction is opened.

I think this could happen on ignored paths.

with :collect <- Transaction.Reporter.start_transaction(:web, path(meta, server)) do

start_transaction returns :ignore, so the attributes from the plug telemetry (including host) never get set.

@binaryseed
Copy link
Collaborator

That wouldn't cause the error... when you call NewRelic.ignore_transaction, we end the transaction right away, and don't call complete on it (since that is what would report the transaction)

@binaryseed
Copy link
Collaborator

I was able to reproduce the error locally and have a PR to fix it: #497

The response time metric is a separate issue that I aim to track down soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants