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

Expose @service from Gruf::Controllers::Request to interceptors #37

Closed
pedelman opened this issue Dec 14, 2017 · 1 comment · Fixed by #38
Closed

Expose @service from Gruf::Controllers::Request to interceptors #37

pedelman opened this issue Dec 14, 2017 · 1 comment · Fixed by #38

Comments

@pedelman
Copy link
Contributor

pedelman commented Dec 14, 2017

I would like to instrument Gruf endpoints with New Relic. For this I plan to create an interceptor which will utilize the ControllerInstrumentation#perform_action_with_newrelic_trace. http://www.rubydoc.info/github/newrelic/rpm/NewRelic%2FAgent%2FInstrumentation%2FControllerInstrumentation:perform_action_with_newrelic_trace

In order for the requests to show up correctly, I need to pass in the class_name of the controller / service. It seems like the @service is a natural fit for this use case.

https://github.com/bigcommerce/gruf/blob/master/lib/gruf/controllers/request.rb#L54

Herre is an example of the code I wrote which can instrument Gruf endpoints using newrelic, (maybe this is something which can also be brought into Gruf).

require 'new_relic/agent'

module Interceptors
  module Gruf
    ##
    # New Relic transaction tracing for Gruf endpoints
    #
    class NewRelicTracer < ::Gruf::Interceptors::ServerInterceptor
      include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation

      def call
        opts = {
          category: :controller,
          class_name: request.instance_variable_get('@service'),
          name: request.method_key
        }

        perform_action_with_newrelic_trace(opts) do
          yield
        end
      end
    end
  end
end

I would also gladly open a pr to add an attr_reader for the service but figure we may want to have a different approach to expose these values.

@pedelman pedelman changed the title Expose @service from Gruf::Controller::Request to interceptors Expose @service from Gruf::Controllers::Request to interceptors Dec 14, 2017
@pedelman
Copy link
Contributor Author

Ping @splittingred @mattolson @ncancelliere @billthompson

Also @Parad0X this is pretty similar to the exposing of the rpc_desc, perhaps the approach can be similar, I know @splittingred has some ideas on how we want to expose these attributes to interceptors.

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

Successfully merging a pull request may close this issue.

1 participant