Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
fix(tracing): fix multiplexed tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
lsanwick committed Oct 22, 2020
1 parent dc8e31d commit 43b6c86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/apollo-studio-tracing/trace_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def send_report(traces_per_query)
end

def to_proto_timestamp(time)
Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time&.nsec || 0)
Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
end
end
# rubocop:enable Metrics/ClassLength
Expand Down
24 changes: 14 additions & 10 deletions lib/apollo-studio-tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def execute_multiplex(data, &block)
results = block.call

# Step 5
# Attach the trace to the 'extensions' key of each result
# Enqueue the final trace onto the TraceChannel.
results.map { |result| attach_trace_to_result(result) }
end

Expand Down Expand Up @@ -234,20 +234,24 @@ def execute_field_lazy(data, &block)
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# Step 4:
# Record end times and merge them into the trace hash. Enqueue the final trace onto the
# TraceChannel.
# Record end times and merge them into the trace hash
def execute_query_lazy(data, &block)
result = block.call

query = data.fetch(:query)
return result unless tracing_enabled?(query&.context)
# Normalize to an array of queries regardless of whether we are multiplexing or performing a
# single query.
queries = Array(data.fetch(:multiplex)&.queries || data.fetch(:query))

trace = query.context.namespace(ApolloStudioTracing::KEY)
queries.map do |query|
next unless tracing_enabled?(query&.context)

trace.merge!(
end_time: Time.now.utc,
end_time_nanos: Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond),
)
trace = query.context.namespace(ApolloStudioTracing::KEY)

trace.merge!(
end_time: Time.now.utc,
end_time_nanos: Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond),
)
end

result
end
Expand Down

0 comments on commit 43b6c86

Please sign in to comment.