Skip to content

Commit

Permalink
Merge pull request #14 from bigcommerce/racially-neutral-lang
Browse files Browse the repository at this point in the history
Change to racially neutral terminology across library
  • Loading branch information
splittingred authored Oct 22, 2020
2 parents a79cfd9 + 9e194f6 commit b33f0b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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+.

Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lib/gruf/lightstep/server_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -59,6 +56,19 @@ def call(&_block)

private

##
# @return [Array<String>]
def ignore_methods
@ignore_methods ||= options.fetch(:ignore_methods, nil) || []
end

##
# @return [Array<Symbol>]
#
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
Expand Down
4 changes: 2 additions & 2 deletions spec/gruf/lightstep/server_interceptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b33f0b1

Please sign in to comment.