Skip to content

Commit d703348

Browse files
committed
chore(data-modeling): add telemetry events COMPASS-9785
1 parent 9c656bb commit d703348

File tree

2 files changed

+137
-16
lines changed

2 files changed

+137
-16
lines changed

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -696,38 +696,56 @@ export function deleteRelationship(
696696

697697
export function deleteCollection(
698698
ns: string
699-
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
700-
return applyEdit({ type: 'RemoveCollection', ns });
699+
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
700+
return (dispatch, getState, { track }) => {
701+
track('Data Modeling Collection Removed', {
702+
source: 'side_panel',
703+
});
704+
705+
dispatch(applyEdit({ type: 'RemoveCollection', ns }));
706+
};
701707
}
702708

703709
export function updateCollectionNote(
704710
ns: string,
705711
note: string
706-
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
712+
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
707713
return applyEdit({ type: 'UpdateCollectionNote', ns, note });
708714
}
709715

710716
export function removeField(
711717
ns: string,
712718
field: FieldPath
713-
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
714-
return applyEdit({ type: 'RemoveField', ns, field });
719+
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
720+
return (dispatch, getState, { track }) => {
721+
track('Data Modeling Field Removed', {
722+
source: 'side_panel',
723+
});
724+
725+
dispatch(applyEdit({ type: 'RemoveField', ns, field }));
726+
};
715727
}
716728

717729
export function renameField(
718730
ns: string,
719731
field: FieldPath,
720732
newName: string
721-
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
722-
return applyEdit({ type: 'RenameField', ns, field, newName });
733+
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
734+
return (dispatch, getState, { track }) => {
735+
track('Data Modeling Field Renamed', {
736+
source: 'side_panel',
737+
});
738+
739+
dispatch(applyEdit({ type: 'RenameField', ns, field, newName }));
740+
};
723741
}
724742

725743
export function changeFieldType(
726744
ns: string,
727745
fieldPath: FieldPath,
728746
newTypes: string[]
729747
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
730-
return (dispatch, getState) => {
748+
return (dispatch, getState, { track }) => {
731749
const collectionSchema = selectCurrentModelFromState(
732750
getState()
733751
).collections.find((collection) => collection.ns === ns)?.jsonSchema;
@@ -738,6 +756,26 @@ export function changeFieldType(
738756
});
739757
if (!field) throw new Error('Field not found in schema');
740758
const to = getSchemaWithNewTypes(field.jsonSchema, newTypes);
759+
760+
track('Data Modeling Field Type Changed', {
761+
source: 'side_panel',
762+
// If the field had a single type, we report that, otherwise 'mixed'.
763+
from: field.jsonSchema.bsonType
764+
? Array.isArray(field.jsonSchema.bsonType)
765+
? field.jsonSchema.bsonType.length === 1
766+
? field.jsonSchema.bsonType[0]
767+
: 'mixed'
768+
: field.jsonSchema.bsonType
769+
: undefined,
770+
to: to.bsonType
771+
? Array.isArray(to.bsonType)
772+
? to.bsonType.length === 1
773+
? to.bsonType[0]
774+
: 'mixed'
775+
: to.bsonType
776+
: undefined,
777+
});
778+
741779
dispatch(
742780
applyEdit({
743781
type: 'ChangeFieldType',
@@ -786,10 +824,10 @@ export function addCollection(
786824
ns?: string,
787825
position?: [number, number]
788826
): DataModelingThunkAction<
789-
boolean,
827+
void,
790828
ApplyEditAction | ApplyEditFailedAction | CollectionSelectedAction
791829
> {
792-
return (dispatch, getState) => {
830+
return (dispatch, getState, { track }) => {
793831
const existingCollections = selectCurrentModelFromState(
794832
getState()
795833
).collections;
@@ -802,6 +840,10 @@ export function addCollection(
802840
});
803841
}
804842

843+
track('Data Modeling Collection Added', {
844+
source: 'toolbar',
845+
});
846+
805847
const edit: Omit<
806848
Extract<Edit, { type: 'AddCollection' }>,
807849
'id' | 'timestamp'
@@ -820,7 +862,6 @@ export function addCollection(
820862
position,
821863
};
822864
dispatch(applyEdit(edit));
823-
return true;
824865
};
825866
}
826867

packages/compass-telemetry/src/telemetry-events.ts

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,42 @@ type CreateIndexStrategiesDocumentationClicked = CommonEvent<{
29192919
};
29202920
}>;
29212921

2922+
/**
2923+
* This event is fired when user adds a collection in a data modeling diagram.
2924+
*
2925+
* @category Data Modeling
2926+
*/
2927+
type DataModelingDiagramCollectionAdded = CommonEvent<{
2928+
name: 'Data Modeling Collection Added';
2929+
payload: {
2930+
source: 'toolbar';
2931+
};
2932+
}>;
2933+
2934+
/**
2935+
* This event is fired when user removes a collection in a data modeling diagram.
2936+
*
2937+
* @category Data Modeling
2938+
*/
2939+
type DataModelingDiagramCollectionRemoved = CommonEvent<{
2940+
name: 'Data Modeling Collection Removed';
2941+
payload: {
2942+
source: 'side_panel';
2943+
};
2944+
}>;
2945+
2946+
/**
2947+
* This event is fired when user renames a collection in a data modeling diagram.
2948+
*
2949+
* @category Data Modeling
2950+
*/
2951+
type DataModelingDiagramCollectionRenamed = CommonEvent<{
2952+
name: 'Data Modeling Collection Renamed';
2953+
payload: {
2954+
source: 'side_panel';
2955+
};
2956+
}>;
2957+
29222958
/**
29232959
* This event is fired when a new data modeling diagram is created
29242960
*
@@ -2943,6 +2979,44 @@ type DataModelingDiagramExported = CommonEvent<{
29432979
};
29442980
}>;
29452981

2982+
/**
2983+
* This event is fired when user removes a field in a data modeling diagram.
2984+
*
2985+
* @category Data Modeling
2986+
*/
2987+
type DataModelingDiagramFieldRemoved = CommonEvent<{
2988+
name: 'Data Modeling Field Removed';
2989+
payload: {
2990+
source: 'side_panel';
2991+
};
2992+
}>;
2993+
2994+
/**
2995+
* This event is fired when user renames a field in a data modeling diagram.
2996+
*
2997+
* @category Data Modeling
2998+
*/
2999+
type DataModelingDiagramFieldRenamed = CommonEvent<{
3000+
name: 'Data Modeling Field Renamed';
3001+
payload: {
3002+
source: 'side_panel';
3003+
};
3004+
}>;
3005+
3006+
/**
3007+
* This event is fired when user changes a field type in a data modeling diagram.
3008+
*
3009+
* @category Data Modeling
3010+
*/
3011+
type DataModelingDiagramFieldTypeChanged = CommonEvent<{
3012+
name: 'Data Modeling Field Type Changed';
3013+
payload: {
3014+
source: 'side_panel';
3015+
from?: string;
3016+
to?: string;
3017+
};
3018+
}>;
3019+
29463020
/**
29473021
* This event is fired when user imports data modeling diagram.
29483022
*
@@ -3064,7 +3138,18 @@ export type TelemetryEvent =
30643138
| ConnectionRemovedEvent
30653139
| CurrentOpShowOperationDetailsEvent
30663140
| DatabaseCreatedEvent
3141+
| DataModelingDiagramCollectionAdded
3142+
| DataModelingDiagramCollectionRemoved
3143+
| DataModelingDiagramCollectionRenamed
30673144
| DataModelingDiagramCreated
3145+
| DataModelingDiagramExported
3146+
| DataModelingDiagramFieldRemoved
3147+
| DataModelingDiagramFieldRenamed
3148+
| DataModelingDiagramFieldTypeChanged
3149+
| DataModelingDiagramImported
3150+
| DataModelingDiagramRelationshipAdded
3151+
| DataModelingDiagramRelationshipEdited
3152+
| DataModelingDiagramRelationshipDeleted
30683153
| DeleteExportedEvent
30693154
| DeleteExportOpenedEvent
30703155
| DetailViewHideOperationDetailsEvent
@@ -3161,10 +3246,5 @@ export type TelemetryEvent =
31613246
| CreateIndexIndexSuggestionsCopied
31623247
| CreateIndexStrategiesDocumentationClicked
31633248
| UUIDEncounteredEvent
3164-
| DataModelingDiagramExported
3165-
| DataModelingDiagramImported
3166-
| DataModelingDiagramRelationshipAdded
3167-
| DataModelingDiagramRelationshipEdited
3168-
| DataModelingDiagramRelationshipDeleted
31693249
| ContextMenuOpened
31703250
| ContextMenuItemClicked;

0 commit comments

Comments
 (0)