generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into ui5-2.0-FF_template-u…
…pdate * origin/main: chore: apply latest changesets feat(fiori-gen): add telemetry helper class and associated functions (#2489)
- Loading branch information
Showing
31 changed files
with
528 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
export * from './cap'; | ||
export * from './environment'; | ||
export * from './logWrapper'; | ||
export * from './system-utils'; | ||
export * from './telemetry'; | ||
export { getPackageScripts } from './getPackageScripts'; | ||
export { getBootstrapResourceUrls, getDefaultTargetFolder } from './helpers'; | ||
export { generateReadMe } from './read-me'; | ||
export * from './system-utils'; | ||
export { PackageJsonScripts, YeomanEnvironment, VSCodeInstance } from './types'; | ||
export * from './logWrapper'; | ||
export { getHostEnvironment } from './environment'; | ||
export { isExtensionInstalled } from './installedCheck'; | ||
export { PackageJsonScripts, YeomanEnvironment, VSCodeInstance, hostEnvironment } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { coerce, lt } from 'semver'; | ||
|
||
/** | ||
* Check for an installed extension, optionally specifying a minimum version. | ||
* Note, this does not check for activation state of specified extension. | ||
* | ||
* @param vscode - vscode instance | ||
* @param extensionId - the id of the extension to find | ||
* @param minVersion - the minimum version of the specified extension, lower versions will not be returned. Must be a valid SemVer string. | ||
* @returns true if the extension is installed and the version is >= minVersion (if provided), false otherwise | ||
*/ | ||
export function isExtensionInstalled(vscode: any, extensionId: string, minVersion?: string): boolean { | ||
const foundExt = vscode?.extensions?.getExtension(extensionId); | ||
if (foundExt) { | ||
const extVersion = coerce(foundExt.packageJSON.version); | ||
if (extVersion) { | ||
// Check installed ver is >= minVersion or return true if minVersion is not specified | ||
return !(minVersion && lt(extVersion, minVersion)); | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { sendTelemetry, sendTelemetryBlocking } from './utils'; | ||
export * from './telemetryHelper'; |
103 changes: 103 additions & 0 deletions
103
packages/fiori-generator-shared/src/telemetry/telemetryHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
PerformanceMeasurementAPI as Performance, | ||
initTelemetrySettings, | ||
type TelemetryProperties, | ||
type ToolsSuiteTelemetryInitSettings | ||
} from '@sap-ux/telemetry'; | ||
import type { TelemetryData } from './types'; | ||
import { getHostEnvironment } from '../environment'; | ||
import osName from 'os-name'; | ||
import { t } from '../i18n'; | ||
|
||
/** | ||
* Helper class for intialising and preparing event data for telemetry. | ||
*/ | ||
export abstract class TelemetryHelper { | ||
private static _telemetryData: TelemetryData; | ||
private static _previousEventTimestamp: number; | ||
|
||
/** | ||
* Returns the telemetry data. | ||
* | ||
* @returns telemetry data | ||
*/ | ||
public static get telemetryData(): TelemetryData { | ||
return this._telemetryData; | ||
} | ||
|
||
/** | ||
* Load telemetry settings. | ||
* | ||
* @param options - tools suite telemetry init settings | ||
*/ | ||
public static async initTelemetrySettings(options: ToolsSuiteTelemetryInitSettings): Promise<void> { | ||
await initTelemetrySettings(options); | ||
} | ||
|
||
/** | ||
* Creates telemetry data and adds default telemetry props. | ||
* | ||
* @param additionalData - set additional properties to be reported by telemetry | ||
* @param filterDups - filters duplicates by returning undefined if it's suspected to be a repeated event based on previous telemetry data & timestamp (1 second) | ||
* @returns telemetry data | ||
*/ | ||
public static createTelemetryData<T extends TelemetryProperties>( | ||
additionalData?: Partial<T>, | ||
filterDups = false | ||
): TelemetryData | undefined { | ||
const currentTimestamp = new Date().getTime(); | ||
if (!this._previousEventTimestamp) { | ||
filterDups = false; // can't filter duplicates if no previous event timestamp | ||
this._previousEventTimestamp = currentTimestamp; | ||
} | ||
|
||
if (!this._telemetryData) { | ||
let osVersionName = t('telemetry.unknownOs'); | ||
try { | ||
osVersionName = osName(); | ||
} catch { | ||
// no matched os name, possible beta or unreleased version | ||
} | ||
this._telemetryData = { | ||
Platform: getHostEnvironment().technical, | ||
OperatingSystem: osVersionName | ||
}; | ||
} | ||
|
||
if (filterDups) { | ||
const newTelemData = { ...this._telemetryData, ...additionalData }; | ||
if ( | ||
Math.abs(this._previousEventTimestamp - currentTimestamp) < 1000 && | ||
JSON.stringify(newTelemData) === JSON.stringify(this._telemetryData) | ||
) { | ||
return undefined; | ||
} | ||
} | ||
this._previousEventTimestamp = currentTimestamp; | ||
this._telemetryData = Object.assign(this._telemetryData, additionalData); | ||
|
||
return this._telemetryData; | ||
} | ||
|
||
/** | ||
* Marks the start time. Example usage: | ||
* At the start of of the writing phase of the yeoman generator. | ||
* It should not be updated everytime calling createTelemetryData(). | ||
*/ | ||
public static markAppGenStartTime(): void { | ||
TelemetryHelper.createTelemetryData({ | ||
markName: Performance.startMark('LOADING_TIME') | ||
}); | ||
} | ||
|
||
/** | ||
* Marks the end time. Example usage: | ||
* At the end of the writing phase of yeoman generator. | ||
*/ | ||
public static markAppGenEndTime(): void { | ||
if (this._telemetryData?.markName) { | ||
Performance.endMark(this._telemetryData.markName); | ||
Performance.measure(this._telemetryData.markName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface TelemetryData { | ||
[key: string]: string; | ||
} |
Oops, something went wrong.