Skip to content

Commit

Permalink
fix: Reorder context assignment in producer code.
Browse files Browse the repository at this point in the history
In error logging, we did not have the full_topic
available for searching/alerting because of the order
in which these assignments happened. Reordering them
to try to ensure we always get the full_topic in context.

edx/edx-arch-experiments#411
  • Loading branch information
dianakhuang committed Aug 28, 2023
1 parent 0e86844 commit 67eaea1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Change Log
Unreleased
**********

* Changed ordering of certain context assignments in producer code.

[5.3.1] - 2023-08-10
********************
Fixed
Expand Down
8 changes: 6 additions & 2 deletions edx_event_bus_kafka/internal/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,17 @@ def send(
context = ProducingContext(signal=signal, initial_topic=topic, event_key_field=event_key_field,
event_data=event_data, event_metadata=event_metadata)
try:
context.event_data_as_json = json.dumps(get_signal_serializer(signal).to_dict(event_data))
context.event_metadata_as_json = event_metadata.to_json()
# Please keep these context assignments in order from least-likely-to-error to most-likely-to-error so that we
# have as much context as possible in error logging.
full_topic = get_full_topic(topic)
context.full_topic = full_topic

context.event_data_as_json = json.dumps(get_signal_serializer(signal).to_dict(event_data))
context.event_metadata_as_json = event_metadata.to_json()

event_key = extract_event_key(event_data, event_key_field)
context.event_key = event_key

headers = _get_headers_from_metadata(event_metadata=event_metadata)

key_serializer, value_serializer = get_serializers(signal, event_key_field)
Expand Down

0 comments on commit 67eaea1

Please sign in to comment.