Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchDevices() and update banner telemetry #519

Merged
merged 9 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-iot-explorer",
"version": "0.14.9",
"version": "0.14.11",
"description": "This project welcomes contributions and suggestions. Most contributions require you to agree to a\r Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\r the rights to use your contribution. For details, visit https://cla.microsoft.com.",
"main": "host/electron.js",
"build": {
Expand Down
15 changes: 12 additions & 3 deletions src/app/api/services/devicesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { DeviceIdentity } from '../models/deviceIdentity';
import { dataPlaneConnectionHelper, dataPlaneResponseHelper, request, DATAPLANE_CONTROLLER_ENDPOINT, DataPlaneRequest } from './dataplaneServiceHelper';
import { getDeviceInterface, getEventHubInterface } from '../shared/interfaceUtils';
import { parseEventHubMessage } from './eventHubMessageHelper';
import { AppInsightsClient } from '../../shared/appTelemetry/appInsightsClient';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';

const PAGE_SIZE = 100;

Expand Down Expand Up @@ -173,6 +175,7 @@ export const fetchDevice = async (parameters: FetchDeviceParameters): Promise<De
return result && result.body;
};

// tslint:disable-next-line:cyclomatic-complexity
export const fetchDevices = async (parameters: FetchDevicesParameters): Promise<DataPlaneResponse<Device[]>> => {
const connectionInformation = await dataPlaneConnectionHelper();
const queryString = buildQueryString(parameters.query);
Expand All @@ -195,9 +198,15 @@ export const fetchDevices = async (parameters: FetchDevicesParameters): Promise<
(dataPlaneRequest.headers as any)[HEADERS.CONTINUATION_TOKEN] = parameters.query.continuationTokens[parameters.query.currentPageIndex]; // tslint:disable-line: no-any
}

const response = await request(DATAPLANE_CONTROLLER_ENDPOINT, dataPlaneRequest);
const result = await dataPlaneResponseHelper(response);
return result;
try {
const response = await request(DATAPLANE_CONTROLLER_ENDPOINT, dataPlaneRequest);
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.FETCH_DEVICES}, {status: response.status.toString(), statusText: response.statusText});
const result = await dataPlaneResponseHelper(response);
return result;
} catch (e) {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.FETCH_DEVICES}, {status: 'N/A', statusText: e.toString()});
throw (e);
}
Comment on lines +201 to +209
Copy link
Member

@c-ryan-k c-ryan-k Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought for the future -

Seems like this method has use outside of just fetching devices (even though that's the only place it's used for now). Possibly in a future PR we could abstract this to a helper function that takes an endpoint, request, and telemetry type;
export const fetchWithTelemetry(endpoint: string, request: any, telemetryType: {enum_or_telemetry_type_TBD})

};

export const deleteDevices = async (parameters: DeleteDevicesParameters) => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/constants/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export enum TELEMETRY_PAGE_NAMES {

}

export enum TELEMETRY_ACTIONS {
ADD = 'add',
export enum TELEMETRY_EVENTS {
FETCH_DEVICES = 'fetch_devices',
INIT = 'init',
UPDATE_BANNER_DISPLAYED = 'update_banner:displayed',
UPDATE_BANNER_CLICKED = 'update_banner:clicked'
}
16 changes: 14 additions & 2 deletions src/app/home/components/appVersionMessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ResourceKeys } from '../../../localization/resourceKeys';
import { fetchLatestReleaseTagName, latestReleaseUrlPath } from '../../api/services/githubService';
import * as packageJson from '../../../../package.json';
import { isNewReleaseVersionHigher } from '../utils/appVersionHelper';
import { AppInsightsClient } from '../../shared/appTelemetry/appInsightsClient';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';

export const AppVersionMessageBar: React.FC = () => {
const { t } = useTranslation();
Expand All @@ -32,14 +34,24 @@ export const AppVersionMessageBar: React.FC = () => {
}
};

const onBannerClicked = () => {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.UPDATE_BANNER_CLICKED});
};

React.useEffect(() => {
if (hasNewerRelease()) {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.UPDATE_BANNER_DISPLAYED});
}
}, [hasNewerRelease]); // tslint:disable-line: align

return hasNewerRelease() ?
(
(
<MessageBar
className="home-view-message-bar"
messageBarType={MessageBarType.info}
>
{t(ResourceKeys.deviceLists.messageBar.message, {version: latestReleaseVersion})}
<Link href={latestReleaseUrlPath} target="_blank">
<Link href={latestReleaseUrlPath} target="_blank" onClick={onBannerClicked}>
{t(ResourceKeys.deviceLists.messageBar.link)}
</Link>
</MessageBar>
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/appTelemetry/appInsightsClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';
import { appConfig } from '../../../appConfig/appConfig';
export class AppInsightsClient {
private static instance: ApplicationInsights;
Expand All @@ -11,7 +12,7 @@ export class AppInsightsClient {
} });
try {
appInsights.loadAppInsights();
appInsights.trackEvent({name: `INIT`}, {type: 'init'});
appInsights.trackEvent({name: TELEMETRY_EVENTS.INIT});
AppInsightsClient.instance = appInsights;
} catch (e) {
// tslint:disable-next-line:no-console
Expand Down