-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathmemory_backend.rb
More file actions
45 lines (39 loc) · 1.02 KB
/
memory_backend.rb
File metadata and controls
45 lines (39 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
module GraphQL
module Tracing
class PerfettoSampler
# An in-memory trace storage backend. Suitable for testing and development only.
# It won't work for multi-process deployments and everything is erased when the app is restarted.
class MemoryBackend
def initialize
@traces = {}
end
def traces
@traces.values
end
def find_trace(id)
@traces[id]
end
def delete_trace(id)
@traces.delete(id)
nil
end
def delete_all_traces
@traces.clear
nil
end
def save_trace(operation_name, duration, timestamp, trace_data)
id = @traces.size
@traces[id] = PerfettoSampler::StoredTrace.new(
id: id,
operation_name: operation_name,
duration_ms: duration,
timestamp: timestamp,
trace_data: trace_data
)
id
end
end
end
end
end