From 9ab2f05fca24c0e4daad8c5391938823432ad531 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Wed, 13 Jul 2022 16:43:47 +0200 Subject: [PATCH] Enable otlp logging and compatibility with env vars --- package.json | 1 + .../plugins/monitoring_collection/README.md | 9 +++++++++ .../monitoring_collection/server/config.ts | 1 + .../monitoring_collection/server/plugin.ts | 20 ++++++++++++++++--- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e9687d0f3e412..99b9a6aa55da6 100644 --- a/package.json +++ b/package.json @@ -275,6 +275,7 @@ "@mapbox/mapbox-gl-draw": "1.3.0", "@mapbox/mapbox-gl-rtl-text": "0.2.3", "@mapbox/vector-tile": "1.3.1", + "@opentelemetry/api": "^1.1.0", "@opentelemetry/api-metrics": "^0.30.0", "@opentelemetry/exporter-metrics-otlp-grpc": "^0.30.0", "@opentelemetry/exporter-prometheus": "^0.30.0", diff --git a/x-pack/plugins/monitoring_collection/README.md b/x-pack/plugins/monitoring_collection/README.md index 13b8396f01b3e..b5e8a38d16ad6 100644 --- a/x-pack/plugins/monitoring_collection/README.md +++ b/x-pack/plugins/monitoring_collection/README.md @@ -49,6 +49,15 @@ monitoring_collection.opentelemetry.metrics: Authorization: "Bearer SECRET_TOKEN" ``` +Alternatively, OTLP Exporter can be configured using environment variables `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, `OTEL_EXPORTER_OTLP_METRICS_HEADERS`. [See OTLP Exporter docs](https://opentelemetry.io/docs/reference/specification/protocol/exporter/) for details. + +It's possible to configure logging for the OTLP integration. If not informed, the default will be `info` + +```yml +monitoring_collection.opentelemetry.metrics: + logLevel: warn | info | debug | warn | none | verbose | all +``` + For connection-level debug information you can set these variables: ```bash diff --git a/x-pack/plugins/monitoring_collection/server/config.ts b/x-pack/plugins/monitoring_collection/server/config.ts index 6efe92986ddd5..5eda950ebe7f1 100644 --- a/x-pack/plugins/monitoring_collection/server/config.ts +++ b/x-pack/plugins/monitoring_collection/server/config.ts @@ -15,6 +15,7 @@ export const configSchema = schema.object({ url: schema.maybe(schema.string()), headers: schema.maybe(schema.recordOf(schema.string(), schema.string())), exportIntervalMillis: schema.number({ defaultValue: 10000 }), + logLevel: schema.string({ defaultValue: 'info' }), }), prometheus: schema.object({ enabled: schema.boolean({ defaultValue: false }), diff --git a/x-pack/plugins/monitoring_collection/server/plugin.ts b/x-pack/plugins/monitoring_collection/server/plugin.ts index e0a0fc76a23ac..818dd81a9c303 100644 --- a/x-pack/plugins/monitoring_collection/server/plugin.ts +++ b/x-pack/plugins/monitoring_collection/server/plugin.ts @@ -18,6 +18,7 @@ import { metrics } from '@opentelemetry/api-metrics'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'; import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics-base'; import { Resource } from '@opentelemetry/resources'; +import { diag, DiagLogger, DiagLogLevel } from '@opentelemetry/api'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import * as grpc from '@grpc/grpc-js'; import { PrometheusExporter } from './lib/prometheus_exporter'; @@ -41,6 +42,7 @@ export class MonitoringCollectionPlugin implements Plugin> = {}; @@ -50,6 +52,14 @@ export class MonitoringCollectionPlugin implements Plugin this.logger.debug(message), + error: (message) => this.logger.error(message), + info: (message) => this.logger.info(message), + warn: (message) => this.logger.warn(message), + verbose: (message) => this.logger.trace(message), + }; } async getMetric(type: string) { @@ -127,11 +137,12 @@ export class MonitoringCollectionPlugin implements Plugin