Skip to content

Commit

Permalink
[APM] Adding telemetry to APM APIs (#103543)
Browse files Browse the repository at this point in the history
* adding telemetry to apm apis

* addressing PR comment

* adding space

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
cauemarcondes and kibanamachine authored Jun 30, 2021
1 parent 9fdd569 commit d046ada
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export class APMPlugin
};
}) as APMRouteHandlerResources['plugins'];

const telemetryUsageCounter = resourcePlugins.usageCollection?.setup.createUsageCounter(
'apm'
);

registerRoutes({
core: {
setup: core,
Expand All @@ -212,6 +216,7 @@ export class APMPlugin
repository: getGlobalApmServerRouteRepository(),
ruleDataClient,
plugins: resourcePlugins,
telemetryUsageCounter,
});

const boundGetApmIndices = async () =>
Expand Down
18 changes: 18 additions & 0 deletions x-pack/plugins/apm/server/routes/register_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
routeValidationObject,
} from '@kbn/server-route-repository';
import { mergeRt, jsonRt } from '@kbn/io-ts-utils';
import { UsageCollectionSetup } from '../../../../../../src/plugins/usage_collection/server';
import { pickKeys } from '../../../common/utils/pick_keys';
import { APMRouteHandlerResources, InspectResponse } from '../typings';
import type { ApmPluginRequestHandlerContext } from '../typings';
Expand All @@ -40,13 +41,17 @@ export function registerRoutes({
logger,
config,
ruleDataClient,
telemetryUsageCounter,
}: {
core: APMRouteHandlerResources['core'];
plugins: APMRouteHandlerResources['plugins'];
logger: APMRouteHandlerResources['logger'];
repository: ServerRouteRepository<APMRouteHandlerResources>;
config: APMRouteHandlerResources['config'];
ruleDataClient: APMRouteHandlerResources['ruleDataClient'];
telemetryUsageCounter?: ReturnType<
UsageCollectionSetup['createUsageCounter']
>;
}) {
const routes = repository.getRoutes();

Expand Down Expand Up @@ -116,9 +121,22 @@ export function registerRoutes({
// cleanup
inspectableEsQueriesMap.delete(request);

if (!options.disableTelemetry && telemetryUsageCounter) {
telemetryUsageCounter.incrementCounter({
counterName: `${method.toUpperCase()} ${pathname}`,
counterType: 'success',
});
}

return response.ok({ body });
} catch (error) {
logger.error(error);
if (!options.disableTelemetry && telemetryUsageCounter) {
telemetryUsageCounter.incrementCounter({
counterName: `${method.toUpperCase()} ${pathname}`,
counterType: 'error',
});
}
const opts = {
statusCode: 500,
body: {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/routes/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface APMRouteCreateOptions {
| 'access:ml:canCreateJob'
>;
body?: { accepts: Array<'application/json' | 'multipart/form-data'> };
disableTelemetry?: boolean;
};
}

Expand Down

0 comments on commit d046ada

Please sign in to comment.