Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
Use replay header
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White committed Aug 1, 2023
1 parent 6eedbbd commit b744871
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/autoblocks-replays.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ jobs:
message: request.payload
mappers:
query: properties.payload.query
__autoblocks_replay_trace_id: traceId
# Filter out properties that are expected to be different on each
# run to prevent the replay diffs from containing unnecessary noise
property-filter-config: |
request.payload:
- payload.__autoblocks_replay_trace_id
ai.intermediate.response:
- response.id
- response.created
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__pycache__/
.ruff_cache/

.idea/

*.pyc
*.DS_Store

Expand Down
4 changes: 2 additions & 2 deletions demo_replays/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import request

from demo_replays import bot
from demo_replays.settings import AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME
from demo_replays.settings import AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME
from demo_replays.settings import env

app = Flask(__name__)
Expand All @@ -26,7 +26,7 @@ def main():

# In production we generate a new trace id for each request,
# but in a replay scenario we use the trace id passed in from the replay
trace_id = payload.get(AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME) or str(uuid.uuid4())
trace_id = request.headers.get(AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME) or str(uuid.uuid4())

autoblocks = AutoblocksTracer(
env.AUTOBLOCKS_INGESTION_KEY, trace_id=trace_id, properties=dict(source="DEMO_REPLAYS")
Expand Down
17 changes: 11 additions & 6 deletions demo_replays/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autoblocks.replays import replay_events_from_view
from autoblocks.replays import start_replay

from demo_replays.settings import AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME
from demo_replays.settings import AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME
from demo_replays.settings import env


Expand All @@ -21,7 +21,11 @@ def static():
("eiffel", "Eiffel Tower"),
]:
print(f"Testing static event {trace_id} - {query}")
requests.post("http://localhost:5000", json={AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME: trace_id, "query": query})
requests.post(
"http://localhost:5000",
json={"query": query},
headers={AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME: trace_id},
)


def dynamic():
Expand Down Expand Up @@ -51,8 +55,9 @@ def dynamic():
# The original payload
payload = event.properties["payload"]

# Modify the payload to pass in the replay trace id
payload[AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME] = event.trace_id

# Replay the request
requests.post("http://localhost:5000", json=payload)
requests.post(
"http://localhost:5000",
json=payload,
headers={AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME: event.trace_id},
)
7 changes: 3 additions & 4 deletions demo_replays/settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pydantic_settings import BaseSettings

# A hidden param that is used to override the trace id that would usually
# be randomly generated for each request with the trace id of the event
# that is being replayed
AUTOBLOCKS_REPLAYS_TRACE_ID_PARAM_NAME = "__autoblocks_replay_trace_id"
# When a request is from a replay, this header contains the trace ID of
# the event being replayed.
AUTOBLOCKS_REPLAY_TRACE_ID_HEADER_NAME = "x-autoblocks-replay-trace-id"


# Environment variables
Expand Down

0 comments on commit b744871

Please sign in to comment.