Skip to content

Commit

Permalink
HP-1696 add faro customized event (#1595)
Browse files Browse the repository at this point in the history
* add faro customized event

* fix import

* fix study name

* better error handling
  • Loading branch information
mfshao authored Sep 16, 2024
1 parent fc33ca8 commit c18855d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
29 changes: 15 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@gen3/guppy": "^0.18.1",
"@gen3/ui-component": "^0.11.4",
"@grafana/faro-core": "^1.9.1",
"@grafana/faro-react": "^1.9.0",
"@mantine/core": "^6.0.21",
"@reactour/tour": "^2.12.0",
Expand Down
16 changes: 13 additions & 3 deletions src/Discovery/DiscoveryActionBar/utils/checkDownloadStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { datadogRum } from '@datadog/browser-rum';
import { faro } from '@grafana/faro-core';
import {
JOB_POLLING_INTERVAL, DOWNLOAD_FAIL_STATUS, DOWNLOAD_SUCCEEDED_MESSAGE,
} from '../DiscoveryActionBarConstants';
Expand Down Expand Up @@ -66,19 +67,28 @@ const checkDownloadStatus = (
});
setTimeout(() => window.open(output), 2000);
const projectNumber = selectedResources.map(
(study) => study.project_number,
(study) => study.project_number || [],
);
const studyName = selectedResources.map(
(study) => study.study_name,
(study) => study.study_metadata?.minimal_info?.study_name || [],
);
const repositoryName = selectedResources.map(
(study) => study.commons,
(study) => study.commons || [],
);
datadogRum.addAction('datasetDownload', {
datasetDownloadProjectNumber: projectNumber,
datasetDownloadStudyName: studyName,
datasetDownloadRepositoryName: repositoryName,
});
faro.api.pushEvent(
'datasetDownload',
// Faro only accept string-string pairs in payload
{
datasetDownloadProjectNumber: projectNumber.join(','),
datasetDownloadStudyName: studyName.join(','),
datasetDownloadRepositoryName: repositoryName.join(','),
},
);
} catch {
// job output is not a url -> then it is an error message
setDownloadStatus({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { datadogRum } from '@datadog/browser-rum';
import { faro } from '@grafana/faro-core';
import FileSaver from 'file-saver';
import { DiscoveryConfig } from '../../DiscoveryConfig';
import assembleFileManifest from './assembleFileManifest';
Expand All @@ -20,14 +21,23 @@ const handleDownloadManifestClick = (
}
// combine manifests from all selected studies
const manifest = assembleFileManifest(manifestFieldName, selectedResources);
const projectNumber = selectedResources.map((study) => study.project_number);
const studyName = selectedResources.map((study) => study.study_name);
const repositoryName = selectedResources.map((study) => study.commons);
const projectNumber = selectedResources.map((study) => study.project_number || []);
const studyName = selectedResources.map((study) => study.study_metadata?.minimal_info?.study_name || []);
const repositoryName = selectedResources.map((study) => study.commons || []);
datadogRum.addAction('manifestDownload', {
manifestDownloadProjectNumber: projectNumber,
manifestDownloadStudyName: studyName,
manifestDownloadRepositoryName: repositoryName,
});
faro.api.pushEvent(
'manifestDownload',
// Faro only accept string-string pairs in payload
{
manifestDownloadProjectNumber: projectNumber.join(','),
manifestDownloadStudyName: studyName.join(','),
manifestDownloadRepositoryName: repositoryName.join(','),
},
);
// download the manifest
const MANIFEST_FILENAME = 'manifest.json';
const blob = new Blob([JSON.stringify(manifest, null, 2)], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { datadogRum } from '@datadog/browser-rum';
import { faro } from '@grafana/faro-core';
import { manifestServiceApiPath, hostname } from '../../../../localconf';
import { DiscoveryConfig } from '../../../DiscoveryConfig';
import { fetchWithCreds } from '../../../../actions';
Expand Down Expand Up @@ -66,14 +67,23 @@ const handleExportToWorkspaceClick = async (
}
});

const projectNumber = selectedResources.map((study) => study.project_number);
const studyName = selectedResources.map((study) => study.study_name);
const repositoryName = selectedResources.map((study) => study.commons);
const projectNumber = selectedResources.map((study) => study.project_number || []);
const studyName = selectedResources.map((study) => study.study_metadata?.minimal_info?.study_name || []);
const repositoryName = selectedResources.map((study) => study.commons || []);
datadogRum.addAction('exportToWorkspace', {
exportToWorkspaceProjectNumber: projectNumber,
exportToWorkspaceStudyName: studyName,
exportToWorkspaceRepositoryName: repositoryName,
});
faro.api.pushEvent(
'exportToWorkspace',
// Faro only accept string-string pairs in payload
{
exportToWorkspaceProjectNumber: projectNumber.join(','),
exportToWorkspaceStudyName: studyName.join(','),
exportToWorkspaceRepositoryName: repositoryName.join(','),
},
);

// post exported manifest to manifestservice
if (manifest.length) {
Expand Down
7 changes: 7 additions & 0 deletions src/Workspace/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Menu, Dropdown, Button as Btn, Tooltip, Space,
} from 'antd';
import { datadogRum } from '@datadog/browser-rum';
import { faro } from '@grafana/faro-core';

import {
DownOutlined, UserOutlined, QuestionCircleOutlined, LoadingOutlined, ExclamationCircleOutlined,
Expand Down Expand Up @@ -320,6 +321,12 @@ class Workspace extends React.Component {
datadogRum.addAction('workspaceLaunch', {
workspaceName: workspace.name,
});
faro.api.pushEvent(
'workspaceLaunch',
{
workspaceName: workspace.name,
},
);
this.checkWorkspaceStatus();
break;
default:
Expand Down

0 comments on commit c18855d

Please sign in to comment.