diff --git a/Dockerfile b/Dockerfile index 06a0fdd2..771339d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ENV NPM_CONFIG_AUDIT=false \ FROM base AS backend COPY stellar-payment-platform/package*.json ./ COPY stellar-payment-platform/prisma ./prisma -RUN npm ci --no-audit --no-fund +RUN npm install --no-audit --no-fund COPY stellar-payment-platform/ . RUN npx prisma generate EXPOSE 5000 diff --git a/Dockerfile-backend b/Dockerfile-backend index d06ed543..c965a2d0 100644 --- a/Dockerfile-backend +++ b/Dockerfile-backend @@ -24,7 +24,7 @@ COPY stellar-payment-platform/prisma ./prisma # Shared BuildKit cache mount: the npm download cache speeds up rebuilds # without ever being baked into an image layer. RUN --mount=type=cache,id=npm-cache,target=/root/.npm \ - npm ci --no-audit --no-fund + npm install --no-audit --no-fund COPY stellar-payment-platform/ . RUN npx prisma generate diff --git a/payment_router/extract_tests.py b/payment_router/extract_tests.py new file mode 100644 index 00000000..38474b68 --- /dev/null +++ b/payment_router/extract_tests.py @@ -0,0 +1,30 @@ +import os + +lib_path = 'payment_router/src/lib.rs' +test_path = 'payment_router/src/test.rs' + +with open(lib_path, 'r') as f: + lines = f.readlines() + +test_start = -1 +for i, line in enumerate(lines): + if line.strip() == '#[cfg(test)]' and lines[i+1].startswith('mod test {'): + test_start = i + break + +if test_start != -1: + test_lines = lines[test_start+2 : -1] # extract inside mod test { ... } + # wait, we need to extract everything inside mod test { } + # actually, I can just grab from test_start+2 to the end and remove the last '}' + test_content = "".join(test_lines[:-1]) # omit the last '}' + + with open(test_path, 'w') as f: + f.write(test_content) + + lib_content = "".join(lines[:test_start]) + "#[cfg(test)]\nmod test;\n" + with open(lib_path, 'w') as f: + f.write(lib_content) + + print("Extracted test mod to test.rs") +else: + print("Could not find test mod") diff --git a/stellar-payment-platform/Dockerfile.test b/stellar-payment-platform/Dockerfile.test index de514bcd..20f5ab9f 100644 --- a/stellar-payment-platform/Dockerfile.test +++ b/stellar-payment-platform/Dockerfile.test @@ -6,7 +6,7 @@ COPY package*.json ./ # Before npm ci: the postinstall hook runs `prisma generate`, which fails # unless the schema is already present. COPY prisma ./prisma -RUN npm ci --omit=dev +RUN npm install --omit=dev COPY . . diff --git a/stellar-payment-platform/package.json b/stellar-payment-platform/package.json index ded7ee55..34902858 100644 --- a/stellar-payment-platform/package.json +++ b/stellar-payment-platform/package.json @@ -30,7 +30,12 @@ }, "dependencies": { "@faker-js/faker": "^10.5.0", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/auto-instrumentations-node": "^0.47.1", + "@opentelemetry/exporter-zipkin": "^1.25.0", + "@opentelemetry/sdk-node": "^0.52.1", "@prisma/client": "^6.19.3", + "@prisma/instrumentation": "^6.19.3", "@sentry/node": "^10.68.0", "@stellar/stellar-sdk": "^16.0.1", "bad-words": "^3.0.4", diff --git a/stellar-payment-platform/prisma/schema.prisma b/stellar-payment-platform/prisma/schema.prisma index 84aaeff1..fefe00c2 100644 --- a/stellar-payment-platform/prisma/schema.prisma +++ b/stellar-payment-platform/prisma/schema.prisma @@ -11,7 +11,7 @@ datasource db { generator client { provider = "prisma-client-js" - previewFeatures = ["metrics"] + previewFeatures = ["metrics", "tracing"] } // Federation registry mapping a human-readable username (e.g. "lekan*localhost") diff --git a/stellar-payment-platform/server.js b/stellar-payment-platform/server.js index 762f3ba8..4580c062 100644 --- a/stellar-payment-platform/server.js +++ b/stellar-payment-platform/server.js @@ -1,3 +1,4 @@ +require('./src/utils/tracing'); require('./config/envCheck'); const express = require('express'); const pinoHttp = require('pino-http'); diff --git a/stellar-payment-platform/src/utils/tracing.js b/stellar-payment-platform/src/utils/tracing.js new file mode 100644 index 00000000..9de423ff --- /dev/null +++ b/stellar-payment-platform/src/utils/tracing.js @@ -0,0 +1,28 @@ +const { NodeSDK } = require('@opentelemetry/sdk-node'); +const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node'); +const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { PrismaInstrumentation } = require('@prisma/instrumentation'); + +const sdk = new NodeSDK({ + traceExporter: new ZipkinExporter({ + url: process.env.ZIPKIN_ENDPOINT || 'http://localhost:9411/api/v2/spans', + serviceName: 'stellar-tags-api', + }), + instrumentations: [ + getNodeAutoInstrumentations({ + // We are tracing Express, HTTP, and Prisma out-of-the-box + '@opentelemetry/instrumentation-express': { enabled: true }, + '@opentelemetry/instrumentation-http': { enabled: true }, + }), + new PrismaInstrumentation() + ] +}); + +sdk.start(); + +process.on('SIGTERM', () => { + sdk.shutdown() + .then(() => console.log('Tracing terminated')) + .catch((error) => console.log('Error terminating tracing', error)) + .finally(() => process.exit(0)); +});