diff --git a/docs/monitoring-and-logging.md b/docs/monitoring-and-logging.md index e5fbf1c266..6897ce80a2 100644 --- a/docs/monitoring-and-logging.md +++ b/docs/monitoring-and-logging.md @@ -1,8 +1,6 @@ # Setting up Metrics Monitoring and Logging for Backstage Showcase -The Backstage Showcase provides a `/metrics` endpoint on port `9464` (for application metrics) and `9463` (for host metrics) that provides OpenTelemetry metrics about your backstage application. This endpoint can be used to monitor your backstage instance using OpenTelemetry and Grafana. - -**Note**: Due to a limitation, the host and application metrics are exposed on separate ports. This is to be improved by making all metrics accessible on the same port (9464) in a future release. This guide will ONLY work with the application metrics from NodeJs and Backstage. +The Backstage Showcase provides a `/metrics` endpoint on port `9464` that provides OpenTelemetry metrics about your backstage application. This endpoint can be used to monitor your backstage instance using OpenTelemetry and Grafana. When deploying Backstage Showcase onto a kubernetes cluster with the [RHDH Helm chart](https://github.com/redhat-developer/rhdh-chart) or the [RHDH Operator](https://github.com/janus-idp/operator), monitoring and logging for your RHDH instance can be configured using the following steps. diff --git a/packages/backend/package.json b/packages/backend/package.json index 68630c1234..8a758280e3 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -51,6 +51,7 @@ "@internal/plugin-scalprum-backend": "*", "@janus-idp/backstage-plugin-audit-log-node": "1.7.0", "@janus-idp/backstage-scaffolder-backend-module-annotator": "2.2.0", + "@opentelemetry/api": "1.9.0", "@opentelemetry/auto-instrumentations-node": "0.50.2", "@opentelemetry/exporter-prometheus": "0.53.0", "@opentelemetry/host-metrics": "0.35.4", diff --git a/packages/backend/src/instrumentation.js b/packages/backend/src/instrumentation.js index 241ded7db7..e8b7547947 100644 --- a/packages/backend/src/instrumentation.js +++ b/packages/backend/src/instrumentation.js @@ -7,12 +7,12 @@ const { } = require('@opentelemetry/instrumentation-runtime-node'); const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); const { HostMetrics } = require('@opentelemetry/host-metrics'); -const { MeterProvider } = require('@opentelemetry/sdk-metrics'); +const { metrics } = require('@opentelemetry/api'); -// Application metrics will be exported to localhost:9464/metrics -const prometheusApplication = new PrometheusExporter(); +// Metrics will be exported to localhost:9464/metrics +const prometheus = new PrometheusExporter(); const sdk = new NodeSDK({ - metricReader: prometheusApplication, + metricReader: prometheus, instrumentations: [ getNodeAutoInstrumentations(), new RuntimeNodeInstrumentation(), @@ -21,10 +21,7 @@ const sdk = new NodeSDK({ sdk.start(); -// Host/process metrics will be exported to localhost:9463/metrics -const prometheusHost = new PrometheusExporter({ port: 9463 }); -const meterProvider = new MeterProvider({ - readers: [prometheusHost], +const hostMetrics = new HostMetrics({ + meterProvider: metrics.getMeterProvider(), }); -const hostMetrics = new HostMetrics({ meterProvider }); hostMetrics.start(); diff --git a/yarn.lock b/yarn.lock index 08f65dd6bd..607d6e8a47 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13986,7 +13986,7 @@ __metadata: languageName: node linkType: hard -"@opentelemetry/api@npm:^1.0.0, @opentelemetry/api@npm:^1.0.1, @opentelemetry/api@npm:^1.3.0, @opentelemetry/api@npm:^1.4.0": +"@opentelemetry/api@npm:1.9.0, @opentelemetry/api@npm:^1.0.0, @opentelemetry/api@npm:^1.0.1, @opentelemetry/api@npm:^1.3.0, @opentelemetry/api@npm:^1.4.0": version: 1.9.0 resolution: "@opentelemetry/api@npm:1.9.0" checksum: 9e88e59d53ced668f3daaecfd721071c5b85a67dd386f1c6f051d1be54375d850016c881f656ffbe9a03bedae85f7e89c2f2b635313f9c9b195ad033cdc31020 @@ -22453,6 +22453,7 @@ __metadata: "@internal/plugin-scalprum-backend": "*" "@janus-idp/backstage-plugin-audit-log-node": 1.7.0 "@janus-idp/backstage-scaffolder-backend-module-annotator": 2.2.0 + "@opentelemetry/api": 1.9.0 "@opentelemetry/auto-instrumentations-node": 0.50.2 "@opentelemetry/exporter-prometheus": 0.53.0 "@opentelemetry/host-metrics": 0.35.4