From c18855d0d3749b4a6563ea3114ada18342a11988 Mon Sep 17 00:00:00 2001 From: Mingfei Shao <2475897+mfshao@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:49:07 -0500 Subject: [PATCH] HP-1696 add faro customized event (#1595) * add faro customized event * fix import * fix study name * better error handling --- package-lock.json | 29 ++++++++++--------- package.json | 1 + .../utils/checkDownloadStatus.tsx | 16 ++++++++-- .../utils/handleDownloadManifestClick.ts | 16 ++++++++-- .../handleExportToWorkspaceClick.ts | 16 ++++++++-- src/Workspace/index.jsx | 7 +++++ 6 files changed, 62 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0555b081dc..7286ebe133 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,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", @@ -4710,9 +4711,9 @@ } }, "node_modules/@grafana/faro-core": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@grafana/faro-core/-/faro-core-1.9.0.tgz", - "integrity": "sha512-mxBeAOmL5aIsYU5hC4Zc0D4TA5UzsbpzD81JPHEaCLmi4PHjFZNC66xYNH2MOJQlsTUGPV/e/bXJS8+F5pfFhg==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@grafana/faro-core/-/faro-core-1.9.1.tgz", + "integrity": "sha512-dAQcuQJXg91oYqCbsuEXXzAW/Z4CLnt1ef7jfW8jui5Ngo+5ZxbFhRmGxMnTqckRti/3q6hxqSc/sYWnu1x78g==", "dependencies": { "@opentelemetry/api": "^1.9.0", "@opentelemetry/otlp-transformer": "^0.52.0" @@ -4750,11 +4751,11 @@ } }, "node_modules/@grafana/faro-web-sdk": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@grafana/faro-web-sdk/-/faro-web-sdk-1.9.0.tgz", - "integrity": "sha512-BRtOpT/Du5pL25AAH0GNM9j7VrJZrDFEumTHG1ku3l+INMZ3j6SqBWiOT5R2Zeh95Tpz848OZoYL8AnN9NocfQ==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@grafana/faro-web-sdk/-/faro-web-sdk-1.9.1.tgz", + "integrity": "sha512-TkSBsYsg+NXsd2QIyDinI0hXJt3rhj5c+uqAliasKkZiPYZ1/HS3XkX1cIsQ/51+uD2fGmilZDVj0sbZnmFuhw==", "dependencies": { - "@grafana/faro-core": "^1.9.0", + "@grafana/faro-core": "^1.9.1", "ua-parser-js": "^1.0.32", "web-vitals": "^4.0.1" } @@ -41878,9 +41879,9 @@ } }, "@grafana/faro-core": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@grafana/faro-core/-/faro-core-1.9.0.tgz", - "integrity": "sha512-mxBeAOmL5aIsYU5hC4Zc0D4TA5UzsbpzD81JPHEaCLmi4PHjFZNC66xYNH2MOJQlsTUGPV/e/bXJS8+F5pfFhg==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@grafana/faro-core/-/faro-core-1.9.1.tgz", + "integrity": "sha512-dAQcuQJXg91oYqCbsuEXXzAW/Z4CLnt1ef7jfW8jui5Ngo+5ZxbFhRmGxMnTqckRti/3q6hxqSc/sYWnu1x78g==", "requires": { "@opentelemetry/api": "^1.9.0", "@opentelemetry/otlp-transformer": "^0.52.0" @@ -41904,11 +41905,11 @@ } }, "@grafana/faro-web-sdk": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@grafana/faro-web-sdk/-/faro-web-sdk-1.9.0.tgz", - "integrity": "sha512-BRtOpT/Du5pL25AAH0GNM9j7VrJZrDFEumTHG1ku3l+INMZ3j6SqBWiOT5R2Zeh95Tpz848OZoYL8AnN9NocfQ==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@grafana/faro-web-sdk/-/faro-web-sdk-1.9.1.tgz", + "integrity": "sha512-TkSBsYsg+NXsd2QIyDinI0hXJt3rhj5c+uqAliasKkZiPYZ1/HS3XkX1cIsQ/51+uD2fGmilZDVj0sbZnmFuhw==", "requires": { - "@grafana/faro-core": "^1.9.0", + "@grafana/faro-core": "^1.9.1", "ua-parser-js": "^1.0.32", "web-vitals": "^4.0.1" }, diff --git a/package.json b/package.json index 2b8dddaa14..c4301b8974 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Discovery/DiscoveryActionBar/utils/checkDownloadStatus.tsx b/src/Discovery/DiscoveryActionBar/utils/checkDownloadStatus.tsx index 30a1f2f355..0287615b88 100644 --- a/src/Discovery/DiscoveryActionBar/utils/checkDownloadStatus.tsx +++ b/src/Discovery/DiscoveryActionBar/utils/checkDownloadStatus.tsx @@ -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'; @@ -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({ diff --git a/src/Discovery/DiscoveryActionBar/utils/handleDownloadManifestClick.ts b/src/Discovery/DiscoveryActionBar/utils/handleDownloadManifestClick.ts index f4cbd9af7d..1ca4d6482f 100644 --- a/src/Discovery/DiscoveryActionBar/utils/handleDownloadManifestClick.ts +++ b/src/Discovery/DiscoveryActionBar/utils/handleDownloadManifestClick.ts @@ -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'; @@ -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)], { diff --git a/src/Discovery/DiscoveryActionBar/utils/handleExportToWorkspaceClick/handleExportToWorkspaceClick.ts b/src/Discovery/DiscoveryActionBar/utils/handleExportToWorkspaceClick/handleExportToWorkspaceClick.ts index 6707746da1..a2af3aeab8 100644 --- a/src/Discovery/DiscoveryActionBar/utils/handleExportToWorkspaceClick/handleExportToWorkspaceClick.ts +++ b/src/Discovery/DiscoveryActionBar/utils/handleExportToWorkspaceClick/handleExportToWorkspaceClick.ts @@ -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'; @@ -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) { diff --git a/src/Workspace/index.jsx b/src/Workspace/index.jsx index c8c3761f97..8649116da4 100644 --- a/src/Workspace/index.jsx +++ b/src/Workspace/index.jsx @@ -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, @@ -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: