Skip to content

Commit

Permalink
feat(api): add prometheus exporter
Browse files Browse the repository at this point in the history
Signed-off-by: iverly <github@iverly.net>
  • Loading branch information
iverly committed Nov 28, 2023
1 parent ac60a49 commit 641158c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0 ./node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0
COPY --from=build /usr/src/app/dist ./dist

# Expose the port that the application listens on.
EXPOSE 3100
# Expose the ports that the application listens on.
EXPOSE 3100 9100

# Run the application.
CMD ["node", "dist/apps/api/main.js"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@opentelemetry/context-async-hooks": "^1.18.1",
"@opentelemetry/core": "^1.18.1",
"@opentelemetry/exporter-jaeger": "^1.18.1",
"@opentelemetry/exporter-prometheus": "^0.45.1",
"@opentelemetry/instrumentation-fastify": "^0.32.4",
"@opentelemetry/instrumentation-http": "^0.45.1",
"@opentelemetry/instrumentation-nestjs-core": "^0.33.3",
Expand Down
11 changes: 10 additions & 1 deletion packages/opentelemetry/src/lib/opentelemetry.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ export class OpenTelemetryModule {
},
},
}),
NestOpenTelemetryModule.forRoot(),
NestOpenTelemetryModule.forRoot({
metrics: {
hostMetrics: true,
apiMetrics: {
enable: true,
ignoreRoutes: ['/favicon.ico'],
ignoreUndefinedRoutes: true,
},
},
}),
],
exports: [NestOpenTelemetryModule, LoggerModule],
};
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry/src/lib/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
import { PrismaInstrumentation } from '@prisma/instrumentation';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';

export const otelEnabled = process.env['OTEL_ENABLED'] === 'true';

export const otelSDK = new NodeSDK({
metricReader: new PrometheusExporter({
port: 9100,
}),
spanProcessor: new BatchSpanProcessor(new JaegerExporter()),
contextManager: new AsyncLocalStorageContextManager(),
textMapPropagator: new CompositePropagator({
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 641158c

Please sign in to comment.