Skip to content

Commit

Permalink
chore: code review
Browse files Browse the repository at this point in the history
* `module_function` vs repetitive `self.`
* fix a call to `result.to_h` in `.attach_trace_to_result`
  • Loading branch information
Lenny Burdette committed Aug 20, 2019
1 parent a9d376c commit 1a787c8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/apollo-federation/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
module ApolloFederation
module Tracing
KEY = :ftv1
DEBUG_KEY = "#{KEY}_debug".to_sym

def self.use(schema)
module_function

def use(schema)
schema.tracer ApolloFederation::Tracing::Tracer
end

def self.should_add_traces(headers)
def should_add_traces(headers)
headers && headers['apollo-federation-include-trace'] == KEY.to_s
end

def self.attach_trace_to_result(result)
def attach_trace_to_result(result)
return result unless result.context[:tracing_enabled]

trace = result.context.namespace(KEY)
Expand All @@ -32,18 +35,17 @@ def self.attach_trace_to_result(result)
root: trace[:node_map].root,
)

json = result.to_h
result[:extensions] ||= {}
result[:extensions][KEY] = Base64.encode64(proto.class.encode(proto))

if result.context[:debug_tracing]
result[:extensions]["#{KEY}_debug".to_sym] = proto.to_h
result[:extensions][DEBUG_KEY] = proto.to_h
end

json
result.to_h
end

def self.to_proto_timestamp(time)
def to_proto_timestamp(time)
Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
end
end
Expand Down

0 comments on commit 1a787c8

Please sign in to comment.