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)


53
54
55
# File 'lib/bitfab/replay_environment.rb', line 53

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
28
29
# File 'lib/bitfab/replay_environment.rb', line 25

def database_url
  snap = require_snapshot
  mark_accessed
  snap.fetch(:database_url)
end

#expires_atObject

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



32
33
34
# File 'lib/bitfab/replay_environment.rb', line 32

def expires_at
  require_snapshot.fetch(:expires_at)
end

#provider_console_urlObject

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



37
38
39
# File 'lib/bitfab/replay_environment.rb', line 37

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.



43
44
45
# File 'lib/bitfab/replay_environment.rb', line 43

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.



59
60
61
62
63
# File 'lib/bitfab/replay_environment.rb', line 59

def snapshot
  snap = read_snapshot
  mark_accessed if snap
  snap
end

#trace_idObject

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



48
49
50
# File 'lib/bitfab/replay_environment.rb', line 48

def trace_id
  require_snapshot.fetch(:trace_id)
end