From a95bb64e461ad755193a2ce1b9102854aa1b57ba Mon Sep 17 00:00:00 2001 From: Niklas Aronsson Date: Thu, 6 Jul 2023 07:09:30 +0200 Subject: [PATCH] Airbrake backend: Support the new backend system Signed-off-by: Niklas Aronsson --- .changeset/fluffy-readers-own.md | 5 +++ plugins/airbrake-backend/api-report.md | 4 +++ plugins/airbrake-backend/package.json | 1 + plugins/airbrake-backend/src/index.ts | 1 + plugins/airbrake-backend/src/plugin.ts | 49 ++++++++++++++++++++++++++ plugins/airbrake/README.md | 11 ++++++ yarn.lock | 1 + 7 files changed, 72 insertions(+) create mode 100644 .changeset/fluffy-readers-own.md create mode 100644 plugins/airbrake-backend/src/plugin.ts diff --git a/.changeset/fluffy-readers-own.md b/.changeset/fluffy-readers-own.md new file mode 100644 index 0000000000..bc38e26f7a --- /dev/null +++ b/.changeset/fluffy-readers-own.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-airbrake-backend': patch +--- + +Added support for the [new backend system](https://backstage.io/docs/backend-system/) diff --git a/plugins/airbrake-backend/api-report.md b/plugins/airbrake-backend/api-report.md index 3ad74e2506..c410245e31 100644 --- a/plugins/airbrake-backend/api-report.md +++ b/plugins/airbrake-backend/api-report.md @@ -3,6 +3,7 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import express from 'express'; import { Logger } from 'winston'; @@ -12,6 +13,9 @@ export interface AirbrakeConfig { apiKey: string; } +// @public +export const airbrakePlugin: () => BackendFeature; + // @public export function createRouter(options: RouterOptions): Promise; diff --git a/plugins/airbrake-backend/package.json b/plugins/airbrake-backend/package.json index 5d0f870583..8a2cf82367 100644 --- a/plugins/airbrake-backend/package.json +++ b/plugins/airbrake-backend/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@types/express": "*", "express": "^4.17.1", diff --git a/plugins/airbrake-backend/src/index.ts b/plugins/airbrake-backend/src/index.ts index f4ec6008c2..5905a7e0e5 100644 --- a/plugins/airbrake-backend/src/index.ts +++ b/plugins/airbrake-backend/src/index.ts @@ -22,3 +22,4 @@ export * from './service/router'; export * from './config'; +export { airbrakePlugin } from './plugin'; diff --git a/plugins/airbrake-backend/src/plugin.ts b/plugins/airbrake-backend/src/plugin.ts new file mode 100644 index 0000000000..79850c1272 --- /dev/null +++ b/plugins/airbrake-backend/src/plugin.ts @@ -0,0 +1,49 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import { createRouter } from './service/router'; +import { extractAirbrakeConfig } from './config'; + +/** + * The Airbrake Backend plugin. + * + * @public + */ +export const airbrakePlugin = createBackendPlugin({ + pluginId: 'airbrake', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + httpRouter: coreServices.httpRouter, + }, + async init({ logger, httpRouter, config }) { + httpRouter.use( + await createRouter({ + airbrakeConfig: extractAirbrakeConfig(config), + logger: loggerToWinstonLogger(logger), + }), + ); + }, + }); + }, +}); diff --git a/plugins/airbrake/README.md b/plugins/airbrake/README.md index f37ab08b75..91d42eb8e7 100644 --- a/plugins/airbrake/README.md +++ b/plugins/airbrake/README.md @@ -98,6 +98,17 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https: } ``` + ```typescript + // Using the new backend system + import { airbrakePlugin } from '@backstage/plugin-airbrake-backend'; + + const backend = createBackend(); + backend.add(airbrakePlugin()); + // ... other feature additions + + backend.start(); + ``` + 6. Add this config as a top level section in your `app-config.yaml`: ```yaml diff --git a/yarn.lock b/yarn.lock index 7c02addce5..23ee3a82ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4656,6 +4656,7 @@ __metadata: resolution: "@backstage/plugin-airbrake-backend@workspace:plugins/airbrake-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@types/express": "*"