Skip to content
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
8 changes: 8 additions & 0 deletions packages/devtools-connect/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ async function resolveMongodbSrv(
error,
duringLoad: true,
resolutionDetails,
durationMs: null,
});
}
if (resolveDnsHelpers !== undefined) {
const dnsResolutionStart = Date.now();
try {
const {
wasNativelyLookedUp,
Expand All @@ -181,6 +183,7 @@ async function resolveMongodbSrv(
const resolved = await resolveDnsHelpers.resolve(uri, {
dns: {
resolveSrv(hostname: string, cb: Parameters<typeof resolveSrv>[1]) {
const start = Date.now();
resolveSrv(
hostname,
(...args: Parameters<Parameters<typeof resolveSrv>[1]>) => {
Expand All @@ -189,6 +192,7 @@ async function resolveMongodbSrv(
hostname,
error: args[0]?.message,
wasNativelyLookedUp: wasNativelyLookedUp(args[1]),
durationMs: Date.now() - start,
});
cb(...args);
}
Expand All @@ -198,11 +202,13 @@ async function resolveMongodbSrv(
resolveTxt(
hostname,
(...args: Parameters<Parameters<typeof resolveTxt>[1]>) => {
const start = Date.now();
resolutionDetails.push({
query: 'TXT',
hostname,
error: args[0]?.message,
wasNativelyLookedUp: wasNativelyLookedUp(args[1]),
durationMs: Date.now() - start,
});
cb(...args);
}
Expand All @@ -214,6 +220,7 @@ async function resolveMongodbSrv(
from: uri,
to: resolved,
resolutionDetails,
durationMs: Date.now() - dnsResolutionStart,
});
return resolved;
} catch (error: any) {
Expand All @@ -222,6 +229,7 @@ async function resolveMongodbSrv(
error,
duringLoad: false,
resolutionDetails,
durationMs: Date.now() - dnsResolutionStart,
});
throw error;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/devtools-connect/src/log-hook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ describe('Logging setup', function () {
hostname: 'hello.world',
error: 'failed',
wasNativelyLookedUp: false,
durationMs: 1,
},
],
durationMs: 2,
});
emitter.emit('devtools-connect:resolve-srv-succeeded', {
from: 'mongodb+srv://foo:[email protected]/',
Expand All @@ -67,8 +69,10 @@ describe('Logging setup', function () {
hostname: 'hello.world',
error: undefined,
wasNativelyLookedUp: true,
durationMs: 3,
},
],
durationMs: 4,
});
emitter.emit('devtools-connect:missing-optional-dependency', {
name: 'kerberos',
Expand Down Expand Up @@ -169,8 +173,10 @@ describe('Logging setup', function () {
error: 'failed',
hostname: 'hello.world',
wasNativelyLookedUp: false,
durationMs: 1,
},
],
durationMs: 2,
},
},
{
Expand All @@ -189,8 +195,10 @@ describe('Logging setup', function () {
error: null,
hostname: 'hello.world',
wasNativelyLookedUp: true,
durationMs: 3,
},
],
durationMs: 4,
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools-connect/src/log-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function hookLogger(
error: ev.error?.message,
duringLoad: ev.duringLoad,
resolutionDetails: ev.resolutionDetails,
durationMs: ev.durationMs,
}
);
}
Expand All @@ -137,6 +138,7 @@ export function hookLogger(
from: redactURICredentials(ev.from),
to: redactURICredentials(ev.to),
resolutionDetails: ev.resolutionDetails,
durationMs: ev.durationMs,
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools-connect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ export interface ConnectDnsResolutionDetail {
hostname: string;
error?: string;
wasNativelyLookedUp?: boolean;
durationMs: number;
}

export interface ConnectResolveSrvErrorEvent {
from: string;
error: Error;
duringLoad: boolean;
resolutionDetails: ConnectDnsResolutionDetail[];
durationMs: number | null;
}

export interface ConnectResolveSrvSucceededEvent {
from: string;
to: string;
resolutionDetails: ConnectDnsResolutionDetail[];
durationMs: number | null;
}

export interface ConnectMissingOptionalDependencyEvent {
Expand Down
Loading