Skip to content

Commit

Permalink
Refactor the Sentry plugin to use the proxy backend instead of a cust…
Browse files Browse the repository at this point in the history
…om backend
  • Loading branch information
dhenneke committed Dec 7, 2020
1 parent 4266967 commit 075d3dc
Show file tree
Hide file tree
Showing 36 changed files with 403 additions and 479 deletions.
65 changes: 65 additions & 0 deletions .changeset/chatty-pens-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
'@backstage/plugin-sentry': minor
'@backstage/plugin-sentry-backend': minor
---

The plugin uses the `proxy-backend` instead of a custom `sentry-backend`.
It requires a proxy configuration:

`app-config.yaml`:

```yaml
proxy:
'/sentry/api':
target: https://sentry.io/api/
allowedMethods: ['GET']
headers:
Authorization:
$env: SENTRY_TOKEN # export SENTRY_TOKEN="Bearer <your-sentry-token>"
```

The `MockApiBackend` is no longer configured by the `NODE_ENV` variable.
Instead, the mock backend can be used with an api-override:

`packages/app/src/apis.ts`:

```ts
import { createApiFactory } from '@backstage/core';
import { MockSentryApi, sentryApiRef } from '@backstage/plugin-sentry';

export const apis = [
// ...

createApiFactory(sentryApiRef, new MockSentryApi()),
];
```

If you already use the Sentry backend, you must remove it from the backend:

Delete `packages/backend/src/plugins/sentry.ts`.

```diff
# packages/backend/package.json

...
"@backstage/plugin-scaffolder-backend": "^0.3.2",
- "@backstage/plugin-sentry-backend": "^0.1.3",
"@backstage/plugin-techdocs-backend": "^0.3.0",
...
```

```diff
// packages/backend/src/index.html

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
apiRouter.use('/rollbar', await rollbar(rollbarEnv));
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
- apiRouter.use('/sentry', await sentry(sentryEnv));
apiRouter.use('/auth', await auth(authEnv));
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/graphql', await graphql(graphqlEnv));
apiRouter.use(notFoundHandler());
```
7 changes: 7 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ proxy:
Authorization:
$env: BUILDKITE_TOKEN

'/sentry/api':
target: https://sentry.io/api/
allowedMethods: ['GET']
headers:
Authorization:
$env: SENTRY_TOKEN

organization:
name: My Company

Expand Down
1 change: 0 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@backstage/plugin-proxy-backend": "^0.2.2",
"@backstage/plugin-rollbar-backend": "^0.1.4",
"@backstage/plugin-scaffolder-backend": "^0.3.3",
"@backstage/plugin-sentry-backend": "^0.1.3",
"@backstage/plugin-techdocs-backend": "^0.3.1",
"@gitbeaker/node": "^25.2.0",
"@octokit/rest": "^18.0.0",
Expand Down
7 changes: 2 additions & 5 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import Router from 'express-promise-router';
import {
createServiceBuilder,
loadBackendConfig,
getRootLogger,
useHotMemoize,
loadBackendConfig,
notFoundHandler,
SingleConnectionDatabaseManager,
SingleHostDiscovery,
UrlReaders,
useHotMemoize,
} from '@backstage/backend-common';
import { Config } from '@backstage/config';
import healthcheck from './plugins/healthcheck';
Expand All @@ -40,7 +40,6 @@ import catalog from './plugins/catalog';
import kubernetes from './plugins/kubernetes';
import rollbar from './plugins/rollbar';
import scaffolder from './plugins/scaffolder';
import sentry from './plugins/sentry';
import proxy from './plugins/proxy';
import techdocs from './plugins/techdocs';
import graphql from './plugins/graphql';
Expand Down Expand Up @@ -76,7 +75,6 @@ async function main() {
const authEnv = useHotMemoize(module, () => createEnv('auth'));
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
const rollbarEnv = useHotMemoize(module, () => createEnv('rollbar'));
const sentryEnv = useHotMemoize(module, () => createEnv('sentry'));
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
const graphqlEnv = useHotMemoize(module, () => createEnv('graphql'));
Expand All @@ -86,7 +84,6 @@ async function main() {
apiRouter.use('/catalog', await catalog(catalogEnv));
apiRouter.use('/rollbar', await rollbar(rollbarEnv));
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
apiRouter.use('/sentry', await sentry(sentryEnv));
apiRouter.use('/auth', await auth(authEnv));
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
Expand Down
4 changes: 3 additions & 1 deletion plugins/sentry-backend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# sentry-backend

Simple plugin forwarding requests to [Sentry](https://sentry.io) API.
> DEPRECATED
Please use the [proxy-backend](../proxy-backend) instead. See [CHANGELOG.md](./CHANGELOG.md).
11 changes: 10 additions & 1 deletion plugins/sentry-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
* limitations under the License.
*/

export * from './service/router';
import { Router } from 'express';
import { Logger } from 'winston';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const createRouter = async (_: Logger): Promise<Router> => Router();

throw new Error(
'The sentry-backend has been deprecated and replaced by the proxy-backend. See the ' +
'changelog on how to migrate to the proxy backend: https://github.com/backstage/backstage/blob/master/plugins/sentry/CHANGELOG.md.',
);
42 changes: 0 additions & 42 deletions plugins/sentry-backend/src/service/router.ts

This file was deleted.

47 changes: 0 additions & 47 deletions plugins/sentry-backend/src/service/sentry-api.ts

This file was deleted.

42 changes: 0 additions & 42 deletions plugins/sentry-backend/src/service/standaloneApplication.ts

This file was deleted.

42 changes: 0 additions & 42 deletions plugins/sentry-backend/src/service/standaloneServer.ts

This file was deleted.

0 comments on commit 075d3dc

Please sign in to comment.