Class: Bitfab::ReplayEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/bitfab/replay_environment.rb

Overview

Per-trace environment exposed to customer code during replay.

The customer instantiates one ReplayEnvironment and passes it to client.replay(environment: …). Inside the replayed method they read env.database_url (and friends) to pick up the per-trace branch URL the Bitfab service resolved from the source trace’s snapshot reference.

Outside replay, reading env.database_url raises. Customer code uses the env only on the replay path; live request code keeps reading ENV the normal way.

Concurrency-safe: the readers resolve through the thread-local replay context, so each in-flight replay item sees its own per-trace values even when the SDK runs items across worker threads.

Internally the resolved per-item state is a DB branch lease (the SDK <-> server protocol term). We expose its useful fields directly here so customer code never sees the word.

Instance Method Summary collapse

Instance Method Details

#active?Boolean

True when read inside a replay item that has a resolved branch.

Returns:

  • (Boolean)


51
52
53
# File 'lib/bitfab/replay_environment.rb', line 51

def active?
  !read_snapshot.nil?
end

#database_urlObject

The per-trace branch URL for the item currently being replayed. Raises if read outside a replay item.



25
26
27
# File 'lib/bitfab/replay_environment.rb', line 25

def database_url
  require_snapshot.fetch(:database_url)
end

#expires_atObject

When the per-trace branch URL stops being valid. ISO-8601.



30
31
32
# File 'lib/bitfab/replay_environment.rb', line 30

def expires_at
  require_snapshot.fetch(:expires_at)
end

#provider_console_urlObject

Deep link to the branch in the provider console, if available.



35
36
37
# File 'lib/bitfab/replay_environment.rb', line 35

def provider_console_url
  require_snapshot[:provider_console_url]
end

#read_onlyObject

True if the branch is read-only. Customer code can use this to skip write operations during replay when the provider returned a read-only lease.



41
42
43
# File 'lib/bitfab/replay_environment.rb', line 41

def read_only
  require_snapshot[:read_only]
end

#snapshotObject

Non-raising variant for callers that handle the inactive case. Returns a symbol-keyed hash or nil.



57
58
59
# File 'lib/bitfab/replay_environment.rb', line 57

def snapshot
  read_snapshot
end

#trace_idObject

The historical trace ID that produced the input for this replay item.



46
47
48
# File 'lib/bitfab/replay_environment.rb', line 46

def trace_id
  require_snapshot.fetch(:trace_id)
end