diff options
author | Eric Eastwood <erice@element.io> | 2022-07-26 21:53:11 -0500 |
---|---|---|
committer | Eric Eastwood <erice@element.io> | 2022-07-26 21:53:11 -0500 |
commit | 2fe6911957db0d49d68d388aeab479a0bf685949 (patch) | |
tree | 179b4e7a978a841279b6faf23c7a9536ec6f111e /synapse/handlers | |
parent | Migrate to OpenTelemetry tracing (diff) | |
download | synapse-2fe6911957db0d49d68d388aeab479a0bf685949.tar.xz |
Some shim and some new
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/device.py | 28 | ||||
-rw-r--r-- | synapse/handlers/devicemessage.py | 8 | ||||
-rw-r--r-- | synapse/handlers/e2e_keys.py | 26 | ||||
-rw-r--r-- | synapse/handlers/e2e_room_keys.py | 2 | ||||
-rw-r--r-- | synapse/handlers/sync.py | 13 |
5 files changed, 41 insertions, 36 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index 824eaf35d9..a84d417a8a 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -36,7 +36,7 @@ from synapse.api.errors import ( RequestSendFailed, SynapseError, ) -from synapse.logging.opentelemetry import log_kv, set_tag, trace +from synapse.logging.tracing import log_kv, set_attribute, trace from synapse.metrics.background_process_metrics import ( run_as_background_process, wrap_as_background_process, @@ -86,7 +86,7 @@ class DeviceWorkerHandler: info on each device """ - set_tag("user_id", user_id) + set_attribute("user_id", user_id) device_map = await self.store.get_devices_by_user(user_id) ips = await self.store.get_last_client_ip_by_device(user_id, device_id=None) @@ -118,8 +118,8 @@ class DeviceWorkerHandler: ips = await self.store.get_last_client_ip_by_device(user_id, device_id) _update_device_from_client_ips(device, ips) - set_tag("device", str(device)) - set_tag("ips", str(ips)) + set_attribute("device", str(device)) + set_attribute("ips", str(ips)) return device @@ -169,8 +169,8 @@ class DeviceWorkerHandler: joined a room, that `user_id` may be interested in. """ - set_tag("user_id", user_id) - set_tag("from_token", str(from_token)) + set_attribute("user_id", user_id) + set_attribute("from_token", str(from_token)) now_room_key = self.store.get_room_max_token() room_ids = await self.store.get_rooms_for_user(user_id) @@ -461,8 +461,8 @@ class DeviceHandler(DeviceWorkerHandler): except errors.StoreError as e: if e.code == 404: # no match - set_tag("error", True) - set_tag("reason", "User doesn't have that device id.") + set_attribute("error", True) + set_attribute("reason", "User doesn't have that device id.") else: raise @@ -794,8 +794,8 @@ class DeviceListUpdater: for parsing the EDU and adding to pending updates list. """ - set_tag("origin", origin) - set_tag("edu_content", str(edu_content)) + set_attribute("origin", origin) + set_attribute("edu_content", str(edu_content)) user_id = edu_content.pop("user_id") device_id = edu_content.pop("device_id") stream_id = str(edu_content.pop("stream_id")) # They may come as ints @@ -815,7 +815,7 @@ class DeviceListUpdater: origin, ) - set_tag("error", True) + set_attribute("error", True) log_kv( { "message": "Got a device list update edu from a user and " @@ -830,7 +830,7 @@ class DeviceListUpdater: if not room_ids: # We don't share any rooms with this user. Ignore update, as we # probably won't get any further updates. - set_tag("error", True) + set_attribute("error", True) log_kv( { "message": "Got an update from a user for which " @@ -1027,12 +1027,12 @@ class DeviceListUpdater: # eventually become consistent. return None except FederationDeniedError as e: - set_tag("error", True) + set_attribute("error", True) log_kv({"reason": "FederationDeniedError"}) logger.info(e) return None except Exception as e: - set_tag("error", True) + set_attribute("error", True) log_kv( {"message": "Exception raised by federation request", "exception": e} ) diff --git a/synapse/handlers/devicemessage.py b/synapse/handlers/devicemessage.py index 465c4c80ba..c0924adaf7 100644 --- a/synapse/handlers/devicemessage.py +++ b/synapse/handlers/devicemessage.py @@ -19,11 +19,11 @@ from synapse.api.constants import EduTypes, ToDeviceEventTypes from synapse.api.errors import SynapseError from synapse.api.ratelimiting import Ratelimiter from synapse.logging.context import run_in_background -from synapse.logging.opentelemetry import ( +from synapse.logging.tracing import ( SynapseTags, get_active_span_text_map, log_kv, - set_tag, + set_attribute, ) from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet from synapse.types import JsonDict, Requester, StreamKeyType, UserID, get_domain_from_id @@ -217,10 +217,10 @@ class DeviceMessageHandler: sender_user_id = requester.user.to_string() message_id = random_string(16) - set_tag(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id) + set_attribute(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id) log_kv({"number_of_to_device_messages": len(messages)}) - set_tag("sender", sender_user_id) + set_attribute("sender", sender_user_id) local_messages = {} remote_messages: Dict[str, Dict[str, Dict[str, JsonDict]]] = {} for user_id, by_device in messages.items(): diff --git a/synapse/handlers/e2e_keys.py b/synapse/handlers/e2e_keys.py index 5e24c0ef7a..a3692f00d9 100644 --- a/synapse/handlers/e2e_keys.py +++ b/synapse/handlers/e2e_keys.py @@ -28,7 +28,7 @@ from twisted.internet import defer from synapse.api.constants import EduTypes from synapse.api.errors import CodeMessageException, Codes, NotFoundError, SynapseError from synapse.logging.context import make_deferred_yieldable, run_in_background -from synapse.logging.opentelemetry import log_kv, set_tag, tag_args, trace +from synapse.logging.tracing import log_kv, set_attribute, tag_args, trace from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet from synapse.types import ( JsonDict, @@ -138,8 +138,8 @@ class E2eKeysHandler: else: remote_queries[user_id] = device_ids - set_tag("local_key_query", str(local_query)) - set_tag("remote_key_query", str(remote_queries)) + set_attribute("local_key_query", str(local_query)) + set_attribute("remote_key_query", str(remote_queries)) # First get local devices. # A map of destination -> failure response. @@ -342,8 +342,8 @@ class E2eKeysHandler: except Exception as e: failure = _exception_to_failure(e) failures[destination] = failure - set_tag("error", True) - set_tag("reason", str(failure)) + set_attribute("error", True) + set_attribute("reason", str(failure)) return @@ -405,7 +405,7 @@ class E2eKeysHandler: Returns: A map from user_id -> device_id -> device details """ - set_tag("local_query", str(query)) + set_attribute("local_query", str(query)) local_query: List[Tuple[str, Optional[str]]] = [] result_dict: Dict[str, Dict[str, dict]] = {} @@ -420,7 +420,7 @@ class E2eKeysHandler: "user_id": user_id, } ) - set_tag("error", True) + set_attribute("error", True) raise SynapseError(400, "Not a user here") if not device_ids: @@ -477,8 +477,8 @@ class E2eKeysHandler: domain = get_domain_from_id(user_id) remote_queries.setdefault(domain, {})[user_id] = one_time_keys - set_tag("local_key_query", str(local_query)) - set_tag("remote_key_query", str(remote_queries)) + set_attribute("local_key_query", str(local_query)) + set_attribute("remote_key_query", str(remote_queries)) results = await self.store.claim_e2e_one_time_keys(local_query) @@ -494,7 +494,7 @@ class E2eKeysHandler: @trace async def claim_client_keys(destination: str) -> None: - set_tag("destination", destination) + set_attribute("destination", destination) device_keys = remote_queries[destination] try: remote_result = await self.federation.claim_client_keys( @@ -507,8 +507,8 @@ class E2eKeysHandler: except Exception as e: failure = _exception_to_failure(e) failures[destination] = failure - set_tag("error", True) - set_tag("reason", str(failure)) + set_attribute("error", True) + set_attribute("reason", str(failure)) await make_deferred_yieldable( defer.gatherResults( @@ -611,7 +611,7 @@ class E2eKeysHandler: result = await self.store.count_e2e_one_time_keys(user_id, device_id) - set_tag("one_time_key_counts", str(result)) + set_attribute("one_time_key_counts", str(result)) return {"one_time_key_counts": result} async def _upload_one_time_keys_for_user( diff --git a/synapse/handlers/e2e_room_keys.py b/synapse/handlers/e2e_room_keys.py index 28909165f5..8786534e54 100644 --- a/synapse/handlers/e2e_room_keys.py +++ b/synapse/handlers/e2e_room_keys.py @@ -25,7 +25,7 @@ from synapse.api.errors import ( StoreError, SynapseError, ) -from synapse.logging.opentelemetry import log_kv, trace +from synapse.logging.tracing import log_kv, trace from synapse.storage.databases.main.e2e_room_keys import RoomKey from synapse.types import JsonDict from synapse.util.async_helpers import Linearizer diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 524f1470e6..ad71feb774 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -25,7 +25,12 @@ from synapse.api.room_versions import KNOWN_ROOM_VERSIONS from synapse.events import EventBase from synapse.handlers.relations import BundledAggregations from synapse.logging.context import current_context -from synapse.logging.opentelemetry import SynapseTags, log_kv, set_tag, start_active_span +from synapse.logging.tracing import ( + SynapseTags, + log_kv, + set_attribute, + start_active_span, +) from synapse.push.clientformat import format_push_rules_for_user from synapse.storage.databases.main.event_push_actions import NotifCounts from synapse.storage.roommember import MemberSummary @@ -396,7 +401,7 @@ class SyncHandler: sync_config, since_token, full_state ) - set_tag(SynapseTags.SYNC_RESULT, bool(sync_result)) + set_attribute(SynapseTags.SYNC_RESULT, bool(sync_result)) return sync_result async def push_rules_for_user(self, user: UserID) -> Dict[str, Dict[str, list]]: @@ -1337,7 +1342,7 @@ class SyncHandler: # `/sync` message_id = message.pop("message_id", None) if message_id: - set_tag(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id) + set_attribute(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id) logger.debug( "Returning %d to-device messages between %d and %d (current token: %d)", @@ -1997,7 +2002,7 @@ class SyncHandler: upto_token = room_builder.upto_token with start_active_span("sync.generate_room_entry"): - set_tag("room_id", room_id) + set_attribute("room_id", room_id) log_kv({"events": len(events or ())}) log_kv( |