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

[APM][ECO] Telemetry #188627

Merged
merged 15 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { AnalyticsServiceSetup } from '@kbn/core/public';
import { BehaviorSubject } from 'rxjs';
import { ServiceInventoryView } from '../context/entity_manager_context/entity_manager_context';

export const serviceInventoryStorageKey = 'apm.service.inventory.view';
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved

export const serviceInventoryViewType$ = new BehaviorSubject({
serviceInventoryViewType: JSON.parse(
window.localStorage.getItem(serviceInventoryStorageKey) || ServiceInventoryView.classic
),
});

export function registerServiceInventoryViewTypeContext(analytics: AnalyticsServiceSetup) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

analytics.registerContextProvider({
name: 'serviceInventoryViewType',
context$: serviceInventoryViewType$,
schema: {
serviceInventoryViewType: {
type: 'keyword',
_meta: { description: 'The APM service inventory view type' },
},
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { EuiFlexItem, EuiFlexGroup } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import React, { useEffect } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { ApmDocumentType } from '../../../../../common/document_type';
import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
Expand All @@ -27,6 +27,8 @@ import { ServiceListItem } from '../../../../../common/service_inventory';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { useProgressiveFetcher } from '../../../../hooks/use_progressive_fetcher';
import { NoEntitiesEmptyState } from './table/no_entities_empty_state';
import { useKibana } from '../../../../context/kibana_context/use_kibana';
import { ApmPluginStartDeps, ApmServices } from '../../../../plugin';

type MainStatisticsApiResponse = APIReturnType<'GET /internal/apm/entities/services'>;

Expand Down Expand Up @@ -143,6 +145,7 @@ function useServicesEntitiesDetailedStatisticsFetcher({

export function MultiSignalInventory() {
const [searchQuery, setSearchQuery] = React.useState('');
const { services } = useKibana<ApmPluginStartDeps & ApmServices>();
const { mainStatisticsData, mainStatisticsStatus } = useServicesEntitiesMainStatisticsFetcher();
const mainStatisticsFetch = useServicesEntitiesMainStatisticsFetcher();

Expand All @@ -163,6 +166,12 @@ export function MultiSignalInventory() {
return callApmApi('GET /internal/apm/has_entities');
}, []);

useEffect(() => {
if (data?.hasData) {
services.telemetry.reportEntityInventoryPageState({ state: 'available' });
}
}, [services.telemetry, data?.hasData]);

if (!data?.hasData && status === FETCH_STATUS.SUCCESS) {
return <NoEntitiesEmptyState />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiCallOut,
Expand All @@ -27,15 +27,22 @@ import {
AssociateServiceLogs,
CollectServiceLogs,
} from '../../../../shared/add_data_buttons/buttons';
import { useKibana } from '../../../../../context/kibana_context/use_kibana';
import { ApmPluginStartDeps, ApmServices } from '../../../../../plugin';

export function NoEntitiesEmptyState() {
const { core } = useApmPluginContext();
const { services } = useKibana<ApmPluginStartDeps & ApmServices>();
const { basePath } = core.http;
const [userHasDismissedCallout, setUserHasDismissedCallout] = useLocalStorage(
'apm.uiNewExperienceCallout',
false
);

useEffect(() => {
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
services.telemetry.reportEntityInventoryPageState({ state: 'empty_state' });
}, [services.telemetry]);

return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { entityCentricExperience } from '@kbn/observability-plugin/common';
import { ENTITY_FETCH_STATUS, useEntityManager } from '../../hooks/use_entity_manager';
import { useLocalStorage } from '../../hooks/use_local_storage';
import { useApmPluginContext } from '../apm_plugin/use_apm_plugin_context';
import {
serviceInventoryStorageKey,
serviceInventoryViewType$,
} from '../../analytics/register_service_inventory_view_type_context';
import { useKibana } from '../kibana_context/use_kibana';
import { ApmPluginStartDeps, ApmServices } from '../../plugin';

export interface EntityManagerEnablementContextValue {
isEntityManagerEnabled: boolean;
Expand All @@ -25,8 +31,6 @@ export enum ServiceInventoryView {
entity = 'entity',
}

export const serviceInventoryStorageKey = 'apm.service.inventory.view';

export const EntityManagerEnablementContext = createContext(
{} as EntityManagerEnablementContextValue
);
Expand All @@ -37,6 +41,7 @@ export function EntityManagerEnablementContextProvider({
children: React.ReactChild;
}) {
const { core } = useApmPluginContext();
const { services } = useKibana<ApmPluginStartDeps & ApmServices>();
const { isEnabled: isEntityManagerEnabled, status, refetch } = useEntityManager();

const [serviceInventoryViewLocalStorageSetting, setServiceInventoryViewLocalStorageSetting] =
Expand All @@ -60,7 +65,14 @@ export function EntityManagerEnablementContextProvider({
isEnablementPending: status === ENTITY_FETCH_STATUS.LOADING,
refetch,
serviceInventoryViewLocalStorageSetting,
setServiceInventoryViewLocalStorageSetting,
setServiceInventoryViewLocalStorageSetting: (nextView) => {
setServiceInventoryViewLocalStorageSetting(nextView);
// Updates the telemetry context variable every time the user switches views
serviceInventoryViewType$.next({ serviceInventoryViewType: nextView });
services.telemetry.reportEntityExperienceStatusChange({
status: nextView === ServiceInventoryView.entity ? 'enabled' : 'disabled',
});
},
isEntityCentricExperienceViewEnabled,
}}
>
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/observability_solution/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { getLazyAPMPolicyEditExtension } from './components/fleet_integration/la
import { featureCatalogueEntry } from './feature_catalogue_entry';
import { APMServiceDetailLocator } from './locator/service_detail_locator';
import { ITelemetryClient, TelemetryService } from './services/telemetry';
import { registerServiceInventoryViewTypeContext } from './analytics/register_service_inventory_view_type_context';

export type ApmPluginSetup = ReturnType<ApmPlugin['setup']>;
export type ApmPluginStart = void;
Expand Down Expand Up @@ -273,6 +274,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
};

this.telemetry.setup({ analytics: core.analytics });
registerServiceInventoryViewTypeContext(core.analytics);

// Registers a status check callback for the tutorial to call and verify if the APM integration is installed on fleet.
pluginSetupDeps.home?.tutorials.registerCustomStatusCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import { AnalyticsServiceSetup } from '@kbn/core-analytics-server';
import { TelemetryEventTypes, ITelemetryClient, SearchQuerySubmittedParams } from './types';
import {
ITelemetryClient,
SearchQuerySubmittedParams,
EntityExperienceStatusParams,
TelemetryEventTypes,
EntityInventoryPageStateParams,
} from './types';

export class TelemetryClient implements ITelemetryClient {
constructor(private analytics: AnalyticsServiceSetup) {}
Expand All @@ -22,4 +28,12 @@ export class TelemetryClient implements ITelemetryClient {
action,
});
};

public reportEntityExperienceStatusChange = ({ status }: EntityExperienceStatusParams) => {
this.analytics.reportEvent(TelemetryEventTypes.ENTITY_EXPERIENCE_STATUS, { status });
};

public reportEntityInventoryPageState = ({ state }: EntityInventoryPageStateParams) => {
this.analytics.reportEvent(TelemetryEventTypes.ENTITY_INVENTORY_PAGE_STATE, { state });
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,32 @@ const searchQuerySubmittedEventType: TelemetryEvent = {
},
};

export const apmTelemetryEventBasedTypes = [searchQuerySubmittedEventType];
const entityExperienceStatusEventType: TelemetryEvent = {
eventType: TelemetryEventTypes.ENTITY_EXPERIENCE_STATUS,
schema: {
status: {
type: 'keyword',
_meta: {
description: 'The status of the Entity experience (Enabled or Disabled)',
},
},
},
};

const entityInventoryPageStateEventType: TelemetryEvent = {
eventType: TelemetryEventTypes.ENTITY_INVENTORY_PAGE_STATE,
schema: {
state: {
type: 'keyword',
_meta: {
description: 'The current entity inventory page state (empty_state or available)',
},
},
},
};

export const apmTelemetryEventBasedTypes = [
searchQuerySubmittedEventType,
entityExperienceStatusEventType,
entityInventoryPageStateEventType,
];
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,32 @@ export interface SearchQuerySubmittedParams {
action: SearchQueryActions;
}

export type TelemetryEventParams = SearchQuerySubmittedParams;
export interface EntityExperienceStatusParams {
status: 'enabled' | 'disabled';
}

export interface EntityInventoryPageStateParams {
state: 'empty_state' | 'available';
}

export type TelemetryEventParams =
| SearchQuerySubmittedParams
| EntityExperienceStatusParams
| EntityInventoryPageStateParams;

export interface ITelemetryClient {
reportSearchQuerySubmitted(params: SearchQuerySubmittedParams): void;
reportEntityExperienceStatusChange(params: EntityExperienceStatusParams): void;
reportEntityInventoryPageState(params: EntityInventoryPageStateParams): void;
}

export enum TelemetryEventTypes {
SEARCH_QUERY_SUBMITTED = 'Search Query Submitted',
ENTITY_EXPERIENCE_STATUS = 'entity_experience_status',
ENTITY_INVENTORY_PAGE_STATE = 'entity_inventory_page_state',
}

export interface TelemetryEvent {
eventType: TelemetryEventTypes.SEARCH_QUERY_SUBMITTED;
schema: RootSchema<SearchQuerySubmittedParams>;
eventType: TelemetryEventTypes;
schema: RootSchema<TelemetryEventParams>;
}