chore: propagate client-side instrumentation across connect (#23524)

Fixes https://github.com/microsoft/playwright/issues/23504
This commit is contained in:
Pavel Feldman 2023-06-05 12:28:20 -07:00 committed by GitHub
parent 2200892ac3
commit def24c0a14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 6 deletions

View File

@ -71,7 +71,7 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap
const connectParams: channels.LocalUtilsConnectParams = { wsEndpoint, headers, slowMo: options.slowMo, timeout: options.timeout };
const { pipe } = await localUtils._channel.connect(connectParams);
const closePipe = () => pipe.close().catch(() => {});
const connection = new Connection(localUtils);
const connection = new Connection(localUtils, this._instrumentation);
connection.markAsRemote();
connection.on('close', closePipe);

View File

@ -156,7 +156,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
connectParams.socksProxyRedirectPortForTest = (params as any).__testHookRedirectPortForwarding;
const { pipe, headers: connectHeaders } = await localUtils._channel.connect(connectParams);
const closePipe = () => pipe.close().catch(() => {});
const connection = new Connection(localUtils);
const connection = new Connection(localUtils, this._instrumentation);
connection.markAsRemote();
connection.on('close', closePipe);

View File

@ -45,6 +45,7 @@ import { LocalUtils } from './localUtils';
import { Tracing } from './tracing';
import { findValidator, ValidationError, type ValidatorContext } from '../protocol/validator';
import { createInstrumentation } from './clientInstrumentation';
import type { ClientInstrumentation } from './clientInstrumentation';
class Root extends ChannelOwner<channels.RootChannel> {
constructor(connection: Connection) {
@ -73,12 +74,13 @@ export class Connection extends EventEmitter {
// Some connections allow resolving in-process dispatchers.
toImpl: ((client: ChannelOwner) => any) | undefined;
private _tracingCount = 0;
readonly _instrumentation = createInstrumentation();
readonly _instrumentation: ClientInstrumentation;
constructor(localUtils?: LocalUtils) {
constructor(localUtils: LocalUtils | undefined, instrumentation: ClientInstrumentation | undefined) {
super();
this._rootObject = new Root(this);
this._localUtils = localUtils;
this._instrumentation = instrumentation || createInstrumentation();
}
markAsRemote() {

View File

@ -24,7 +24,7 @@ import type { Language } from './utils/isomorphic/locatorGenerators';
export function createInProcessPlaywright(): PlaywrightAPI {
const playwright = createPlaywright({ sdkLanguage: (process.env.PW_LANG_NAME as Language | undefined) || 'javascript' });
const clientConnection = new Connection();
const clientConnection = new Connection(undefined, undefined);
const dispatcherConnection = new DispatcherConnection(true /* local */);
// Dispatch synchronously at first.

View File

@ -45,7 +45,7 @@ class PlaywrightClient {
this._driverProcess.unref();
this._driverProcess.stderr!.on('data', data => process.stderr.write(data));
const connection = new Connection();
const connection = new Connection(undefined, undefined);
connection.markAsRemote();
const transport = new PipeTransport(this._driverProcess.stdin!, this._driverProcess.stdout!);
connection.onmessage = message => transport.send(JSON.stringify(message));