Skip to content

Commit 4d295fa

Browse files
authored
feat(web): provide callback props for logging and telemetry CLOUDP-253932 (#5931)
* feat(web): provide callback props for logging and telemetry * chore: fix tests and checks * fix: restore data-service object.assign
1 parent dd59697 commit 4d295fa

File tree

9 files changed

+418
-160
lines changed

9 files changed

+418
-160
lines changed

package-lock.json

Lines changed: 41 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-logging/src/provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,5 @@ export function withLoggerAndTelemetry<
119119
export function mongoLogId(id: number): MongoLogId { // !dupedLogId
120120
return { __value: id };
121121
}
122+
123+
export type { MongoLogWriter } from 'mongodb-log-writer';

packages/compass-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@mongodb-js/tsconfig-compass": "^1.0.4",
8989
"@mongodb-js/webpack-config-compass": "^1.3.10",
9090
"@testing-library/react": "^12.1.5",
91+
"@testing-library/react-hooks": "^7.0.2",
9192
"@testing-library/user-event": "^13.5.0",
9293
"@types/chai": "^4.2.21",
9394
"@types/chai-dom": "^0.0.10",
@@ -117,7 +118,6 @@
117118
"mongodb": "^6.6.2",
118119
"mongodb-connection-string-url": "^3.0.1",
119120
"mongodb-data-service": "^22.20.2",
120-
"mongodb-log-writer": "^1.4.2",
121121
"nyc": "^15.1.0",
122122
"os-browserify": "^0.3.0",
123123
"path-browserify": "^1.0.1",

packages/compass-web/sandbox/index.tsx

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from 'mongodb-connection-string-url';
2222

2323
import { CompassWeb } from '../src/index';
24-
import { LoggerAndTelemetryProvider } from '@mongodb-js/compass-logging/provider';
2524
import type { ConnectionInfo } from '@mongodb-js/connection-storage/renderer';
2625
import { sandboxLogger } from './sandbox-logger';
2726
import { useWorkspaceTabRouter } from './use-workspace-tab-router';
@@ -276,50 +275,51 @@ function ConnectedApp({ connectionInfo }: { connectionInfo: ConnectionInfo }) {
276275
value={!isAtlas ? connectionInfo : null}
277276
>
278277
<Body as="div" className={sandboxContainerStyles}>
279-
<LoggerAndTelemetryProvider value={sandboxLogger}>
280-
<CompassWeb
281-
{...(isAtlas
282-
? {
283-
orgId: connectionInfo.atlasMetadata.orgId,
284-
projectId: connectionInfo.atlasMetadata.projectId,
278+
<CompassWeb
279+
{...(isAtlas
280+
? {
281+
orgId: connectionInfo.atlasMetadata.orgId,
282+
projectId: connectionInfo.atlasMetadata.projectId,
283+
}
284+
: {
285+
// We don't want to make those props optional as they are
286+
// always required in DE, at the same time we still want to
287+
// support non-Atlas connections in sandbox. For that purpose
288+
// we pass empty strings when connecting here. If those values
289+
// are empty AND sandbox autoconnect provider didn't get the
290+
// value, sandbox will fail to connect
291+
orgId: '',
292+
projectId: '',
293+
})}
294+
initialWorkspace={initialCurrentTabRef.current}
295+
onActiveWorkspaceTabChange={updateCurrentTab}
296+
initialPreferences={{
297+
enablePerformanceAdvisorBanner: isAtlas,
298+
enableAtlasSearchIndexes: !isAtlas,
299+
maximumNumberOfActiveConnections: isAtlas ? 1 : 10,
300+
atlasServiceBackendPreset: atlasServiceSandboxBackendVariant,
301+
}}
302+
renderConnecting={(connectionInfo) => {
303+
return (
304+
<LoadingScreen
305+
connectionString={
306+
connectionInfo?.atlasMetadata?.clusterName ??
307+
connectionInfo?.connectionOptions.connectionString
285308
}
286-
: {
287-
// We don't want to make those props optional as they are
288-
// always required in DE, at the same time we still want to
289-
// support non-Atlas connections in sandbox. For that purpose
290-
// we pass empty strings when connecting here. If those values
291-
// are empty AND sandbox autoconnect provider didn't get the
292-
// value, sandbox will fail to connect
293-
orgId: '',
294-
projectId: '',
295-
})}
296-
initialWorkspace={initialCurrentTabRef.current}
297-
onActiveWorkspaceTabChange={updateCurrentTab}
298-
initialPreferences={{
299-
enablePerformanceAdvisorBanner: isAtlas,
300-
enableAtlasSearchIndexes: !isAtlas,
301-
maximumNumberOfActiveConnections: isAtlas ? 1 : 10,
302-
atlasServiceBackendPreset: atlasServiceSandboxBackendVariant,
303-
}}
304-
renderConnecting={(connectionInfo) => {
305-
return (
306-
<LoadingScreen
307-
connectionString={
308-
connectionInfo?.atlasMetadata?.clusterName ??
309-
connectionInfo?.connectionOptions.connectionString
310-
}
311-
></LoadingScreen>
312-
);
313-
}}
314-
renderError={(_connectionInfo, err) => {
315-
return (
316-
<ErrorScreen
317-
error={err.message ?? 'Error occured when connecting'}
318-
></ErrorScreen>
319-
);
320-
}}
321-
></CompassWeb>
322-
</LoggerAndTelemetryProvider>
309+
></LoadingScreen>
310+
);
311+
}}
312+
renderError={(_connectionInfo, err) => {
313+
return (
314+
<ErrorScreen
315+
error={err.message ?? 'Error occured when connecting'}
316+
></ErrorScreen>
317+
);
318+
}}
319+
onTrack={sandboxLogger.track}
320+
onDebug={sandboxLogger.debug}
321+
onLog={sandboxLogger.log}
322+
></CompassWeb>
323323
</Body>
324324
</SandboxAutoconnectProvider>
325325
);
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import createDebug from 'debug';
2-
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
3-
import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging';
4-
import type { MongoLogWriter } from 'mongodb-log-writer';
52

63
const tracking: { event: string; properties: any }[] = ((
74
globalThis as any
@@ -11,36 +8,16 @@ const logging: { name: string; component: string; args: any[] }[] = ((
118
globalThis as any
129
).logging = []);
1310

14-
export const sandboxLogger = {
15-
createLogger: (component = 'SANDBOX-LOGGER'): LoggerAndTelemetry => {
16-
const logger = (name: 'debug' | 'info' | 'warn' | 'error' | 'fatal') => {
17-
return (...args: any[]) => {
18-
logging.push({ name, component, args });
19-
};
20-
};
21-
22-
const track = (event: string, properties: any) => {
23-
tracking.push({ event, properties });
24-
};
11+
const debug = createDebug(`mongodb-compass:compass-web-sandbox`);
2512

26-
const debug = createDebug(`mongodb-compass:${component.toLowerCase()}`);
13+
export const sandboxLogger = {
14+
log: (name: string, component: string, ...args: any[]) => {
15+
logging.push({ name, component, args });
16+
},
2717

28-
return {
29-
log: {
30-
component,
31-
get unbound() {
32-
return this as unknown as MongoLogWriter;
33-
},
34-
write: () => true,
35-
debug: logger('debug'),
36-
info: logger('info'),
37-
warn: logger('warn'),
38-
error: logger('error'),
39-
fatal: logger('fatal'),
40-
},
41-
debug,
42-
track,
43-
mongoLogId,
44-
};
18+
track: (event: string, properties: any) => {
19+
tracking.push({ event, properties });
4520
},
21+
22+
debug,
4623
};

packages/compass-web/src/compass-web-connection-storage.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)