Skip to content

Server: Instrumentation and Logging

Shaun McCormick edited this page Jan 22, 2024 · 5 revisions

gruf comes out of the box with a couple of instrumentation interceptors packed in: output metadata timings and StatsD support.

Output Metadata Timing

Enabled by default, this will push timings for successful responses through the response output metadata back to the client.

StatsD

The StatsD support is not enabled by default. To enable it, you'll want to do:

Gruf.configure do |c|
  c.interceptors.use(
    Gruf::Interceptors::Instrumentation::Statsd,
    client: ::Statsd.new('my.statsd.host', 8125),
    prefix: 'my_application_prefix.rpc'
  )
end

This will measure counts and timings for each endpoint.

Request Logging

Gruf 1.2+ comes built with request logging out of the box; you'll get Rails-style logs with your gRPC calls:

# plain
I, [2017-07-14T09:50:54.200506 #70571]  INFO -- : [GRPC::Ok] (thing_service.get_thing) [0.348ms]
# logstash
I, [2017-07-14T09:51:03.299050 #70595]  INFO -- : {"message":"[GRPC::Ok] (thing_service.get_thing) [0.372ms]","service":"thing_service","method":"thing_service.get_thing","grpc_status":"GRPC::Ok"}

It supports formatters (including custom ones) that you can use to specify the formatting of the logging:

Gruf.configure do |c|
  c.interceptors.use(
    Gruf::Interceptors::Instrumentation::RequestLogging::Interceptor,
    formatter: :logstash
  )
end

It comes with a few more options as well:

Option Description Default
formatter The formatter to use. By default :plain and :logstash are supported. :logstash
log_parameters If set to true, will log parameters in the response false
blocklist An array of parameter key names to redact from logging, in path.to.key format []
redacted_string The string to use for redacted parameters. REDACTED
ignore_methods An array of method names to ignore from logging. E.g. ['namespace.health.check'] []

It's important to maintain a safe blocklist should you decide to log parameters; gruf does no parameter sanitization on its own. We also recommend blocklisting parameters that may contain very large values (such as binary or json data).

Other Options

There are other options for observability packaged as gems:


Next: Server: Testing