Skip to content

Commit

Permalink
fix: hide page.route calls from traces (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Oct 24, 2024
1 parent 8cb44c5 commit 3352d85
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
23 changes: 15 additions & 8 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ def __init__(self, connection: "Connection", object: "ChannelOwner") -> None:
self._guid = object._guid
self._object = object
self.on("error", lambda exc: self._connection._on_event_listener_error(exc))
self._is_internal_type = False

async def send(self, method: str, params: Dict = None) -> Any:
return await self._connection.wrap_api_call(
lambda: self.inner_send(method, params, False)
lambda: self._inner_send(method, params, False),
self._is_internal_type,
)

async def send_return_as_dict(self, method: str, params: Dict = None) -> Any:
return await self._connection.wrap_api_call(
lambda: self.inner_send(method, params, True)
lambda: self._inner_send(method, params, True),
self._is_internal_type,
)

def send_no_reply(self, method: str, params: Dict = None) -> None:
Expand All @@ -73,7 +76,7 @@ def send_no_reply(self, method: str, params: Dict = None) -> None:
)
)

async def inner_send(
async def _inner_send(
self, method: str, params: Optional[Dict], return_as_dict: bool
) -> Any:
if params is None:
Expand Down Expand Up @@ -108,6 +111,9 @@ async def inner_send(
key = next(iter(result))
return result[key]

def mark_as_internal_type(self) -> None:
self._is_internal_type = True


class ChannelOwner(AsyncIOEventEmitter):
def __init__(
Expand All @@ -132,7 +138,6 @@ def __init__(
self._channel: Channel = Channel(self._connection, self)
self._initializer = initializer
self._was_collected = False
self._is_internal_type = False

self._connection._objects[guid] = self
if self._parent:
Expand All @@ -157,9 +162,6 @@ def _adopt(self, child: "ChannelOwner") -> None:
self._objects[child._guid] = child
child._parent = self

def mark_as_internal_type(self) -> None:
self._is_internal_type = True

def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None:
self._event_to_subscription_mapping = mapping

Expand Down Expand Up @@ -359,7 +361,12 @@ def _send_message_to_server(
"params": self._replace_channels_with_guids(params),
"metadata": metadata,
}
if self._tracing_count > 0 and frames and not object._is_internal_type:
if (
self._tracing_count > 0
and frames
and frames
and object._guid != "localUtils"
):
self.local_utils.add_stack_to_tracing_no_reply(id, frames)

self._transport.send(message)
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_local_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self.mark_as_internal_type()
self._channel.mark_as_internal_type()
self.devices = {
device["name"]: parse_device_descriptor(device["descriptor"])
for device in initializer["deviceDescriptors"]
Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self.mark_as_internal_type()
self._channel.mark_as_internal_type()
self._handling_future: Optional[asyncio.Future["bool"]] = None
self._context: "BrowserContext" = cast("BrowserContext", None)
self._did_throw = False
Expand Down Expand Up @@ -603,7 +603,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self.mark_as_internal_type()
self._channel.mark_as_internal_type()
self._on_page_message: Optional[Callable[[Union[str, bytes]], Any]] = None
self._on_page_close: Optional[Callable[[Optional[int], Optional[str]], Any]] = (
None
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self.mark_as_internal_type()
self._channel.mark_as_internal_type()
self._include_sources: bool = False
self._stacks_id: Optional[str] = None
self._is_tracing: bool = False
Expand Down
1 change: 0 additions & 1 deletion tests/async/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ async def test_should_collect_trace_with_resources_but_no_js(
"Page.wait_for_timeout",
"Page.route",
"Page.goto",
"Route.continue_",
"Page.goto",
"Page.close",
]
Expand Down
1 change: 0 additions & 1 deletion tests/sync/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_should_collect_trace_with_resources_but_no_js(
"Page.wait_for_timeout",
"Page.route",
"Page.goto",
"Route.continue_",
"Page.goto",
"Page.close",
]
Expand Down

0 comments on commit 3352d85

Please sign in to comment.