Airbrake backend: Support the new backend system

Signed-off-by: Niklas Aronsson <niklasar@axis.com>
This commit is contained in:
Niklas Aronsson
2023-07-06 07:09:30 +02:00
parent 06c88a8d30
commit a95bb64e46
7 changed files with 72 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-airbrake-backend': patch
---
Added support for the [new backend system](https://backstage.io/docs/backend-system/)
+4
View File
@@ -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<express.Router>;
+1
View File
@@ -23,6 +23,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@types/express": "*",
"express": "^4.17.1",
+1
View File
@@ -22,3 +22,4 @@
export * from './service/router';
export * from './config';
export { airbrakePlugin } from './plugin';
+49
View File
@@ -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),
}),
);
},
});
},
});
+11
View File
@@ -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
+1
View File
@@ -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": "*"