diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bfd25b..1ce909f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ Changelog for the gruf-lightstep gem. ### Pending Release +- Move from whitelist -> allowlist in server interceptor + ### 1.3.0 - Bump Ruby requirement to 2.6+ @@ -26,7 +28,7 @@ Changelog for the gruf-lightstep gem. - First OSS release - Explicitly require bc-lightstep-ruby dependency -- Add option to whitelist request params to lightstep as span tags +- Add option to allowlist request params to lightstep as span tags ### 1.1.1 diff --git a/README.md b/README.md index ce4b039..0808dc9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gruf-lightstep - LightStep tracing for gruf -[![CircleCI](https://circleci.com/gh/bigcommerce/gruf-lightstep/tree/master.svg?style=svg)](https://circleci.com/gh/bigcommerce/gruf-lightstep/tree/master) [![Gem Version](https://badge.fury.io/rb/gruf-lightstep.svg)](https://badge.fury.io/rb/gruf-lightstep) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-lightstep.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-lightstep) +[![CircleCI](https://circleci.com/gh/bigcommerce/gruf-lightstep/tree/main.svg?style=svg)](https://circleci.com/gh/bigcommerce/gruf-lightstep/tree/main) [![Gem Version](https://badge.fury.io/rb/gruf-lightstep.svg)](https://badge.fury.io/rb/gruf-lightstep) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-lightstep.svg?branch=main)](http://inch-ci.org/github/bigcommerce/gruf-lightstep) Adds LightStep tracing support for [gruf](https://github.com/bigcommerce/gruf) 2.0.0+. @@ -43,11 +43,11 @@ It comes with a few more options as well: | Option | Description | Default | | ------ | ----------- | ------- | -| whitelist | An array of parameter key names to log to lightstep. E.g. `[uuid kind]` | `[]` | +| allowlist | An array of parameter key names to log to lightstep. E.g. `[uuid kind]` | `[]` | | ignore_methods | An array of method names to ignore from logging. E.g. `['namespace.health.check']` | `[]` | -It's important to maintain a safe whitelist should you decide to log parameters; gruf does no -parameter sanitization on its own. We also recommend do not whitelist parameters that may contain +It's important to maintain a safe allowlist should you decide to log parameters; gruf does no +parameter sanitization on its own. We also recommend do not allowlist parameters that may contain very large values (such as binary or json data). ### Client Interceptors diff --git a/lib/gruf/lightstep/server_interceptor.rb b/lib/gruf/lightstep/server_interceptor.rb index 3fb3614..76f363c 100644 --- a/lib/gruf/lightstep/server_interceptor.rb +++ b/lib/gruf/lightstep/server_interceptor.rb @@ -25,13 +25,10 @@ class ServerInterceptor < Gruf::Interceptors::ServerInterceptor # Handle the gruf around hook and trace sampled requests # def call(&_block) - return yield if options.fetch(:ignore_methods, []).include?(request.method_name) + return yield if ignore_methods.include?(request.method_name) result = nil - - whitelist = options.fetch(:whitelist, []).map(&:to_s).map(&:to_sym) params = request_message_params - tracer = ::Bigcommerce::Lightstep::Tracer.instance tracer.clear_active_span! # because we're always starting from the top on a gRPC boundary tracer.start_span(request.method_name, context: request_method.headers.to_h) do |span| @@ -40,7 +37,7 @@ def call(&_block) span.set_tag('grpc.service', request.service_key) span.set_tag('span.kind', 'server') - whitelist.each do |param| + allowlist.each do |param| span.set_tag(param.to_s, params[param]) if params.key?(param) end @@ -59,6 +56,19 @@ def call(&_block) private + ## + # @return [Array] + def ignore_methods + @ignore_methods ||= options.fetch(:ignore_methods, nil) || [] + end + + ## + # @return [Array] + # + def allowlist + @allowlist ||= (options.fetch(:allowlist, nil) || []).map(&:to_s).map(&:to_sym) + end + ## # @param [StandardError] # @return [Number] that maps to one of the GRCP::Core::StatusCodes or Gruf::Lightstep.default_error_code diff --git a/spec/gruf/lightstep/server_interceptor_spec.rb b/spec/gruf/lightstep/server_interceptor_spec.rb index d069725..77b9124 100644 --- a/spec/gruf/lightstep/server_interceptor_spec.rb +++ b/spec/gruf/lightstep/server_interceptor_spec.rb @@ -112,8 +112,8 @@ end end - context 'with request param whitelist' do - let(:options) { { whitelist: ['uuid'] } } + context 'with request param allowlist' do + let(:options) { { allowlist: ['uuid'] } } let(:span) { double(:span, set_tag: true) } it 'should only trace the uuid request param' do