Skip to content

Commit e5637dc

Browse files
authored
fix: add connectionInfo to telemetry calls, and connectionId to events COMPASS-7968 (#5977)
1 parent eebbc52 commit e5637dc

File tree

106 files changed

+1449
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1449
-533
lines changed

configs/eslint-config-compass/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ const tsOverrides = {
3030
const tsxRules = {
3131
...common.tsxRules,
3232
...extraTsRules,
33+
'react-hooks/exhaustive-deps': [
34+
'warn',
35+
{
36+
additionalHooks: 'useTrackOnChange',
37+
},
38+
],
3339
};
3440

3541
const tsxOverrides = {

packages/compass-aggregations/src/components/aggregation-side-panel/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { FeedbackLink } from './feedback-link';
1818
import { addWizard } from '../../modules/pipeline-builder/stage-editor';
1919
import { UseCaseCard } from './stage-wizard-use-cases';
2020
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
21+
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
2122

2223
const containerStyles = css({
2324
height: '100%',
@@ -79,6 +80,7 @@ export const AggregationSidePanel = ({
7980
onSelectUseCase,
8081
}: AggregationSidePanelProps) => {
8182
const track = useTelemetry();
83+
const connectionInfoAccess = useConnectionInfoAccess();
8284
const [searchText, setSearchText] = useState<string>('');
8385
const darkMode = useDarkMode();
8486

@@ -104,12 +106,16 @@ export const AggregationSidePanel = ({
104106
return;
105107
}
106108
onSelectUseCase(id, useCase.stageOperator);
107-
track('Aggregation Use Case Added', {
108-
drag_and_drop: false,
109-
stage_name: useCase.stageOperator,
110-
});
109+
track(
110+
'Aggregation Use Case Added',
111+
{
112+
drag_and_drop: false,
113+
stage_name: useCase.stageOperator,
114+
},
115+
connectionInfoAccess.getCurrentConnectionInfo()
116+
);
111117
},
112-
[onSelectUseCase, track]
118+
[onSelectUseCase, track, connectionInfoAccess]
113119
);
114120

115121
return (

packages/compass-aggregations/src/components/create-view-modal/create-view-modal.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { createView, changeViewName, close } from '../../modules/create-view';
1313
import type { CreateViewRootState } from '../../stores/create-view';
1414
import { withTelemetry } from '@mongodb-js/compass-telemetry/provider';
1515
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
16+
import {
17+
type ConnectionRepository,
18+
withConnectionRepository,
19+
type ConnectionInfo,
20+
} from '@mongodb-js/compass-connections/provider';
1621

1722
const progressContainerStyles = css({
1823
display: 'flex',
@@ -29,9 +34,11 @@ type CreateViewModalProps = {
2934
isDuplicating?: boolean;
3035
source?: string;
3136
pipeline?: unknown[];
37+
connectionId: ConnectionInfo['id'];
3238
isRunning?: boolean;
3339
error: Error | null;
3440
track: TrackFunction;
41+
connectionRepository: ConnectionRepository;
3542
};
3643

3744
class CreateViewModal extends PureComponent<CreateViewModalProps> {
@@ -46,7 +53,11 @@ class CreateViewModal extends PureComponent<CreateViewModalProps> {
4653

4754
componentDidUpdate(prevProps: CreateViewModalProps) {
4855
if (prevProps.isVisible !== this.props.isVisible && this.props.isVisible) {
49-
this.props.track('Screen', { name: 'create_view_modal' });
56+
const connectionInfo =
57+
this.props.connectionRepository.getConnectionInfoById(
58+
this.props.connectionId
59+
);
60+
this.props.track('Screen', { name: 'create_view_modal' }, connectionInfo);
5061
}
5162
}
5263

@@ -107,18 +118,21 @@ const mapStateToProps = (state: CreateViewRootState) => ({
107118
error: state.error,
108119
source: state.source,
109120
pipeline: state.pipeline,
121+
connectionId: state.connectionId,
110122
});
111123

112124
/**
113125
* Connect the redux store to the component.
114126
* (dispatch)
115127
*/
116128
const MappedCreateViewModal = withTelemetry(
117-
connect(mapStateToProps, {
118-
createView,
119-
changeViewName,
120-
closeModal: close,
121-
})(CreateViewModal)
129+
withConnectionRepository(
130+
connect(mapStateToProps, {
131+
createView,
132+
changeViewName,
133+
closeModal: close,
134+
})(CreateViewModal)
135+
)
122136
);
123137

124138
export default MappedCreateViewModal;

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-as-text-workspace/pipeline-editor.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { changeEditorValue } from '../../../modules/pipeline-builder/text-editor
2121
import type { PipelineParserError } from '../../../modules/pipeline-builder/pipeline-parser/utils';
2222
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
2323
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
24+
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
2425

2526
const containerStyles = css({
2627
position: 'relative',
@@ -80,6 +81,7 @@ export const PipelineEditor: React.FunctionComponent<PipelineEditorProps> = ({
8081
}) => {
8182
const fields = useAutocompleteFields(namespace);
8283
const track = useTelemetry();
84+
const connectionInfoAccess = useConnectionInfoAccess();
8385
const editorInitialValueRef = useRef<string>(pipelineText);
8486
const editorCurrentValueRef = useRef<string>(pipelineText);
8587
editorCurrentValueRef.current = pipelineText;
@@ -100,13 +102,17 @@ export const PipelineEditor: React.FunctionComponent<PipelineEditorProps> = ({
100102
!!editorCurrentValueRef.current &&
101103
editorCurrentValueRef.current !== editorInitialValueRef.current
102104
) {
103-
track('Aggregation Edited', {
104-
num_stages,
105-
editor_view_type: 'text',
106-
});
105+
track(
106+
'Aggregation Edited',
107+
{
108+
num_stages,
109+
editor_view_type: 'text',
110+
},
111+
connectionInfoAccess.getCurrentConnectionInfo()
112+
);
107113
editorInitialValueRef.current = editorCurrentValueRef.current;
108114
}
109-
}, [num_stages, track]);
115+
}, [num_stages, track, connectionInfoAccess]);
110116

111117
const annotations: Annotation[] = useMemo(() => {
112118
return syntaxErrors

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-ai.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe('PipelineAI Component', function () {
171171
{
172172
event: 'PipelineAI Feedback',
173173
properties: {
174+
connection_id: 'TEST',
174175
feedback: 'positive',
175176
request_id: 'pineapple',
176177
text: 'this is the pipeline I was looking for',

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-ai.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import type { RootState } from '../../modules';
1515
import { useLogger } from '@mongodb-js/compass-logging/provider';
1616
import { getPipelineStageOperatorsFromBuilderState } from '../../modules/pipeline-builder/builder-helpers';
1717
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
18+
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
1819

1920
const useOnSubmitFeedback = (lastAIPipelineRequestId: string | null) => {
2021
const logger = useLogger('AI-PIPELINE-UI');
2122
const track = useTelemetry();
23+
const connectionInfoAccess = useConnectionInfoAccess();
2224
return useCallback(
2325
(feedback: 'positive' | 'negative', text: string) => {
2426
const { log, mongoLogId } = logger;
@@ -33,19 +35,23 @@ const useOnSubmitFeedback = (lastAIPipelineRequestId: string | null) => {
3335
}
3436
);
3537

36-
track('PipelineAI Feedback', () => ({
37-
feedback,
38-
request_id: lastAIPipelineRequestId,
39-
text,
40-
}));
38+
track(
39+
'PipelineAI Feedback',
40+
() => ({
41+
feedback,
42+
request_id: lastAIPipelineRequestId,
43+
text,
44+
}),
45+
connectionInfoAccess.getCurrentConnectionInfo()
46+
);
4147

4248
openToast('pipeline-ai-feedback-submitted', {
4349
variant: 'success',
4450
title: 'Your feedback has been submitted.',
4551
timeout: 10_000,
4652
});
4753
},
48-
[logger, track, lastAIPipelineRequestId]
54+
[logger, track, lastAIPipelineRequestId, connectionInfoAccess]
4955
);
5056
};
5157

packages/compass-aggregations/src/components/stage-editor/stage-editor.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { RootState } from '../../modules';
2525
import type { PipelineParserError } from '../../modules/pipeline-builder/pipeline-parser/utils';
2626
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
2727
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
28+
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
2829

2930
const editorContainerStyles = css({
3031
display: 'flex',
@@ -97,6 +98,7 @@ export const StageEditor = ({
9798
editorRef,
9899
}: StageEditorProps) => {
99100
const track = useTelemetry();
101+
const connectionInfoAccess = useConnectionInfoAccess();
100102
const darkMode = useDarkMode();
101103
const editorInitialValueRef = useRef<string | null>(stageValue);
102104
const editorCurrentValueRef = useRef<string | null>(stageValue);
@@ -136,16 +138,27 @@ export const StageEditor = ({
136138
!!editorCurrentValueRef.current &&
137139
editorCurrentValueRef.current !== editorInitialValueRef.current
138140
) {
139-
track('Aggregation Edited', {
140-
num_stages: num_stages,
141-
stage_index: index + 1,
142-
stage_action: 'stage_content_changed',
143-
stage_name: stageOperator,
144-
editor_view_type: editor_view_type,
145-
});
141+
track(
142+
'Aggregation Edited',
143+
{
144+
num_stages: num_stages,
145+
stage_index: index + 1,
146+
stage_action: 'stage_content_changed',
147+
stage_name: stageOperator,
148+
editor_view_type: editor_view_type,
149+
},
150+
connectionInfoAccess.getCurrentConnectionInfo()
151+
);
146152
editorInitialValueRef.current = editorCurrentValueRef.current;
147153
}
148-
}, [track, num_stages, index, stageOperator, editor_view_type]);
154+
}, [
155+
track,
156+
num_stages,
157+
index,
158+
stageOperator,
159+
editor_view_type,
160+
connectionInfoAccess,
161+
]);
149162

150163
return (
151164
<div

packages/compass-aggregations/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type DataServiceLocator,
1414
} from '@mongodb-js/compass-connections/provider';
1515
import { createLoggerLocator } from '@mongodb-js/compass-logging/provider';
16-
import { createTelemetryLocator } from '@mongodb-js/compass-telemetry/provider';
16+
import { telemetryLocator } from '@mongodb-js/compass-telemetry/provider';
1717
import type {
1818
OptionalDataServiceProps,
1919
RequiredDataServiceProps,
@@ -27,6 +27,7 @@ import { preferencesLocator } from 'compass-preferences-model/provider';
2727
import { atlasAuthServiceLocator } from '@mongodb-js/atlas-service/provider';
2828
import { atlasAiServiceLocator } from '@mongodb-js/compass-generative-ai/provider';
2929
import { pipelineStorageLocator } from '@mongodb-js/my-queries-storage/provider';
30+
import { connectionRepositoryAccessLocator } from '@mongodb-js/compass-connections/provider';
3031

3132
export const CompassAggregationsHadronPlugin = registerHadronPlugin(
3233
{
@@ -43,7 +44,7 @@ export const CompassAggregationsHadronPlugin = registerHadronPlugin(
4344
instance: mongoDBInstanceLocator,
4445
preferences: preferencesLocator,
4546
logger: createLoggerLocator('COMPASS-AGGREGATIONS-UI'),
46-
track: createTelemetryLocator(),
47+
track: telemetryLocator,
4748
atlasAuthService: atlasAuthServiceLocator,
4849
atlasAiService: atlasAiServiceLocator,
4950
pipelineStorage: pipelineStorageLocator,
@@ -67,8 +68,9 @@ export const CreateViewPlugin = registerHadronPlugin(
6768
},
6869
{
6970
connectionsManager: connectionsManagerLocator,
71+
connectionRepository: connectionRepositoryAccessLocator,
7072
logger: createLoggerLocator('COMPASS-CREATE-VIEW-UI'),
71-
track: createTelemetryLocator(),
73+
track: telemetryLocator,
7274
workspaces: workspacesServiceLocator,
7375
}
7476
);

packages/compass-aggregations/src/modules/aggregation.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const getMockedStore = (
4141
preferences: defaultPreferencesInstance,
4242
logger: createNoopLogger(),
4343
track: createNoopTrack(),
44+
connectionInfoAccess: { getCurrentConnectionInfo: () => {} },
4445
})
4546
)
4647
);

packages/compass-aggregations/src/modules/aggregation.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export const runAggregation = (): PipelineBuilderThunkAction<Promise<void>> => {
289289
return async (
290290
dispatch,
291291
getState,
292-
{ pipelineBuilder, instance, dataService, track }
292+
{ pipelineBuilder, instance, dataService, track, connectionInfoAccess }
293293
) => {
294294
const pipeline = getPipelineFromBuilderState(getState(), pipelineBuilder);
295295

@@ -309,10 +309,14 @@ export const runAggregation = (): PipelineBuilderThunkAction<Promise<void>> => {
309309
type: ActionTypes.RunAggregation,
310310
pipeline,
311311
});
312-
track('Aggregation Executed', () => ({
313-
num_stages: pipeline.length,
314-
editor_view_type: mapPipelineModeToEditorViewType(getState()),
315-
}));
312+
track(
313+
'Aggregation Executed',
314+
() => ({
315+
num_stages: pipeline.length,
316+
editor_view_type: mapPipelineModeToEditorViewType(getState()),
317+
}),
318+
connectionInfoAccess.getCurrentConnectionInfo()
319+
);
316320
return dispatch(fetchAggregationData());
317321
};
318322
};
@@ -363,8 +367,12 @@ export const cancelAggregation = (): PipelineBuilderThunkAction<
363367
void,
364368
Actions
365369
> => {
366-
return (dispatch, getState, { track }) => {
367-
track('Aggregation Canceled');
370+
return (dispatch, getState, { track, connectionInfoAccess }) => {
371+
track(
372+
'Aggregation Canceled',
373+
{},
374+
connectionInfoAccess.getCurrentConnectionInfo()
375+
);
368376
const {
369377
aggregation: { abortController },
370378
} = getState();
@@ -387,7 +395,13 @@ const fetchAggregationData = (
387395
return async (
388396
dispatch,
389397
getState,
390-
{ preferences, logger: { log, mongoLogId }, track, globalAppRegistry }
398+
{
399+
preferences,
400+
logger: { log, mongoLogId },
401+
track,
402+
connectionInfoAccess,
403+
globalAppRegistry,
404+
}
391405
) => {
392406
const {
393407
namespace,
@@ -470,7 +484,11 @@ const fetchAggregationData = (
470484
page,
471485
});
472486
if ((e as MongoServerError).codeName === 'MaxTimeMSExpired') {
473-
track('Aggregation Timed Out', { max_time_ms: maxTimeMS ?? null });
487+
track(
488+
'Aggregation Timed Out',
489+
{ max_time_ms: maxTimeMS ?? null },
490+
connectionInfoAccess.getCurrentConnectionInfo()
491+
);
474492
}
475493
log.warn(
476494
mongoLogId(1001000106),

0 commit comments

Comments
 (0)