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

Mini Profiler UI not displayed when the response is JSON #243

Closed
cireficc opened this issue May 17, 2016 · 21 comments
Closed

Mini Profiler UI not displayed when the response is JSON #243

cireficc opened this issue May 17, 2016 · 21 comments

Comments

@cireficc
Copy link

In a Rails JSON API, the profiler UI is not displayed, which is unfortunate!

A workaround is easy though; you need two tabs open - one for the JSON, one for the profiler. The second tab needs to be any page that renders HTML (for example the root route /). Make the JSON request, then refresh the page that renders HTML, and the profiler UI will show the JSON request.

Can this be fixed so that the profiler UI shows up on JSON-only pages, or is this by design (and why)?

@seanlinsley
Copy link
Contributor

It's impossible for the profiler to show up on JSON requests, because the browser only expects JSON. For HTML requests, we insert JS to render the profiler.

The only way to get around that is by making rack-mini-profiler a browser extension, but that's a huge amount of work.

@kbrock
Copy link
Contributor

kbrock commented Jun 6, 2016

The request is to actively push events to the browsers.

The infrastructure is not in place for this. It seems websockets /server sent events is overkill here.

Maybe when chrome adds adds header cookies for performance data this may become more viable

@SamSaffron
Copy link
Member

A custom page that does a req say every 5-10 seconds to update the list should do the trick without enormous amounts of added complexity. Alternatively you could use message bus on such a page.

Totally support shipping a sample or even a custom page for dealing with this.

@southwolf
Copy link

southwolf commented Sep 25, 2016

The profiler UI will not show up on /404.html in production environment for a rails-api project.

The Rack::MiniProfiler.authorize_request configuration won't help

Repo: https://github.com/southwolf/rack-profiler-in-production

Ruby Version: 2.2.4, Rails version: 4.2.5.1

@kbrock
Copy link
Contributor

kbrock commented Sep 26, 2016

Thanks @southwolf could you create a PR for your issue? This seems like a separate thread.

@kofiav
Copy link

kofiav commented May 1, 2018

I am currently experiencing the same issue as @southwolf and would appreciate some pointers on what to do. I have a rails app that I initialized with the api defaults:

rails new api_name --api

@oyeanuj
Copy link

oyeanuj commented Jul 25, 2018

@SamSaffron or others around, what is the recommended way of using rack-mini-profiler with Rails in API only mode?

@cireficc cireficc changed the title Mini Profiler UI not displayed when the response is JOSN Mini Profiler UI not displayed when the response is JSON Jul 25, 2018
@benterprise
Copy link

Also have an API only app that I'd like to monitor

@printercu
Copy link

Maybe it's possible to add new ?pp= flag which will suppress application output and render profiler layout for that request?

@SamSaffron
Copy link
Member

@oyeanuj / @printercu the workaround is in the OP use two browser windows, one open to an HTML page.

I think we should ship a blank page people can just hit so you can do http://myapp.com/rack-mini-profiler/requests or something to see everything. Then you don't have to roll out your own blank page.

@RudyOnRails
Copy link

How is the profile info sent back to the browser normally? Is there some way to just update the DOM with JSON request profiles as they arrive? Reason I ask is because JSON requests that are mounted in Vue components get profiled just fine as part of the main page load profile I think. Seems like it would't be too difficult to include new subsequent AJAX requests, but I'm not sure how MP works and wouldn't know where to start.

@x-ji
Copy link

x-ji commented May 27, 2019

I added an empty page to my API-only project, but the page doesn't seem to load any resource from rack-mini-profiler (i.e. doesn't make any requests to anything under http://localhost:3000/mini-profiler-resources/). I also explicitly added Rack::MiniProfiler.authorize_request as a before_action, and commented out config.api_only = true in application.rb, but they had no effect either.

I wonder if it has something to do with the fact that the ApplicationController inherits from ActionController::API instead of ActionController::Base?

@x-ji
Copy link

x-ji commented May 27, 2019

Never mind. I think I finally made it work. I just added a completely empty controller action, and left a corresponding template file under app/views/. The template file got rendered automatically and mini profiler showed up.

Also note that you do need to have at least the <body> tag in your template to be rendered, otherwise the mini-profiler divs will not be properly injected.

@x-ji
Copy link

x-ji commented May 27, 2019

So it does look like I had to change ApplicationController to inherit from ActionController::Base instead of ActionController::API to make it work, while I didn't need to do so in a vanilla app initialized with rails new api_name --api. I'm not sure why. Might be something related to Rails version or the configuration of that particular project.

@rinkei
Copy link

rinkei commented Oct 9, 2019

I'm trying to update #396, but I got a trouble.
After getting /rack-mini-profiler/requests, my puma shows bellow logs.

Started GET "/rack-mini-profiler/requests" for 127.0.0.1 at 2019-10-08 12:53:16 +0900
ActionController::RoutingError (No route matches [GET] "/rack-mini-profiler/requests"):

Then puma don't receive any commands and other requests vanish.
Do you have any idea to debug this problem?

@jvalenciag
Copy link

I'm having the same problem, does somebody have any clue of how to fix this?

I'm trying to update #396, but I got a trouble.
After getting /rack-mini-profiler/requests, my puma shows bellow logs.

Started GET "/rack-mini-profiler/requests" for 127.0.0.1 at 2019-10-08 12:53:16 +0900
ActionController::RoutingError (No route matches [GET] "/rack-mini-profiler/requests"):

Then puma don't receive any commands and other requests vanish.
Do you have any idea to debug this problem?

@SamSaffron
Copy link
Member

@OsamaSayegh can you test this out? I would like to make sure /requests route works it makes it practical to debug json only sites.

@OsamaSayegh
Copy link
Collaborator

Looks like I missed this one, sorry!

I tested /rack-mini-profiler/requests on my local Discourse instance and it seemed to work. Here is how I tested it:

  • I opened a new tab and went to /rack-mini-profiler/requests and I saw MP speed badge to the left
  • Opened another tab and loaded a .json route
  • Went back to my MP tab, refreshed the page and it showed me a speed badge for the .json route (along with badges for other things like service worker) and I could see db queries etc.

Is there something I missed here? I was not aware of this little feature so I'm not familiar with how it's supposed to work.

@OsamaSayegh
Copy link
Collaborator

@rinkei @jvalenciag I was able to reproduce this "error" you got but I don't think it's a legit error. If you go to /rack-mini-profiler/requests and see Mini Profiler speed badge on the page, then it is working as expected. Though I've opened #453 to make the error go away.

@OsamaSayegh
Copy link
Collaborator

PR merged, closing this issue.

@benoittgt
Copy link

Hello
I was thinking. It will be nice to have ?pp=request that print the output directly? I didn't look at the code yet but I think it could be even better than having a page with the list of recent request?

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

No branches or pull requests