Skip to content

Commit

Permalink
chore: improve types and documentation for telemetry (#6176)
Browse files Browse the repository at this point in the history
* chore: improve types and documentation for telemetry

* fix test and mixed up branches

* add is_favorite and document identify traits

* improve modeForTelemetry type

* remove unnecessary as const
  • Loading branch information
mcasimir authored Sep 10, 2024
1 parent 1e040df commit bea9599
Show file tree
Hide file tree
Showing 13 changed files with 1,219 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('StageEditor [Component]', function () {
syntaxError={null}
serverError={null}
num_stages={0}
editor_view_type=""
editor_view_type="text"
/>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type StageEditorProps = {
syntaxError: PipelineParserError | null;
serverError: MongoServerError | null;
num_stages: number;
editor_view_type: string;
editor_view_type: 'text' | 'stage' | 'focus';
className?: string;
onChange: (index: number, value: string) => void;
editorRef?: React.Ref<EditorRef>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,6 @@ export const connect = (
'Connection Attempt',
{
is_favorite: connectionInfo.savedConnectionType === 'favorite',
is_recent:
!!connectionInfo.lastUsed &&
connectionInfo.savedConnectionType !== 'favorite',
is_new: isNewConnection(getState(), connectionInfo.id),
},
connectionInfo
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-crud/src/stores/crud-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class CrudStoreImpl
* to update if the labels change at some point.
*/
modeForTelemetry() {
return this.state.view.toLowerCase();
return this.state.view.toLowerCase() as Lowercase<DocumentView>;
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/compass-e2e-tests/tests/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ describe('Logging and Telemetry integration', function () {
.events()
.find((entry) => entry.event === 'Connection Attempt');
expect(connectionAttempt.properties.is_favorite).to.equal(false);
expect(connectionAttempt.properties.is_recent).to.equal(false);
expect(connectionAttempt.properties.is_new).to.equal(true);
});

Expand Down
88 changes: 52 additions & 36 deletions packages/compass-export-to-language/src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,51 +146,67 @@ const ExportToLanguageModal: React.FunctionComponent<
const [wasOpen, setWasOpen] = useState(false);

useEffect(() => {
const trackingEvent =
mode === 'Update Query'
? 'Update Export Opened'
: mode === 'Delete Query'
? 'Delete Export Opened'
: mode === 'Query'
? 'Query Export Opened'
: 'Aggregation Export Opened';

if (modalOpen && !wasOpen) {
const connectionInfo = connectionInfoAccess.getCurrentConnectionInfo();
track(
trackingEvent,
{
...stageCountForTelemetry(inputExpression),
},
connectionInfo
);

if (mode === 'Query') {
track('Query Export Opened', {}, connectionInfo);
} else if (mode === 'Delete Query') {
track('Delete Export Opened', {}, connectionInfo);
} else if (mode === 'Update Query') {
track('Update Export Opened', {}, connectionInfo);
} else if (mode === 'Pipeline') {
track(
'Aggregation Export Opened',
{
...stageCountForTelemetry(inputExpression),
},
connectionInfo
);
}

track('Screen', { name: 'export_to_language_modal' }, connectionInfo);
}

setWasOpen(modalOpen);
}, [modalOpen, wasOpen, mode, inputExpression, track, connectionInfoAccess]);

const trackCopiedOutput = useCallback(() => {
const trackingEvent =
mode === 'Update Query'
? 'Update Exported'
: mode === 'Delete Query'
? 'Delete Exported'
: mode === 'Query'
? 'Query Exported'
: 'Aggregation Exported';

track(
trackingEvent,
{
language: outputLanguage,
with_import_statements: includeImports,
with_drivers_syntax: includeDrivers,
with_builders: useBuilders,
...stageCountForTelemetry(inputExpression),
},
connectionInfoAccess.getCurrentConnectionInfo()
);
const commonProps = {
language: outputLanguage,
with_import_statements: includeImports,
with_drivers_syntax: includeDrivers,
with_builders: useBuilders,
};

if (mode === 'Update Query') {
track(
'Update Exported',
commonProps,
connectionInfoAccess.getCurrentConnectionInfo()
);
} else if (mode === 'Delete Query') {
track(
'Delete Exported',
commonProps,
connectionInfoAccess.getCurrentConnectionInfo()
);
} else if (mode === 'Query') {
track(
'Query Exported',
commonProps,
connectionInfoAccess.getCurrentConnectionInfo()
);
} else if (mode === 'Pipeline') {
track(
'Aggregation Exported',
{
...commonProps,
...stageCountForTelemetry(inputExpression),
},
connectionInfoAccess.getCurrentConnectionInfo()
);
}
}, [
track,
connectionInfoAccess,
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-import-export/src/modules/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const startImport = (): ImportThunkAction<Promise<void>> => {
file_type: fileType,
all_fields: exclude.length === 0,
stop_on_error_selected: stopOnErrors,
number_of_docs: err.result.docsWritten,
number_of_docs: err.result?.docsWritten,
success: !err,
aborted: abortSignal.aborted,
ignore_empty_strings: fileType === 'csv' ? ignoreBlanks : undefined,
Expand All @@ -369,7 +369,7 @@ export const startImport = (): ImportThunkAction<Promise<void>> => {
log.error(mongoLogId(1001000081), 'Import', 'Import failed', {
ns,
errorLogFilePath,
docsWritten: err.result.docsWritten,
docsWritten: err.result?.docsWritten,
error: err.message,
});
debug('Error while importing:', err.stack);
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-telemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { createIpcTrack, createIpcSendTrack } from './ipc-track';
export type { TelemetryServiceOptions } from './generic-track';
export type { TrackFunction } from './types';
export type { TrackFunction, IdentifyTraits } from './types';
Loading

0 comments on commit bea9599

Please sign in to comment.