Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
OpenTracing instrumentation for gRPC in Ruby.
It's expected that usage of gRPC libraries across different languages will be consistent. That's why I've based the API on GRPC-Java OpenTracing using Ruby idioms at the same time.
Add this line to your application's Gemfile:
gem 'grpc-opentracing'
And then execute:
$ bundle
Or install it yourself as:
$ gem install grpc-opentracing
If you want to add basic tracing to your clients and servers, you can do so in a few short and simple steps, as shown below. These code snippets use the gRPC example's GreeterGrpc
, generated by protocol buffers.
The gem exposes two tracing and wrapping interceptors:
GRPC::OpenTracing::ClientInterceptor
,GRPC::OpenTracing::ServerInterceptor
.Steps:
GRPC::OpenTracing::ClientInterceptor
require 'grpc'
require 'helloworld_services_pb'
require 'grpc-opentracing'
def build_client(host, creds)
tracing_interceptor = GRPC::OpenTracing::ClientInterceptor.new(tracer: OpenTracing.global_tracer)
client = Helloworld::Greeter::Stub.new(host, creds)
tracing_interceptor.intercept(client)
end
def main
stub = build_client('localhost:50051', :this_channel_is_insecure)
message = stub.say_hello(Helloworld::HelloRequest.new(name: 'world')).message
end
main
tracer: OpenTracing::Tracer
an OT compatible tracer. Default OpenTracing.global_tracer
active_span: Proc
an active span provider. Default: nil
.decorators: Array[SpanDecorator]
a lists of span decorators. Default to [RequestReplySpanDecorator]
GRPC::OpenTracing::ServerInterceptor
require 'grpc'
require 'helloworld_services_pb'
require 'grpc-opentracing'
class GreeterServer < Helloworld::Greeter::Service
def say_hello(hello_req, _unused_call)
Helloworld::HelloReply.new(message: "Hello #{hello_req.name}")
end
end
def main
tracing_interceptor = GRPC::OpenTracing::ServerInterceptor.new(tracer: OpenTracing.global_tracer)
s = GRPC::RpcServer.new
s.add_http2_port('0.0.0.0:50051', :this_port_is_insecure)
s.handle(tracing_interceptor.intercept(GreeterServer))
s.run_till_terminated
end
main
tracer: OpenTracing::Tracer
an OT compatible tracer. Default OpenTracing.global_tracer
active_span: Proc
an active span provider. Default: nil
.decorators: Array[SpanDecorator]
a lists of span decorators. Default to [RequestReplySpanDecorator]
Traced spans can be customized through decorators - SpanDecorator
class. They're called once the processing of a request is done, no matter if the processing has finished with success or failure.
You can provide a set of decorators during an interceptor creation e.g.
class RequestSpanDecorator
def self.call(span, method, request, response, error)
span.set_tag('grpc.request', request.to_json) if request
end
end
tracing_interceptor = GRPC::OpenTracing::ServerInterceptor.new(decorators: [RequestSpanDecorator])
tracing_interceptor = GRPC::OpenTracing::ClientInterceptor.new(decorators: [RequestSpanDecorator])
Notice that by default RequestReplySpanDecorator
is attached, so if you want to preserve the behaviour make sure to append it to the decorators
list.
span: OpenTracing::Span
the current active span.method: String
current method name in the /service_name/method_name
form.request
an instance of gRPC message class e.g. Helloworld::HelloRequest
.response
an instance of gRPC message class e.g. Helloworld::HelloReply
.error: Exception
an exception. Set in case of processing failure.After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/iaintshine/ruby-grpc-opentracing. 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.
Everyone interacting in the GRPC::OpenTracing project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that grpc-opentracing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.