Skip to content

Commit fe84c57

Browse files
author
chrisronline
committed
be more defensive
1 parent ef64cfc commit fe84c57

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

  • x-pack/plugins/monitoring_collection/server

x-pack/plugins/monitoring_collection/server/plugin.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,25 @@ export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSe
138138

139139
return {
140140
reportCounter: (name: string, dimensions: Record<string, string>, amount: number = 1) => {
141-
// @ts-ignore-line
142-
const counter = apm.registerMetricCounter(name, {
143-
...dimensions,
144-
...kibanaDimensions,
145-
});
146-
if (counter) {
147-
counter.inc(amount);
141+
try {
142+
// @ts-ignore-line
143+
const counter = apm.registerMetricCounter(name, {
144+
...dimensions,
145+
...kibanaDimensions,
146+
});
147+
if (counter) {
148+
counter.inc(amount);
149+
}
150+
} catch (err) {
151+
this.logger.warn(`Unable to report counter for ${name} due to ${err.message}`);
148152
}
149153
},
150154
reportGauge: (name: string, dimensions: Record<string, string>, value: number) => {
151-
// console.log(`reportGauge()`, { name, dimensions, value })
152-
apm.registerMetric(name, { ...dimensions, ...kibanaDimensions }, () => value);
155+
try {
156+
apm.registerMetric(name, { ...dimensions, ...kibanaDimensions }, () => value);
157+
} catch (err) {
158+
this.logger.warn(`Unable to report gauge for ${name} due to ${err.message}`);
159+
}
153160
},
154161
registerCustomElasticsearchClient: (customClient: ICustomClusterClient) => {
155162
this.client = customClient;

0 commit comments

Comments
 (0)