Skip to content

Commit

Permalink
be more defensive
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Apr 21, 2022
1 parent ef64cfc commit fe84c57
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions x-pack/plugins/monitoring_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,25 @@ export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSe

return {
reportCounter: (name: string, dimensions: Record<string, string>, amount: number = 1) => {
// @ts-ignore-line
const counter = apm.registerMetricCounter(name, {
...dimensions,
...kibanaDimensions,
});
if (counter) {
counter.inc(amount);
try {
// @ts-ignore-line
const counter = apm.registerMetricCounter(name, {
...dimensions,
...kibanaDimensions,
});
if (counter) {
counter.inc(amount);
}
} catch (err) {
this.logger.warn(`Unable to report counter for ${name} due to ${err.message}`);
}
},
reportGauge: (name: string, dimensions: Record<string, string>, value: number) => {
// console.log(`reportGauge()`, { name, dimensions, value })
apm.registerMetric(name, { ...dimensions, ...kibanaDimensions }, () => value);
try {
apm.registerMetric(name, { ...dimensions, ...kibanaDimensions }, () => value);
} catch (err) {
this.logger.warn(`Unable to report gauge for ${name} due to ${err.message}`);
}
},
registerCustomElasticsearchClient: (customClient: ICustomClusterClient) => {
this.client = customClient;
Expand Down

0 comments on commit fe84c57

Please sign in to comment.