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

Rails instrumentation does not work with persistence model #238

Closed
trungpham opened this issue Sep 8, 2014 · 10 comments
Closed

Rails instrumentation does not work with persistence model #238

trungpham opened this issue Sep 8, 2014 · 10 comments
Labels

Comments

@trungpham
Copy link

class MyModel
  include Elasticsearch::Persistence::Model
end

I can't seem to get rails timing to work the standalone persistence model. Is it because I'm not using ActiveModel?

@karmi
Copy link
Contributor

karmi commented Sep 9, 2014

Can you provide more information and code, please? I don't have the bandwith to decipher what "get rails timing to work" can mean and try it on my own.

@karmi karmi added the waiting label Sep 9, 2014
@trungpham
Copy link
Author

I added require 'elasticsearch/rails/lograge' to application.rb,
but the elasticsearch_runtime value in the event object is always 0.

https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/lib/elasticsearch/rails/lograge.rb#L25

@karmi
Copy link
Contributor

karmi commented Sep 15, 2014

Well, the persistence doesn't work with the "elasticsearch-persistence" gem, that would have to be added ...

UPDATE: the instrumentation of course...

@lorgio
Copy link

lorgio commented Sep 17, 2014

It looks like there's a difference between the way the persistence gem builds a query in the search method and the one used in elasticsearch-model .

The Instrumentation::Publishers chains to the execute! method, which the persistence-gem does not have.

In the persistence gem, the search method does a client.search call, while the elasticsearch-model creates a SearchRequest object.

@trungpham
Copy link
Author

I think we should instrument the timing at the lowest level possible, so both elasticsearch-model and persistence gems can share them.

@karmi
Copy link
Contributor

karmi commented Sep 29, 2014

I'll have a look into that. I don't think we can re-use the searching code between model and persistence, but it would have been nice to have the instrumentation support for persistence of course.

@karmi karmi added feature and removed waiting labels Sep 29, 2014
@trungpham
Copy link
Author

@karmi awesome!

karmi added a commit that referenced this issue Oct 1, 2014
…est class

Extracted the `gateway.search` call into a specific class, `SearchRequest`,
primarily to allow hooking into the `SearchRequest#execute!` method in Rails instrumentation.

Updated unit tests, this change should be totally opaque to the user.

Related: #238
@karmi karmi closed this as completed in ee29d75 Oct 1, 2014
@karmi
Copy link
Contributor

karmi commented Oct 1, 2014

@trungpham I've spent hours debugging the weird ways Rails calls initializers :), but the instrumentation should be working now. Verified in my own application using Persistence::Model.

There's a slight incovenience with Lograge, since it probably ignores any config.lograge.custom_options when not enabled. I've opened roidrage/lograge#89 for reference.

In the meantime, just copy&paste that code into your production.rb or something like that.

@Mathiou04
Copy link

Mathiou04 commented Aug 31, 2017

Hi,
I am using elasticsearch-persistence (5.0.1) but cannot find a way to instrument it in my development environment.
I tried to require 'elasticsearch/rails/instrumentation' in my application.rb file but this does not seem to work as I do not see any more logs in my rails console.

I suppose I could make it work by overloading the client using option log: true in my model.
Actually I see the instrumentation logs when I instantiate a client:
Elasticsearch::Client.new(log: true).cluster.health
But is there a better way to turn it on once for all models ?

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

No branches or pull requests

4 participants