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

24840 observability payments #41

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions apps/payments-api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ LOGTO_M2M_ANALYTICS_APP_SECRET=m2m_analytics_api_local_secret
ANALYTICS_WEBSITE_ID=2c144c54-e581-2591-c5fc-2d9db0b2bbed
ANALYTICS_URL=http://localhost:8075
ANALYTICS_MATOMO_TOKEN=

OTEL_SERVICE_NAME=payments-api
OTEL_COLLECTOR_URL=http://localhost:44317
2 changes: 1 addition & 1 deletion apps/payments-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ WORKDIR /app/apps/payments-api
ENV NODE_ENV=production
ENV LOG_LEVEL=trace
EXPOSE 8001
CMD [ "npx", "ts-node", "dist/", "index.js" ]
CMD [ "npx", "ts-node", "dist/", "bootstrap.js" ]
2 changes: 2 additions & 0 deletions apps/payments-api/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./instrumentation";
import "./index";
8 changes: 8 additions & 0 deletions apps/payments-api/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { instrumentNode } from "@ogcio/o11y-sdk-node";

instrumentNode({
serviceName: process.env.OTEL_SERVICE_NAME,
collectorUrl: process.env.OTEL_COLLECTOR_URL!,
collectorMode: "batch",
diagLogLevel: "INFO",
});
7 changes: 4 additions & 3 deletions apps/payments-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test:smoke:e2e": "cd ./e2e && mkdir -p test-results && bru run --env dev --output ./test-results/results.xml --format junit",
"test:regression:e2e": "cd ./e2e && mkdir -p test-results && bru run --env dev --output ./test-results/results.xml --format junit",
"test:nf": "mkdir -p test_reports && mkdir -p test_reports/perf && echo \"Error: no test specified\" && exit 0",
"start": "node dist/index.js",
"start": "node --env-file=.env dist/bootstrap.js",
"dev": "nodemon | pino-pretty",
"lint": "eslint . --ext .ts",
"build": "rm -rf dist && tsc -p tsconfig.prod.json && cp logo.png dist/",
Expand All @@ -22,7 +22,7 @@
"./**/*"
],
"ext": "ts,json",
"exec": "node --import tsx index.ts"
"exec": "node --env-file=.env --import tsx bootstrap.ts"
},
"type": "module",
"author": "",
Expand All @@ -40,7 +40,8 @@
"@ogcio/api-auth": "^4.29.1",
"@ogcio/building-blocks-sdk": "^0.1.14",
"@ogcio/fastify-error-handler": "^4.0.1",
"@ogcio/fastify-logging-wrapper": "^4.0.1",
"@ogcio/fastify-logging-wrapper": "^5.1.0",
"@ogcio/o11y-sdk-node": "^0.1.0-beta.2",
"@sinclair/typebox": "^0.32.31",
"db-migrate": "^0.11.14",
"db-migrate-pg": "^1.5.2",
Expand Down
7 changes: 7 additions & 0 deletions apps/payments/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ NEXT_PUBLIC_ANALYTICS_WEBSITE_ID=2c144c54-e581-2591-c5fc-2d9db0b2bbed
NEXT_PUBLIC_AUTH_ORGANIZATION_ID=ogcio

PROFILE_BACKEND_URL=http://localhost:8003

NEXT_PUBLIC_OTEL_CLIENT_SERVICE_NAME=payments
NEXT_PUBLIC_OTEL_FARO_URL=http://localhost:12347/collect
NEXT_PUBLIC_OTEL_PROPAGATE_TRACE_HEADER=http://localhost:3001/*

OTEL_SERVER_SERVICE_NAME=payments-next-server
OTEL_COLLECTOR_URL=http://localhost:44317
14 changes: 14 additions & 0 deletions apps/payments/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
import("@ogcio/o11y-sdk-node").then(async (sdk) => {
sdk.instrumentNode({
serviceName: process.env.OTEL_SERVER_SERVICE_NAME!,
collectorUrl: process.env.OTEL_COLLECTOR_URL!,
collectorMode: "batch",
});
});
} else {
console.error("Instrumentation not supported on current runtime");
}
}

2 changes: 2 additions & 0 deletions apps/payments/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const nextConfig = {
poweredByHeader: false,
experimental: {
outputFileTracingRoot: path.join(__dirname, "../../"),
instrumentationHook: true,
serverComponentsExternalPackages: ["pino", "@opentelemetry/instrumentation-pino"]
},
// Added this because `unleash-client` is a peer dependency
// of `building-blocks-sdk` and when next.js builds the project,
Expand Down
3 changes: 3 additions & 0 deletions apps/payments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"@ogcio/life-events-ds": "^0.1.1",
"@ogcio/nextjs-analytics": "0.1.2",
"@ogcio/nextjs-auth": "3.5.0",
"@ogcio/o11y-sdk-node": "^0.1.0-beta.2",
"@ogcio/o11y-sdk-react": "0.0.1-beta.1",
"@stripe/react-stripe-js": "^2.7.1",
"@stripe/stripe-js": "^3.4.1",
"allure-commandline": "^2.30.0",
Expand All @@ -43,6 +45,7 @@
"next": "14.2.5",
"next-intl": "^3.17.2",
"pg": "^8.11.5",
"pino": "^9.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.83.1",
Expand Down
Loading