Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DTA-1034] Integrate BugSnag error monitoring in the Payment Service #6

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ LOAD_GENERATOR_DOCKERFILE=./src/loadgenerator/Dockerfile
PAYMENT_SERVICE_PORT=50051
PAYMENT_SERVICE_ADDR=paymentservice:${PAYMENT_SERVICE_PORT}
PAYMENT_SERVICE_DOCKERFILE=./src/paymentservice/Dockerfile
PAYMENT_SERVICE_BUGSNAG_API_KEY=<your-api-key>

# Product Catalog Service
PRODUCT_CATALOG_SERVICE_PORT=3550
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ services:
- "${PAYMENT_SERVICE_PORT}"
environment:
- PAYMENT_SERVICE_PORT
- BUGSNAG_API_KEY=${PAYMENT_SERVICE_BUGSNAG_API_KEY}
- FLAGD_HOST
- FLAGD_PORT
- OTEL_EXPORTER_OTLP_ENDPOINT
Expand Down
16 changes: 15 additions & 1 deletion src/paymentservice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ const opentelemetry = require('@opentelemetry/api')

const charge = require('./charge')
const logger = require('./logger')
const { trace, context } = require('@opentelemetry/api');
const Bugsnag = require('@bugsnag/js');

Bugsnag.start({
apiKey: process.env.PAYMENT_SERVICE_BUGSNAG_API_KEY,
onError: function (event) {
const spanContext = trace.getSpanContext(context.active());
event.addMetadata("correlation", {
traceId: spanContext.traceId,
spanId: spanContext.spanId,
});
}
});

async function chargeServiceHandler(call, callback) {
const span = opentelemetry.trace.getActiveSpan();
Expand All @@ -23,7 +36,8 @@ async function chargeServiceHandler(call, callback) {

} catch (err) {
logger.warn({ err })

Bugsnag.notify(err);

span.recordException(err)
span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR })

Expand Down
132 changes: 132 additions & 0 deletions src/paymentservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/paymentservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
"author": "Jonathan Lui",
"license": "ISC",
"dependencies": {
"@bugsnag/js": "^8.1.2",
"@grpc/grpc-js": "1.10.8",
"@grpc/proto-loader": "0.7.13",
"@openfeature/flagd-provider": "0.13.0",
"@openfeature/server-sdk": "1.14.0",
"@opentelemetry/api": "1.8.0",
"@opentelemetry/auto-instrumentations-node": "0.46.1",
"@opentelemetry/core": "1.24.1",
"@opentelemetry/resources": "1.24.1",
"@opentelemetry/api": "1.8.0",
"@opentelemetry/sdk-metrics": "1.24.1",
"@opentelemetry/exporter-trace-otlp-grpc": "0.51.1",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.51.1",
"@opentelemetry/sdk-node": "0.51.1",
"@opentelemetry/exporter-trace-otlp-grpc": "0.51.1",
"@opentelemetry/resource-detector-alibaba-cloud": "0.28.9",
"@opentelemetry/resource-detector-aws": "1.5.0",
"@opentelemetry/resource-detector-container": "0.3.9",
"@opentelemetry/resource-detector-gcp": "0.29.9",
"@opentelemetry/resources": "1.24.1",
"@opentelemetry/sdk-metrics": "1.24.1",
"@opentelemetry/sdk-node": "0.51.1",
"grpc-js-health-check": "1.1.0",
"pino": "8.16.1",
"simple-card-validator": "1.1.0",
Expand Down
Loading