Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Link the send loop with the edus contexts #5984

Merged
merged 5 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5984.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sending of EDUs when opentracing is enabled with an empty whitelist.
13 changes: 10 additions & 3 deletions synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
set_tag,
start_active_span_follows_from,
tags,
whitelisted_homeserver,
)
from synapse.util.metrics import measure_func

Expand Down Expand Up @@ -59,9 +60,15 @@ def send_new_transaction(self, destination, pending_pdus, pending_edus):
# The span_contexts is a generator so that it won't be evaluated if
# opentracing is disabled. (Yay speed!)

span_contexts = (
extract_text_map(json.loads(edu.get_context())) for edu in pending_edus
)
span_contexts = []
keep_destination = whitelisted_homeserver(destination)

for edu in pending_edus:
context = edu.get_context()
if context:
span_contexts.append(extract_text_map(json.loads(context)))
if keep_destination:
edu.strip_context()

with start_active_span_follows_from("send_transaction", span_contexts):

Expand Down
3 changes: 3 additions & 0 deletions synapse/federation/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Edu(JsonEncodedObject):
def get_context(self):
return getattr(self, "content", {}).get("org.matrix.opentracing_context", "{}")

def strip_context(self):
getattr(self, "content", {})["org.matrix.opentracing_context"] = "{}"


class Transaction(JsonEncodedObject):
""" A transaction is a list of Pdus and Edus to be sent to a remote home
Expand Down
5 changes: 1 addition & 4 deletions synapse/handlers/devicemessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
log_kv,
set_tag,
start_active_span,
whitelisted_homeserver,
)
from synapse.types import UserID, get_domain_from_id
from synapse.util.stringutils import random_string
Expand Down Expand Up @@ -121,9 +120,7 @@ def send_device_message(self, sender_user_id, message_type, messages):
"sender": sender_user_id,
"type": message_type,
"message_id": message_id,
"org.matrix.opentracing_context": json.dumps(context)
if whitelisted_homeserver(destination)
else None,
"org.matrix.opentracing_context": json.dumps(context),
}

log_kv({"local_messages": local_messages})
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def _add_device_change_txn(self, txn, user_id, device_ids, hosts, stream_id):
"ts": now,
"opentracing_context": json.dumps(context)
if whitelisted_homeserver(destination)
else None,
else "{}",
}
for destination in hosts
for device_id in device_ids
Expand Down