Add some more opentracing to sliding sync (#17501)

This will make it easier to see what it is doing in jaeger.
This commit is contained in:
Erik Johnston 2024-07-30 10:54:11 +01:00 committed by GitHub
parent 808dab0699
commit 62ae56a4ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 5 deletions

1
changelog.d/17501.misc Normal file
View file

@ -0,0 +1 @@
Add some opentracing tags and logging to the experimental sliding sync implementation.

View file

@ -41,7 +41,7 @@ from synapse.api.constants import AccountDataTypes, Direction, EventTypes, Membe
from synapse.events import EventBase
from synapse.events.utils import strip_event
from synapse.handlers.relations import BundledAggregations
from synapse.logging.opentracing import start_active_span, tag_args, trace
from synapse.logging.opentracing import log_kv, start_active_span, tag_args, trace
from synapse.storage.databases.main.roommember import extract_heroes_from_room_summary
from synapse.storage.databases.main.stream import CurrentStateDeltaMembership
from synapse.storage.roommember import MemberSummary
@ -444,6 +444,7 @@ class SlidingSyncHandler:
return result
@trace
async def current_sync_for_user(
self,
sync_config: SlidingSyncConfig,
@ -682,6 +683,7 @@ class SlidingSyncHandler:
if room_sync_result or not from_token:
rooms[room_id] = room_sync_result
if relevant_room_map:
with start_active_span("sliding_sync.generate_room_entries"):
await concurrently_execute(handle_room, relevant_room_map, 10)
@ -1161,6 +1163,7 @@ class SlidingSyncHandler:
# return None
@trace
async def filter_rooms(
self,
user: UserID,
@ -1284,6 +1287,7 @@ class SlidingSyncHandler:
# Assemble a new sync room map but only with the `filtered_room_id_set`
return {room_id: sync_room_map[room_id] for room_id in filtered_room_id_set}
@trace
async def sort_rooms(
self,
sync_room_map: Dict[str, _RoomMembershipForUser],
@ -1492,6 +1496,10 @@ class SlidingSyncHandler:
else:
assert_never(room_status.status)
log_kv({"sliding_sync.room_status": room_status})
log_kv({"sliding_sync.from_bound": from_bound, "sliding_sync.initial": initial})
# Assemble the list of timeline events
#
# FIXME: It would be nice to make the `rooms` response more uniform regardless of
@ -1890,6 +1898,7 @@ class SlidingSyncHandler:
highlight_count=0,
)
@trace
async def get_extensions_response(
self,
sync_config: SlidingSyncConfig,
@ -1942,6 +1951,7 @@ class SlidingSyncHandler:
account_data=account_data_response,
)
@trace
async def get_to_device_extension_response(
self,
sync_config: SlidingSyncConfig,
@ -2016,6 +2026,7 @@ class SlidingSyncHandler:
events=messages,
)
@trace
async def get_e2ee_extension_response(
self,
sync_config: SlidingSyncConfig,
@ -2066,6 +2077,7 @@ class SlidingSyncHandler:
device_unused_fallback_key_types=device_unused_fallback_key_types,
)
@trace
async def get_account_data_extension_response(
self,
sync_config: SlidingSyncConfig,

View file

@ -52,7 +52,7 @@ from synapse.http.servlet import (
parse_string,
)
from synapse.http.site import SynapseRequest
from synapse.logging.opentracing import trace_with_opname
from synapse.logging.opentracing import log_kv, set_tag, trace_with_opname
from synapse.rest.admin.experimental_features import ExperimentalFeature
from synapse.types import JsonDict, Requester, SlidingSyncStreamToken, StreamToken
from synapse.types.rest.client import SlidingSyncBody
@ -897,7 +897,23 @@ class SlidingSyncRestServlet(RestServlet):
# by filter ID. For now, we will just prototype with always passing everything
# in.
body = parse_and_validate_json_object_from_request(request, SlidingSyncBody)
logger.info("Sliding sync request: %r", body)
# Tag and log useful data to differentiate requests.
set_tag("sliding_sync.conn_id", body.conn_id or "")
log_kv(
{
"sliding_sync.lists": {
list_name: {
"ranges": list_config.ranges,
"timeline_limit": list_config.timeline_limit,
}
for list_name, list_config in (body.lists or {}).items()
},
"sliding_sync.room_subscriptions": list(
(body.room_subscriptions or {}).keys()
),
}
)
sync_config = SlidingSyncConfig(
user=user,