Add Stackdriver trace support for gruf.
Add this line to your application's Gemfile:
gem 'gruf-stackdriver-trace'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gruf-stackdriver-trace
Configure and use interceptor in gruf's initializer.
require 'gruf/stackdriver_trace'
Gruf.configure do |c|
# optional
Gruf::StackdriverTrace.configure do |config|
end
c.interceptors.use(Gruf::StackdriverTrace::ServerInterceptor)
end
Specify Gruf::StackdriverTrace::ClientInterceptor
instance to client_options[:interceptors]
.
client = Gruf::Client.new(
service: Rpc::Products,
client_options: {
interceptors: [
Gruf::StackdriverTrace::ClientInterceptor.new
]
}
)
resp = client.call(:GetProduct)
NOTE: Gruf::StackdriverTrace::ClientInterceptor
will not be enabled if the tracing context of Gruf::StackdriverTrace::ServerInterceptor
or Stackdriver Trace(ex. use with Rails middleware) cannot be obtained.
You can configure with Gruf::StackdriverTrace.configure { |config| ... }
.
config[:service]
(default:nil
)- A reporter Class that provides to send traced data
- SEE: https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-trace/lib/google/cloud/trace/async_reporter.rb
config[:sampled]
(default:true
)- Whether to capture tracing
true
: enable tracingfalse
: disable tracing- ex.
config[:sampled] = Rails.env.production?
to be enable tracing in only production env.
config[:capture_stack]
(default:true
)- Whether to capture stack traces for each span
true
: enable to recording of stack tracefalse
: disable to recording of stack trace
config[:sampler]
(default:nil
)- A sampler Class makes the decision whether to record a trace for each request
- SEE: https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-trace/lib/google/cloud/trace/time_sampler.rb
config[:span_id_generator]
(default:nil
)- A generator Proc that generates the name String for new TraceRecord
- SEE: https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-trace/lib/google/cloud/trace/trace_record.rb#L59-L60
If you are running the application locally, in self-hosted VMs, or a third party hosting service, you will need to provide the project ID and credentials (keyfile) to the Google Cloud client library. See this section for details.
ex.
Google::Cloud.configure do |config|
config.project_id = "your-project-id"
config.keyfile = "path/to/service-account.json"
end
TODO
Bug reports and pull requests are welcome on GitHub at https://github.com/atman-inc/gruf-stackdriver-trace. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Gruf::StackdriverTrace project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.