├── .husky ├── .gitignore ├── pre-commit └── commit-msg ├── .tool-versions ├── .prettierignore ├── .eslintignore ├── .npmrc ├── tsconfig.build.json ├── src ├── index.ts ├── metrics │ ├── index.ts │ ├── gauge.ts │ ├── counter.ts │ ├── summary.ts │ ├── histogram.ts │ └── utils.ts ├── constants.ts ├── injector.ts ├── controller.ts ├── interfaces.ts └── module.ts ├── .editorconfig ├── ad-hocs └── mocha │ ├── plugins.ts │ └── hooks.ts ├── tsconfig.lint.json ├── .prettierrc.js ├── test ├── injector.spec.ts ├── fixtures │ ├── resource.controller.ts │ ├── core.module.ts │ └── core-prefix.module.ts ├── metrics │ ├── summary.spec.ts │ ├── histogram.spec.ts │ ├── gauge.spec.ts │ └── counter.spec.ts ├── utils.ts ├── fastify.spec.ts ├── custom-controller.spec.ts ├── push-gateway.spec.ts ├── e2e.spec.ts └── module.spec.ts ├── .vscode └── settings.json ├── .github ├── workflows │ └── ci.yml └── FUNDING.yml ├── renovate.json ├── .gitignore ├── tsconfig.json ├── .gitattributes ├── eslint.config.mjs ├── package.json ├── README.md ├── LICENSE └── CHANGELOG.md /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs lts 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | pnpm exec lint-staged 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | pnpm exec commitlint --edit "$1" 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | CHANGELOG.md 2 | dist 3 | pnpm-lock.yaml 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | typings 5 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | strict-peer-dependencies=true 2 | auto-install-peers=true 3 | save-exact=true 4 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["src/**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./controller"; 2 | export * from "./injector"; 3 | export * from "./interfaces"; 4 | export * from "./metrics"; 5 | export * from "./module"; 6 | -------------------------------------------------------------------------------- /src/metrics/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./counter"; 2 | export * from "./gauge"; 3 | export * from "./histogram"; 4 | export * from "./summary"; 5 | export * from "./utils"; 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /ad-hocs/mocha/plugins.ts: -------------------------------------------------------------------------------- 1 | import * as chai from "chai"; 2 | import * as chaiAsPromised from "chai-as-promised"; 3 | import * as sinonChai from "sinon-chai"; 4 | 5 | chai.use(chaiAsPromised); 6 | chai.use(sinonChai); 7 | -------------------------------------------------------------------------------- /tsconfig.lint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": [ 4 | "src/**/*.ts", 5 | "test/**/*.ts", 6 | "ad-hocs/**/*.ts", 7 | ".*.js", 8 | "*.js", 9 | "*.ts", 10 | "*.mjs" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Token used to register the computed options as a provider 3 | * 4 | * @internal 5 | */ 6 | export const PROMETHEUS_OPTIONS = Symbol("PROMETHEUS_OPTIONS"); 7 | 8 | /** 9 | * @internal 10 | */ 11 | export const PROM_CLIENT = Symbol("PROM_CLIENT"); 12 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: "always", 3 | semi: true, 4 | singleQuote: false, 5 | trailingComma: "all", 6 | plugins: [ 7 | require.resolve("prettier-plugin-organize-imports"), 8 | require.resolve("prettier-plugin-packagejson"), 9 | ], 10 | }; 11 | -------------------------------------------------------------------------------- /test/injector.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { InjectMetric } from "../src"; 3 | 4 | describe("InjectMetric", function () { 5 | it("returns a function", function () { 6 | const result = InjectMetric("controller"); 7 | 8 | expect(result).to.be.a("function"); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /ad-hocs/mocha/hooks.ts: -------------------------------------------------------------------------------- 1 | import { RootHookObject } from "mocha"; 2 | import * as sinon from "sinon"; 3 | 4 | export const mochaHooks: () => RootHookObject = () => { 5 | return { 6 | afterEach() { 7 | // https://sinonjs.org/releases/v9.1.0/general-setup/ 8 | sinon.restore(); 9 | }, 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll": "explicit", 4 | "source.organizeImports": "explicit" 5 | }, 6 | "typescript.preferences.importModuleSpecifier": "relative", 7 | "typescript.preferences.quoteStyle": "double", 8 | "typescript.tsdk": "node_modules/typescript/lib" 9 | } 10 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | test: 11 | uses: "willsoto/actions/.github/workflows/node-ci.yml@v3.1.0" 12 | secrets: 13 | GitHubToken: ${{ secrets.GH_TOKEN }} 14 | NPMToken: ${{ secrets.NPM_TOKEN }} 15 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended", 5 | "group:typescript-eslintMonorepo", 6 | "group:allNonMajor" 7 | ], 8 | "automerge": true, 9 | "semanticCommits": "enabled", 10 | "ignoreDeps": ["chai"], 11 | "schedule": ["before 4am on Monday"], 12 | "minimumReleaseAge": "7 days" 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # OS 14 | .DS_Store 15 | 16 | # Tests 17 | /coverage 18 | /.nyc_output 19 | 20 | # IDEs and editors 21 | /.idea 22 | .project 23 | .classpath 24 | .c9/ 25 | *.launch 26 | .settings/ 27 | *.sublime-workspace 28 | 29 | # IDE - VSCode 30 | .vscode/* 31 | !.vscode/settings.json 32 | !.vscode/tasks.json 33 | !.vscode/launch.json 34 | !.vscode/extensions.json 35 | 36 | /typings 37 | /docs 38 | /temp 39 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "outDir": "./dist", 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "declaration": true, 8 | "declarationMap": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "lib": ["es2018"], 11 | "module": "commonjs", 12 | "removeComments": false, 13 | "skipLibCheck": true, 14 | "sourceMap": true, 15 | "strict": true, 16 | "target": "es2018" 17 | }, 18 | "include": ["src/**/*.ts", "test/**/*.ts"], 19 | "exclude": ["node_modules", "dist"] 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/resource.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from "@nestjs/common"; 2 | import { Counter, Gauge } from "prom-client"; 3 | import { InjectMetric } from "../../src"; 4 | 5 | @Controller("/resource") 6 | export class ResourceController { 7 | constructor( 8 | @InjectMetric("counter") public counter: Counter, 9 | @InjectMetric("gauge") public gauge: Gauge, 10 | ) {} 11 | 12 | @Get("/counter") 13 | counterMetric() { 14 | this.counter.inc(); 15 | return this.counter.get(); 16 | } 17 | 18 | @Get("/gauge") 19 | gaugeMetric() { 20 | this.gauge.inc(); 21 | return this.gauge.get(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [willsoto] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /src/injector.ts: -------------------------------------------------------------------------------- 1 | import { Inject } from "@nestjs/common"; 2 | import { getToken } from "./metrics"; 3 | 4 | /** 5 | * Used to inject the registered metric via the given token 6 | * 7 | * @public 8 | * 9 | * @example 10 | * Assuming you have registered a metric with the name `metric_name`, you would inject it 11 | * like so: 12 | * ``` 13 | * import { Injectable } from "@nestjs/common"; 14 | * import { Counter } from "prom-client"; 15 | * import { InjectMetric } from "@willsoto/nestjs-prometheus"; 16 | * 17 | * @Injectable() 18 | * export class Service { 19 | * constructor(@InjectMetric("metric_name") public counter: Counter) {} 20 | * } 21 | * ``` 22 | */ 23 | export function InjectMetric(name: string) { 24 | return Inject(getToken(name)); 25 | } 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Don't allow people to merge changes to these generated files, because the result 2 | # may be invalid. You need to run "rush update" again. 3 | pnpm-lock.yaml merge=binary 4 | shrinkwrap.yaml merge=binary 5 | npm-shrinkwrap.json merge=binary 6 | yarn.lock merge=binary 7 | 8 | # Rush's JSON config files use JavaScript-style code comments. The rule below prevents pedantic 9 | # syntax highlighters such as GitHub's from highlighting these comments as errors. Your text editor 10 | # may also require a special configuration to allow comments in JSON. 11 | # 12 | # For more information, see this issue: https://github.com/microsoft/rushstack/issues/1088 13 | # 14 | *.json linguist-language=JSON-with-Comments 15 | -------------------------------------------------------------------------------- /src/metrics/gauge.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from "@nestjs/common"; 2 | import * as client from "prom-client"; 3 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 4 | import { PROMETHEUS_OPTIONS } from "../constants"; 5 | import { PrometheusOptions } from "../interfaces"; 6 | import { getOrCreateMetric, getToken } from "./utils"; 7 | 8 | /** 9 | * @public 10 | */ 11 | export function makeGaugeProvider( 12 | options: client.GaugeConfiguration, 13 | ): Provider { 14 | return { 15 | provide: getToken(options.name), 16 | useFactory( 17 | config?: PrometheusOptions, 18 | ): client.Metric { 19 | return getOrCreateMetric("Gauge", options, config); 20 | }, 21 | inject: [ 22 | { 23 | token: PROMETHEUS_OPTIONS, 24 | optional: true, 25 | }, 26 | ], 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/metrics/counter.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from "@nestjs/common"; 2 | import * as client from "prom-client"; 3 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 4 | import { PROMETHEUS_OPTIONS } from "../constants"; 5 | import { PrometheusOptions } from "../interfaces"; 6 | import { getOrCreateMetric, getToken } from "./utils"; 7 | 8 | /** 9 | * @public 10 | */ 11 | export function makeCounterProvider( 12 | options: client.CounterConfiguration, 13 | ): Provider { 14 | return { 15 | provide: getToken(options.name), 16 | useFactory( 17 | config?: PrometheusOptions, 18 | ): client.Metric { 19 | return getOrCreateMetric("Counter", options, config); 20 | }, 21 | inject: [ 22 | { 23 | token: PROMETHEUS_OPTIONS, 24 | optional: true, 25 | }, 26 | ], 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/metrics/summary.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from "@nestjs/common"; 2 | import * as client from "prom-client"; 3 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 4 | import { PROMETHEUS_OPTIONS } from "../constants"; 5 | import { PrometheusOptions } from "../interfaces"; 6 | import { getOrCreateMetric, getToken } from "./utils"; 7 | 8 | /** 9 | * @public 10 | */ 11 | export function makeSummaryProvider( 12 | options: client.SummaryConfiguration, 13 | ): Provider { 14 | return { 15 | provide: getToken(options.name), 16 | useFactory( 17 | config?: PrometheusOptions, 18 | ): client.Metric { 19 | return getOrCreateMetric("Summary", options, config); 20 | }, 21 | inject: [ 22 | { 23 | token: PROMETHEUS_OPTIONS, 24 | optional: true, 25 | }, 26 | ], 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/metrics/histogram.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from "@nestjs/common"; 2 | import * as client from "prom-client"; 3 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 4 | import { PROMETHEUS_OPTIONS } from "../constants"; 5 | import { PrometheusOptions } from "../interfaces"; 6 | import { getOrCreateMetric, getToken } from "./utils"; 7 | 8 | /** 9 | * @public 10 | */ 11 | export function makeHistogramProvider( 12 | options: client.HistogramConfiguration, 13 | ): Provider { 14 | return { 15 | provide: getToken(options.name), 16 | useFactory( 17 | config?: PrometheusOptions, 18 | ): client.Metric { 19 | return getOrCreateMetric("Histogram", options, config); 20 | }, 21 | inject: [ 22 | { 23 | token: PROMETHEUS_OPTIONS, 24 | optional: true, 25 | }, 26 | ], 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/controller.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unsafe-call */ 2 | /* eslint-disable @typescript-eslint/ban-ts-comment */ 3 | import { Controller, Get, Res } from "@nestjs/common"; 4 | import * as client from "prom-client"; 5 | 6 | /** 7 | * @public 8 | * 9 | * {@inheritDoc PrometheusOptions.controller} 10 | */ 11 | @Controller() 12 | export class PrometheusController { 13 | @Get() 14 | async index(@Res({ passthrough: true }) response: unknown): Promise { 15 | // See this issue for why we type this as `unknown` 16 | // https://github.com/willsoto/nestjs-prometheus/issues/530 17 | // I currently don't know of any type from NestJS that captures the 18 | // union of all available responses and I don't want to force users to 19 | // download types for a framework they aren't using. 20 | // @ts-expect-error 21 | response.header("Content-Type", client.register.contentType); 22 | return client.register.metrics(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/core.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from "@nestjs/common"; 2 | import { 3 | PrometheusModule, 4 | makeCounterProvider, 5 | makeGaugeProvider, 6 | makeHistogramProvider, 7 | makeSummaryProvider, 8 | } from "../../src"; 9 | 10 | const counter = makeCounterProvider({ 11 | name: "counter", 12 | help: "counter helper", 13 | }); 14 | 15 | const gauge = makeGaugeProvider({ 16 | name: "gauge", 17 | help: "gauge helper", 18 | }); 19 | 20 | @Module({ 21 | imports: [ 22 | PrometheusModule.register({ 23 | defaultMetrics: { 24 | enabled: false, 25 | }, 26 | }), 27 | ], 28 | providers: [ 29 | counter, 30 | gauge, 31 | makeHistogramProvider({ 32 | name: "histogram", 33 | help: "histrogram helper", 34 | }), 35 | makeSummaryProvider({ 36 | name: "summary", 37 | help: "summary helper", 38 | }), 39 | ], 40 | exports: [PrometheusModule, counter, gauge], 41 | }) 42 | export class CoreModule {} 43 | -------------------------------------------------------------------------------- /test/fixtures/core-prefix.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from "@nestjs/common"; 2 | import { 3 | PrometheusModule, 4 | makeCounterProvider, 5 | makeGaugeProvider, 6 | makeHistogramProvider, 7 | makeSummaryProvider, 8 | } from "../../src"; 9 | 10 | const counter = makeCounterProvider({ 11 | name: "counter", 12 | help: "counter helper", 13 | }); 14 | 15 | const gauge = makeGaugeProvider({ 16 | name: "gauge", 17 | help: "gauge helper", 18 | }); 19 | 20 | @Module({ 21 | imports: [ 22 | PrometheusModule.register({ 23 | defaultMetrics: { 24 | enabled: false, 25 | }, 26 | customMetricPrefix: "app", 27 | }), 28 | ], 29 | providers: [ 30 | counter, 31 | gauge, 32 | makeHistogramProvider({ 33 | name: "histogram", 34 | help: "histrogram helper", 35 | }), 36 | makeSummaryProvider({ 37 | name: "summary", 38 | help: "summary helper", 39 | }), 40 | ], 41 | exports: [PrometheusModule, counter, gauge], 42 | }) 43 | export class CorePrefixModule {} 44 | -------------------------------------------------------------------------------- /test/metrics/summary.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from "@nestjs/testing"; 2 | import { expect } from "chai"; 3 | import * as client from "prom-client"; 4 | import { MetricObjectWithValues, MetricValue } from "prom-client"; 5 | import { getToken, makeSummaryProvider } from "../../src"; 6 | import { PROMETHEUS_OPTIONS } from "../../src/constants"; 7 | 8 | describe("Summary", function () { 9 | let testingModule: TestingModule; 10 | let metric: client.Summary; 11 | 12 | beforeEach(async function () { 13 | testingModule = await Test.createTestingModule({ 14 | providers: [ 15 | makeSummaryProvider({ 16 | name: "controller_summary", 17 | help: "controller_summary_help", 18 | }), 19 | { 20 | provide: PROMETHEUS_OPTIONS, 21 | useValue: { 22 | customMetricPrefix: "app", 23 | }, 24 | }, 25 | ], 26 | }).compile(); 27 | 28 | metric = testingModule.get(getToken("controller_summary")); 29 | }); 30 | 31 | afterEach(async function () { 32 | await testingModule.close(); 33 | }); 34 | 35 | it("creates a Summary", function () { 36 | expect(metric).to.be.instanceOf(client.Summary); 37 | }); 38 | 39 | it("has the appropriate methods (observe)", function () { 40 | expect(metric.observe).to.be.a("function"); 41 | }); 42 | 43 | it("should prefix the metric if provided", async function () { 44 | const metricValues: MetricObjectWithValues> = 45 | await metric.get(); 46 | 47 | expect(metricValues.name).to.eq("app_controller_summary"); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /test/metrics/histogram.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from "@nestjs/testing"; 2 | import { expect } from "chai"; 3 | import * as client from "prom-client"; 4 | import { MetricObjectWithValues, MetricValue } from "prom-client"; 5 | import { getToken, makeHistogramProvider } from "../../src"; 6 | import { PROMETHEUS_OPTIONS } from "../../src/constants"; 7 | 8 | describe("Histogram", function () { 9 | let testingModule: TestingModule; 10 | let metric: client.Histogram; 11 | 12 | beforeEach(async function () { 13 | testingModule = await Test.createTestingModule({ 14 | providers: [ 15 | makeHistogramProvider({ 16 | name: "controller_histogram", 17 | help: "controller_histogram_help", 18 | }), 19 | { 20 | provide: PROMETHEUS_OPTIONS, 21 | useValue: { 22 | customMetricPrefix: "app", 23 | }, 24 | }, 25 | ], 26 | }).compile(); 27 | 28 | metric = testingModule.get(getToken("controller_histogram")); 29 | }); 30 | 31 | afterEach(async function () { 32 | await testingModule.close(); 33 | }); 34 | 35 | it("creates a Histogram", function () { 36 | expect(metric).to.be.instanceOf(client.Histogram); 37 | }); 38 | 39 | it("has the appropriate methods (observe)", function () { 40 | expect(metric.observe).to.be.a("function"); 41 | }); 42 | 43 | it("should prefix the metric if provided", async function () { 44 | const metricValues: MetricObjectWithValues> = 45 | await metric.get(); 46 | 47 | expect(metricValues.name).to.eq("app_controller_histogram"); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /test/metrics/gauge.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from "@nestjs/testing"; 2 | import { expect } from "chai"; 3 | import * as client from "prom-client"; 4 | import { MetricObjectWithValues, MetricValue } from "prom-client"; 5 | import { getToken, makeGaugeProvider } from "../../src"; 6 | import { PROMETHEUS_OPTIONS } from "../../src/constants"; 7 | 8 | describe("Gauge", function () { 9 | let testingModule: TestingModule; 10 | let metric: client.Gauge; 11 | 12 | beforeEach(async function () { 13 | testingModule = await Test.createTestingModule({ 14 | providers: [ 15 | { 16 | provide: PROMETHEUS_OPTIONS, 17 | useValue: { 18 | customMetricPrefix: "app", 19 | }, 20 | }, 21 | makeGaugeProvider({ 22 | name: "controller_gauge", 23 | help: "controller_gauge_help", 24 | }), 25 | ], 26 | }).compile(); 27 | 28 | metric = testingModule.get(getToken("controller_gauge")); 29 | }); 30 | 31 | afterEach(async function () { 32 | await testingModule.close(); 33 | }); 34 | 35 | it("creates a Gauge", function () { 36 | expect(metric).to.be.instanceOf(client.Gauge); 37 | }); 38 | 39 | it("has the appropriate methods (inc)", function () { 40 | expect(metric.inc).to.be.a("function"); 41 | }); 42 | 43 | it("has the appropriate methods (dec)", function () { 44 | expect(metric.dec).to.be.a("function"); 45 | }); 46 | 47 | it("should prefix the metric if provided", async function () { 48 | const metricValues: MetricObjectWithValues> = 49 | await metric.get(); 50 | 51 | expect(metricValues.name).to.eq("app_controller_gauge"); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /test/utils.ts: -------------------------------------------------------------------------------- 1 | import { INestApplication } from "@nestjs/common"; 2 | import { NestExpressApplication } from "@nestjs/platform-express"; 3 | import { Test, TestingModule } from "@nestjs/testing"; 4 | import * as request from "supertest"; 5 | import { 6 | PrometheusAsyncOptions, 7 | PrometheusModule, 8 | PrometheusOptions, 9 | } from "../src"; 10 | // eslint-disable-next-line @typescript-eslint/no-require-imports 11 | import TestAgent = require("supertest/lib/agent"); 12 | 13 | export type Agent = TestAgent; 14 | export type App = INestApplication; 15 | 16 | export interface TestHarness { 17 | testingModule: TestingModule; 18 | app: App; 19 | agent: Agent; 20 | } 21 | 22 | export async function createPrometheusModule( 23 | options?: PrometheusOptions, 24 | ): Promise { 25 | const testingModule = await Test.createTestingModule({ 26 | imports: [PrometheusModule.register(options)], 27 | }).compile(); 28 | 29 | const app = testingModule.createNestApplication(); 30 | await app.init(); 31 | 32 | const agent = request(app.getHttpServer()); 33 | 34 | return { 35 | testingModule, 36 | app, 37 | agent, 38 | }; 39 | } 40 | 41 | export async function createAsyncPrometheusModule( 42 | options: PrometheusAsyncOptions, 43 | ): Promise { 44 | const testingModule = await Test.createTestingModule({ 45 | imports: [PrometheusModule.registerAsync(options)], 46 | }).compile(); 47 | 48 | const app = testingModule.createNestApplication(); 49 | await app.init(); 50 | 51 | const agent = request(app.getHttpServer()); 52 | 53 | return { 54 | testingModule, 55 | app, 56 | agent, 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /test/fastify.spec.ts: -------------------------------------------------------------------------------- 1 | import compression from "@fastify/compress"; 2 | import { 3 | FastifyAdapter, 4 | NestFastifyApplication, 5 | } from "@nestjs/platform-fastify"; 6 | import { Test } from "@nestjs/testing"; 7 | import { expect } from "chai"; 8 | import { afterEach, beforeEach } from "mocha"; 9 | import { register } from "prom-client"; 10 | import { PrometheusModule } from "../src"; 11 | 12 | describe("Fastify integration", () => { 13 | let app: NestFastifyApplication; 14 | 15 | beforeEach(async () => { 16 | const testingModule = await Test.createTestingModule({ 17 | imports: [PrometheusModule.register()], 18 | }).compile(); 19 | 20 | app = testingModule.createNestApplication( 21 | new FastifyAdapter(), 22 | ); 23 | }); 24 | 25 | afterEach(async () => { 26 | register.clear(); 27 | await app.close(); 28 | }); 29 | 30 | describe("without compression", function () { 31 | beforeEach(async () => { 32 | await app.init(); 33 | }); 34 | 35 | it("registers a /metrics endpoint", async () => { 36 | const response = await app.inject({ 37 | method: "GET", 38 | url: "/metrics", 39 | }); 40 | 41 | expect(response).to.have.property("statusCode").to.eql(200); 42 | expect(response.body).to.be.a("string"); 43 | }); 44 | }); 45 | 46 | describe("with compression", function () { 47 | beforeEach(async () => { 48 | await app.register(compression); 49 | await app.init(); 50 | }); 51 | 52 | it("registers a /metrics endpoint", async () => { 53 | const response = await app.inject({ 54 | method: "GET", 55 | url: "/metrics", 56 | }); 57 | 58 | expect(response).to.have.property("statusCode").to.eql(200); 59 | expect(response.body).to.be.a("string"); 60 | }); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import { FlatCompat } from "@eslint/eslintrc"; 3 | import js from "@eslint/js"; 4 | import typescriptEslint from "@typescript-eslint/eslint-plugin"; 5 | import tsParser from "@typescript-eslint/parser"; 6 | import globals from "globals"; 7 | import path from "node:path"; 8 | import { fileURLToPath } from "node:url"; 9 | 10 | const __filename = fileURLToPath(import.meta.url); 11 | const __dirname = path.dirname(__filename); 12 | const compat = new FlatCompat({ 13 | baseDirectory: __dirname, 14 | recommendedConfig: js.configs.recommended, 15 | allConfig: js.configs.all, 16 | }); 17 | 18 | export default [ 19 | { 20 | ignores: ["**/node_modules", "**/dist", "**/coverage", "**/typings"], 21 | }, 22 | ...compat.extends( 23 | "eslint:recommended", 24 | "plugin:@typescript-eslint/eslint-recommended", 25 | "plugin:@typescript-eslint/recommended", 26 | "plugin:@typescript-eslint/recommended-requiring-type-checking", 27 | "prettier", 28 | ), 29 | { 30 | plugins: { 31 | "@typescript-eslint": typescriptEslint, 32 | }, 33 | 34 | languageOptions: { 35 | globals: { 36 | ...globals.node, 37 | Reflect: true, 38 | }, 39 | 40 | parser: tsParser, 41 | ecmaVersion: 5, 42 | sourceType: "commonjs", 43 | 44 | parserOptions: { 45 | project: "./tsconfig.lint.json", 46 | }, 47 | }, 48 | 49 | rules: { 50 | "new-cap": "off", 51 | }, 52 | }, 53 | { 54 | files: ["test/**/*.ts"], 55 | 56 | languageOptions: { 57 | globals: { 58 | ...globals.mocha, 59 | }, 60 | }, 61 | 62 | rules: { 63 | "@typescript-eslint/explicit-function-return-type": "off", 64 | "no-unused-expressions": "off", 65 | "no-magic-numbers": "off", 66 | "@typescript-eslint/unbound-method": "off", 67 | }, 68 | }, 69 | ]; 70 | -------------------------------------------------------------------------------- /src/metrics/utils.ts: -------------------------------------------------------------------------------- 1 | import * as client from "prom-client"; 2 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 3 | import { PrometheusOptions } from "../interfaces"; 4 | 5 | /** 6 | * @internal 7 | */ 8 | export type Metrics = "Gauge" | "Summary" | "Histogram" | "Counter"; 9 | 10 | /** 11 | * @internal 12 | */ 13 | export type Options = 14 | | client.GaugeConfiguration 15 | | client.SummaryConfiguration 16 | | client.CounterConfiguration 17 | | client.HistogramConfiguration; 18 | 19 | /** 20 | * @internal 21 | */ 22 | export function getOrCreateMetric< 23 | T extends RegistryContentType = PrometheusContentType, 24 | >( 25 | type: Metrics, 26 | options: Options, 27 | prometheusOptions?: PrometheusOptions, 28 | ): client.Metric { 29 | const opts: Options = { 30 | ...options, 31 | name: prometheusOptions?.customMetricPrefix 32 | ? prometheusOptions.customMetricPrefix.concat("_", options.name) 33 | : options.name, 34 | }; 35 | 36 | const existingMetric = client.register.getSingleMetric(opts.name); 37 | if (existingMetric) { 38 | return existingMetric; 39 | } 40 | 41 | switch (type) { 42 | case "Gauge": 43 | return new client.Gauge(opts as client.GaugeConfiguration); 44 | case "Counter": 45 | return new client.Counter(opts as client.CounterConfiguration); 46 | case "Histogram": 47 | return new client.Histogram( 48 | opts as client.HistogramConfiguration, 49 | ); 50 | case "Summary": 51 | return new client.Summary(opts as client.SummaryConfiguration); 52 | default: 53 | // eslint-disable-next-line @typescript-eslint/restrict-template-expressions 54 | throw new Error(`Unknown type: ${type}`); 55 | } 56 | } 57 | 58 | /** 59 | * @public 60 | */ 61 | export function getToken(name: string): string { 62 | return `PROM_METRIC_${name.toUpperCase()}`; 63 | } 64 | -------------------------------------------------------------------------------- /test/metrics/counter.spec.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@nestjs/common"; 2 | import { Test, TestingModule } from "@nestjs/testing"; 3 | import { expect } from "chai"; 4 | import * as client from "prom-client"; 5 | import { 6 | Counter, 7 | MetricObjectWithValues, 8 | MetricValue, 9 | register, 10 | } from "prom-client"; 11 | import { 12 | InjectMetric, 13 | PrometheusModule, 14 | getToken, 15 | makeCounterProvider, 16 | } from "../../src"; 17 | 18 | describe("Counter", function () { 19 | let testingModule: TestingModule; 20 | let metric: client.Counter; 21 | 22 | @Injectable() 23 | class MyService { 24 | constructor( 25 | @InjectMetric("controller_counter") public counter: Counter, 26 | ) {} 27 | } 28 | 29 | beforeEach(async function () { 30 | testingModule = await Test.createTestingModule({ 31 | imports: [PrometheusModule.register()], 32 | providers: [ 33 | MyService, 34 | makeCounterProvider({ 35 | name: "controller_counter", 36 | help: "controller_counter_help", 37 | }), 38 | ], 39 | }).compile(); 40 | 41 | metric = testingModule.get(getToken("controller_counter")); 42 | }); 43 | 44 | afterEach(async function () { 45 | register.clear(); 46 | await testingModule.close(); 47 | }); 48 | 49 | it("creates a Counter", function () { 50 | expect(metric).to.be.instanceOf(client.Counter); 51 | }); 52 | 53 | it("has the appropriate methods (inc)", function () { 54 | expect(metric.inc).to.be.a("function"); 55 | }); 56 | 57 | it("should be injectable into the service", function () { 58 | expect(testingModule.get(MyService)).to.be.instanceOf(MyService); 59 | 60 | const service = testingModule.get(MyService); 61 | 62 | expect(service.counter).to.be.instanceOf(Counter); 63 | }); 64 | 65 | it("should not prefix the metric if not provided", async function () { 66 | const metricValues: MetricObjectWithValues> = 67 | await metric.get(); 68 | expect(metricValues.name).to.equal("controller_counter"); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /test/custom-controller.spec.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-expressions */ 2 | import { Get, Res } from "@nestjs/common"; 3 | import { expect } from "chai"; 4 | import { Response } from "express"; 5 | import { register } from "prom-client"; 6 | import * as sinon from "sinon"; 7 | import { PrometheusController } from "../src"; 8 | import { 9 | Agent, 10 | App, 11 | createAsyncPrometheusModule, 12 | createPrometheusModule, 13 | } from "./utils"; 14 | 15 | describe("PrometheusModule with a custom controller", function () { 16 | let agent: Agent; 17 | let app: App; 18 | let fake: sinon.SinonSpy; 19 | 20 | afterEach(async function () { 21 | register.clear(); 22 | await app.close(); 23 | }); 24 | 25 | it("registers a /metrics endpoint (sync)", async function () { 26 | fake = sinon.fake(); 27 | 28 | class CustomController extends PrometheusController { 29 | @Get() 30 | async index(@Res() response: Response): Promise { 31 | fake(); 32 | return super.index(response); 33 | } 34 | } 35 | 36 | ({ agent, app } = await createPrometheusModule({ 37 | controller: CustomController, 38 | })); 39 | 40 | const response = await agent.get("/metrics"); 41 | 42 | expect(response).to.have.property("status").to.eql(200); 43 | expect(fake).to.have.been.calledOnce; 44 | 45 | expect(response) 46 | .to.have.property("text") 47 | .to.contain("process_cpu_user_seconds_total"); 48 | }); 49 | 50 | it("registers a /metrics endpoint (async)", async function () { 51 | fake = sinon.fake(); 52 | 53 | class CustomController extends PrometheusController { 54 | @Get() 55 | async index(@Res() response: Response): Promise { 56 | fake(); 57 | return super.index(response); 58 | } 59 | } 60 | 61 | ({ agent, app } = await createAsyncPrometheusModule({ 62 | controller: CustomController, 63 | useFactory() { 64 | return {}; 65 | }, 66 | })); 67 | 68 | const response = await agent.get("/metrics"); 69 | 70 | expect(response).to.have.property("status").to.eql(200); 71 | expect(fake).to.have.been.calledOnce; 72 | 73 | expect(response) 74 | .to.have.property("text") 75 | .to.contain("process_cpu_user_seconds_total"); 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /test/push-gateway.spec.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Module } from "@nestjs/common"; 2 | import { Test } from "@nestjs/testing"; 3 | import { expect } from "chai"; 4 | import { PrometheusContentType, Pushgateway, register } from "prom-client"; 5 | import { 6 | PrometheusModule, 7 | PrometheusOptions, 8 | PrometheusOptionsFactory, 9 | } from "../src"; 10 | import { createAsyncPrometheusModule, createPrometheusModule } from "./utils"; 11 | 12 | describe("Pushgateway", function () { 13 | @Injectable() 14 | class OptionsService implements PrometheusOptionsFactory { 15 | createPrometheusOptions(): PrometheusOptions | Promise { 16 | return { 17 | pushgateway: { 18 | url: "http://127.0.0.1:9091", 19 | }, 20 | }; 21 | } 22 | } 23 | 24 | @Injectable() 25 | class MockService { 26 | constructor( 27 | public readonly pushgateway: Pushgateway, 28 | ) {} 29 | } 30 | 31 | @Module({ 32 | providers: [OptionsService], 33 | exports: [OptionsService], 34 | }) 35 | class OptionsModule {} 36 | 37 | afterEach(function () { 38 | register.clear(); 39 | }); 40 | 41 | it("should register a pushgateway if options are provided (sync)", async function () { 42 | const { testingModule, app } = await createPrometheusModule({ 43 | pushgateway: { 44 | url: "http://127.0.0.1:9091", 45 | }, 46 | }); 47 | const gateway = testingModule.get(Pushgateway); 48 | 49 | expect(gateway).to.be.instanceOf(Pushgateway); 50 | 51 | await app.close(); 52 | }); 53 | 54 | it("should register a pushgateway if options are provided (async)", async function () { 55 | const { testingModule, app } = await createAsyncPrometheusModule({ 56 | imports: [OptionsModule], 57 | useExisting: OptionsService, 58 | inject: [OptionsService], 59 | }); 60 | const gateway = testingModule.get(Pushgateway); 61 | 62 | expect(gateway).to.be.instanceOf(Pushgateway); 63 | 64 | await app.close(); 65 | }); 66 | 67 | it("should be injected in another provider for sync", async function () { 68 | const moduleRef = await Test.createTestingModule({ 69 | imports: [ 70 | PrometheusModule.register({ 71 | pushgateway: { 72 | url: "http://127.0.0.1:9091", 73 | }, 74 | }), 75 | ], 76 | providers: [MockService], 77 | }).compile(); 78 | 79 | const mockService = moduleRef.get(MockService); 80 | 81 | expect(mockService.pushgateway).to.be.an.instanceOf(Pushgateway); 82 | expect(mockService.pushgateway).to.have.property( 83 | "gatewayUrl", 84 | "http://127.0.0.1:9091", 85 | ); 86 | }); 87 | 88 | it("should be injected in another provider for async", async function () { 89 | const moduleRef = await Test.createTestingModule({ 90 | imports: [ 91 | PrometheusModule.registerAsync({ 92 | useClass: OptionsService, 93 | }), 94 | ], 95 | providers: [MockService], 96 | }).compile(); 97 | 98 | const mockService = moduleRef.get(MockService); 99 | 100 | expect(mockService.pushgateway).to.be.an.instanceOf(Pushgateway); 101 | expect(mockService.pushgateway).to.have.property( 102 | "gatewayUrl", 103 | "http://127.0.0.1:9091", 104 | ); 105 | }); 106 | }); 107 | -------------------------------------------------------------------------------- /src/interfaces.ts: -------------------------------------------------------------------------------- 1 | import { Type } from "@nestjs/common"; 2 | import { ModuleMetadata } from "@nestjs/common/interfaces"; 3 | import * as client from "prom-client"; 4 | import { PrometheusContentType, RegistryContentType } from "prom-client"; 5 | 6 | /** 7 | * Configuration for the defaultMetrics collected by `prom-client`. 8 | * 9 | * @public 10 | */ 11 | export interface PrometheusDefaultMetrics< 12 | T extends RegistryContentType = PrometheusContentType, 13 | > { 14 | /** 15 | * Whether or not default metrics are collected. 16 | * 17 | * @defaultValue true 18 | */ 19 | enabled: boolean; 20 | /** 21 | * {@link https://github.com/siimon/prom-client#default-metrics | Default Metrics} 22 | */ 23 | config?: client.DefaultMetricsCollectorConfiguration; 24 | } 25 | 26 | /** 27 | * Options for the Prometheus Module. 28 | * 29 | * @public 30 | */ 31 | export interface PrometheusOptions< 32 | T extends RegistryContentType = PrometheusContentType, 33 | > { 34 | /** 35 | * Make the module global when set to true 36 | * */ 37 | global?: boolean; 38 | /** 39 | * Similar to `defaultMetrics.prefix`, this will be applied to each custom 40 | * metric created using the various providers. Will suffix the given prefix 41 | * with `_`. 42 | * 43 | * For example, given a metric name of "my_metric" and a prefix of "app" 44 | * would create a metric name of `app_my_metric` 45 | * */ 46 | customMetricPrefix?: string; 47 | /** 48 | * A custom controller to be used instead of the default one. Only needs to be 49 | * provided if you need to do any kind of customization on the route, eg Swagger. 50 | * 51 | * You can use the {@link PrometheusController} as a base class. 52 | * 53 | * @example 54 | * ``` 55 | * import { PrometheusController } from "@willsoto/nestjs-prometheus"; 56 | * import { Controller, Get, Res } from "@nestjs/common"; 57 | * import { Response } from "express"; 58 | * 59 | * @Controller() 60 | * class MyCustomController extends PrometheusController { 61 | * @Get() 62 | * index(@Res({ passthrough: true }) response: Response) { 63 | * return super.index(response); 64 | * } 65 | * } 66 | * ``` 67 | */ 68 | controller?: Type; 69 | /** 70 | * The URL at which Prometheus metrics will be available 71 | * 72 | * @defaultValue /metrics 73 | */ 74 | path?: string; 75 | /** {@inheritDoc PrometheusDefaultMetrics} */ 76 | defaultMetrics?: PrometheusDefaultMetrics; 77 | /** 78 | * Will be passed into `setDefaultLabels` 79 | * 80 | * {@link https://github.com/siimon/prom-client#default-labels-segmented-by-registry} 81 | */ 82 | // Using this type to match what prom-client specifies. 83 | defaultLabels?: object; 84 | pushgateway?: { 85 | url: string; 86 | options?: unknown; 87 | registry?: client.Registry; 88 | }; 89 | } 90 | 91 | export type PrometheusOptionsWithDefaults< 92 | T extends RegistryContentType = PrometheusContentType, 93 | > = Required, "pushgateway" | "customMetricPrefix">>; 94 | 95 | /** 96 | * @private 97 | */ 98 | export interface PrometheusOptionsFactory< 99 | T extends RegistryContentType = PrometheusContentType, 100 | > { 101 | createPrometheusOptions(): 102 | | Promise> 103 | | PrometheusOptions; 104 | } 105 | 106 | /** 107 | * @private 108 | */ 109 | export type PrometheusUseFactoryOptions< 110 | T extends RegistryContentType = PrometheusContentType, 111 | > = Omit, "controller">; 112 | 113 | /** 114 | * Options for configuring a dynamic provider 115 | * 116 | * @public 117 | */ 118 | export interface PrometheusAsyncOptions< 119 | T extends RegistryContentType = PrometheusContentType, 120 | > extends Pick { 121 | global?: boolean; 122 | 123 | useExisting?: Type>; 124 | useClass?: Type>; 125 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 126 | inject?: any[]; 127 | 128 | /** {@inheritDoc PrometheusOptions.controller} */ 129 | controller?: PrometheusOptions["controller"]; 130 | useFactory?( 131 | ...args: unknown[] 132 | ): Promise> | PrometheusUseFactoryOptions; 133 | } 134 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@willsoto/nestjs-prometheus", 3 | "version": "6.0.2", 4 | "description": "NestJS module for Prometheus", 5 | "repository": "git://github.com/willsoto/nestjs-prometheus.git", 6 | "license": "Apache-2.0", 7 | "author": "Will Soto (https://github.com/willsoto)", 8 | "main": "./dist/index.js", 9 | "typings": "./dist/index.d.ts", 10 | "files": [ 11 | "dist", 12 | "typings" 13 | ], 14 | "scripts": { 15 | "prebuild": "pnpm run clean", 16 | "build": "tsc --project tsconfig.build.json", 17 | "clean": "rimraf dist coverage", 18 | "lint": "eslint . --fix", 19 | "prepare": "husky", 20 | "prerelease": "pnpm run build", 21 | "release": "semantic-release", 22 | "test": "mocha", 23 | "test:coverage": "c8 mocha", 24 | "test:watch": "mocha --watch", 25 | "typecheck": "tsc --project tsconfig.lint.json --noEmit" 26 | }, 27 | "commitlint": { 28 | "extends": [ 29 | "@commitlint/config-conventional" 30 | ] 31 | }, 32 | "lint-staged": { 33 | "*.{md,yaml,yml,json}": [ 34 | "prettier --write" 35 | ], 36 | "*.{ts,js}": [ 37 | "npm run lint", 38 | "prettier --write" 39 | ], 40 | "README.md": [ 41 | "markdown-toc -i", 42 | "prettier --write" 43 | ] 44 | }, 45 | "release": { 46 | "branches": [ 47 | "main" 48 | ], 49 | "plugins": [ 50 | "@semantic-release/commit-analyzer", 51 | "@semantic-release/release-notes-generator", 52 | "@semantic-release/github", 53 | "@semantic-release/npm", 54 | "@semantic-release/changelog", 55 | "@semantic-release/git" 56 | ] 57 | }, 58 | "mocha": { 59 | "extension": [ 60 | "ts" 61 | ], 62 | "file": "./ad-hocs/mocha/plugins.ts", 63 | "recursive": true, 64 | "require": [ 65 | "ts-node/register", 66 | "./ad-hocs/mocha/hooks.ts" 67 | ], 68 | "sort": true, 69 | "watch-files": [ 70 | "src/**/*.ts", 71 | "test/**/*.ts" 72 | ] 73 | }, 74 | "c8": { 75 | "all": true, 76 | "include": [ 77 | "src/**/*.ts" 78 | ] 79 | }, 80 | "devDependencies": { 81 | "@commitlint/cli": "20.2.0", 82 | "@commitlint/config-conventional": "20.2.0", 83 | "@eslint/eslintrc": "3.3.3", 84 | "@eslint/js": "9.39.2", 85 | "@fastify/compress": "8.3.0", 86 | "@nestjs/cli": "11.0.14", 87 | "@nestjs/common": "11.1.9", 88 | "@nestjs/core": "11.1.9", 89 | "@nestjs/platform-express": "11.1.9", 90 | "@nestjs/platform-fastify": "11.1.9", 91 | "@nestjs/schematics": "11.0.9", 92 | "@nestjs/testing": "11.1.9", 93 | "@semantic-release/changelog": "6.0.3", 94 | "@semantic-release/git": "10.0.1", 95 | "@types/chai": "5.2.3", 96 | "@types/chai-as-promised": "7.1.8", 97 | "@types/eslint": "9.6.1", 98 | "@types/express": "5.0.6", 99 | "@types/express-serve-static-core": "5.1.0", 100 | "@types/mocha": "10.0.10", 101 | "@types/node": "24.10.4", 102 | "@types/sinon": "21.0.0", 103 | "@types/sinon-chai": "3.2.12", 104 | "@types/supertest": "6.0.3", 105 | "@typescript-eslint/eslint-plugin": "8.49.0", 106 | "@typescript-eslint/parser": "8.49.0", 107 | "c8": "10.1.3", 108 | "chai": "4.4.1", 109 | "chai-as-promised": "7.1.2", 110 | "eslint": "8.57.1", 111 | "eslint-config-prettier": "10.1.8", 112 | "globals": "16.5.0", 113 | "husky": "9.1.7", 114 | "lint-staged": "16.2.7", 115 | "markdown-toc": "1.2.0", 116 | "mocha": "11.7.5", 117 | "prettier": "3.7.4", 118 | "prettier-plugin-organize-imports": "4.3.0", 119 | "prettier-plugin-packagejson": "2.5.20", 120 | "prom-client": "15.1.3", 121 | "reflect-metadata": "0.2.2", 122 | "rimraf": "6.1.2", 123 | "rxjs": "7.8.2", 124 | "semantic-release": "25.0.2", 125 | "sinon": "21.0.0", 126 | "sinon-chai": "3.7.0", 127 | "standard-version": "9.5.0", 128 | "supertest": "7.1.4", 129 | "ts-node": "10.9.2", 130 | "typescript": "5.9.3" 131 | }, 132 | "peerDependencies": { 133 | "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0", 134 | "prom-client": "^15.0.0" 135 | }, 136 | "packageManager": "pnpm@10.25.0", 137 | "volta": { 138 | "node": "24.12.0", 139 | "pnpm": "10.25.0" 140 | }, 141 | "pnpm": { 142 | "peerDependencyRules": { 143 | "allowAny": [ 144 | "marked" 145 | ] 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /test/e2e.spec.ts: -------------------------------------------------------------------------------- 1 | import { NestExpressApplication } from "@nestjs/platform-express"; 2 | import { Test } from "@nestjs/testing"; 3 | import { expect } from "chai"; 4 | import { register } from "prom-client"; 5 | import * as request from "supertest"; 6 | import { CorePrefixModule } from "./fixtures/core-prefix.module"; 7 | import { CoreModule } from "./fixtures/core.module"; 8 | import { ResourceController } from "./fixtures/resource.controller"; 9 | 10 | describe("End-to-end", function () { 11 | let app: NestExpressApplication; 12 | 13 | after(async function () { 14 | register.clear(); 15 | await app.close(); 16 | }); 17 | 18 | describe("when all metrics are not prefixed", function () { 19 | before(async function () { 20 | const testingModule = await Test.createTestingModule({ 21 | imports: [CoreModule], 22 | controllers: [ResourceController], 23 | }).compile(); 24 | 25 | app = testingModule.createNestApplication(); 26 | await app.init(); 27 | }); 28 | 29 | it("should return metrics", async function () { 30 | const response = await request(app.getHttpServer()).get("/metrics"); 31 | 32 | expect(response.status).to.eql(200); 33 | 34 | expect(response.text).to.contain("counter"); 35 | expect(response.text).to.contain("gauge"); 36 | expect(response.text).to.contain("histogram"); 37 | expect(response.text).to.contain("summary"); 38 | }); 39 | 40 | it("should be able to incremement the counter", async function () { 41 | const response = await request(app.getHttpServer()).get( 42 | "/resource/counter", 43 | ); 44 | 45 | expect(response.status).to.eql(200); 46 | expect(response.text).to.eq( 47 | JSON.stringify({ 48 | help: "counter helper", 49 | name: "counter", 50 | type: "counter", 51 | values: [{ value: 1, labels: {} }], 52 | aggregator: "sum", 53 | }), 54 | ); 55 | }); 56 | 57 | it("should be able to incremement the gauge", async function () { 58 | const response = await request(app.getHttpServer()).get( 59 | "/resource/gauge", 60 | ); 61 | 62 | expect(response.status).to.eql(200); 63 | expect(response.text).to.eq( 64 | JSON.stringify({ 65 | help: "gauge helper", 66 | name: "gauge", 67 | type: "gauge", 68 | values: [{ value: 1, labels: {} }], 69 | aggregator: "sum", 70 | }), 71 | ); 72 | }); 73 | }); 74 | 75 | describe("when all metrics are prefixed", function () { 76 | before(async function () { 77 | const testingModule = await Test.createTestingModule({ 78 | imports: [CorePrefixModule], 79 | controllers: [ResourceController], 80 | }).compile(); 81 | 82 | app = testingModule.createNestApplication(); 83 | await app.init(); 84 | }); 85 | 86 | it("should return metrics", async function () { 87 | const response = await request(app.getHttpServer()).get("/metrics"); 88 | 89 | expect(response.status).to.eql(200); 90 | 91 | expect(response.text).to.contain("app_counter"); 92 | expect(response.text).to.contain("app_gauge"); 93 | expect(response.text).to.contain("app_histogram"); 94 | expect(response.text).to.contain("app_summary"); 95 | }); 96 | 97 | it("should be able to incremement the counter", async function () { 98 | const response = await request(app.getHttpServer()).get( 99 | "/resource/counter", 100 | ); 101 | 102 | expect(response.status).to.eql(200); 103 | expect(response.text).to.eq( 104 | JSON.stringify({ 105 | help: "counter helper", 106 | name: "app_counter", 107 | type: "counter", 108 | values: [{ value: 1, labels: {} }], 109 | aggregator: "sum", 110 | }), 111 | ); 112 | }); 113 | 114 | it("should be able to incremement the gauge", async function () { 115 | const response = await request(app.getHttpServer()).get( 116 | "/resource/gauge", 117 | ); 118 | 119 | expect(response.status).to.eql(200); 120 | expect(response.text).to.eq( 121 | JSON.stringify({ 122 | help: "gauge helper", 123 | name: "app_gauge", 124 | type: "gauge", 125 | values: [{ value: 1, labels: {} }], 126 | aggregator: "sum", 127 | }), 128 | ); 129 | }); 130 | }); 131 | }); 132 | -------------------------------------------------------------------------------- /src/module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DynamicModule, 3 | FactoryProvider, 4 | Module, 5 | Provider, 6 | } from "@nestjs/common"; 7 | import * as promClient from "prom-client"; 8 | import { RegistryContentType } from "prom-client"; 9 | import { PROMETHEUS_OPTIONS, PROM_CLIENT } from "./constants"; 10 | import { PrometheusController } from "./controller"; 11 | import { 12 | PrometheusAsyncOptions, 13 | PrometheusOptions, 14 | PrometheusOptionsFactory, 15 | PrometheusOptionsWithDefaults, 16 | } from "./interfaces"; 17 | 18 | /** 19 | * The primary entrypoint. This should be registered once in the root application module. 20 | * 21 | * @public 22 | */ 23 | @Module({}) 24 | export class PrometheusModule { 25 | public static register( 26 | options?: PrometheusOptions, 27 | ): DynamicModule { 28 | const opts = PrometheusModule.makeDefaultOptions(options); 29 | 30 | PrometheusModule.configureServer(opts); 31 | 32 | const providers: Provider[] = [ 33 | { 34 | provide: PROMETHEUS_OPTIONS, 35 | useValue: options, 36 | }, 37 | ]; 38 | if (options?.pushgateway !== undefined) { 39 | const { url, options: gatewayOptions, registry } = options.pushgateway; 40 | providers.push({ 41 | provide: promClient.Pushgateway, 42 | useValue: PrometheusModule.configurePushgateway( 43 | url, 44 | gatewayOptions, 45 | registry, 46 | ), 47 | }); 48 | } 49 | 50 | return { 51 | module: PrometheusModule, 52 | global: opts.global, 53 | providers, 54 | controllers: [opts.controller], 55 | exports: providers, 56 | }; 57 | } 58 | 59 | public static registerAsync( 60 | options: PrometheusAsyncOptions, 61 | ): DynamicModule { 62 | const providers = this.createAsyncProviders(options); 63 | const controller = options.controller ?? PrometheusController; 64 | 65 | return { 66 | module: PrometheusModule, 67 | global: options.global, 68 | controllers: [controller], 69 | imports: options.imports, 70 | providers: [ 71 | ...providers, 72 | { 73 | provide: PROM_CLIENT, 74 | inject: [PROMETHEUS_OPTIONS], 75 | useFactory( 76 | userOptions: PrometheusOptions, 77 | ) { 78 | const opts = PrometheusModule.makeDefaultOptions(userOptions); 79 | 80 | PrometheusModule.configureServer(opts); 81 | 82 | return promClient; 83 | }, 84 | }, 85 | ], 86 | exports: [...providers], 87 | }; 88 | } 89 | 90 | public static createAsyncProviders( 91 | options: PrometheusAsyncOptions, 92 | ): Provider[] { 93 | if (options.useExisting || options.useFactory) { 94 | return [ 95 | this.createAsyncOptionsProvider(options), 96 | PrometheusModule.createPushgatewayProvider(), 97 | ]; 98 | } else if (!options.useClass) { 99 | throw new Error( 100 | "Invalid configuration. Must provide useClass or useExisting", 101 | ); 102 | } 103 | 104 | return [ 105 | this.createAsyncOptionsProvider(options), 106 | { 107 | provide: options.useClass, 108 | useClass: options.useClass, 109 | }, 110 | PrometheusModule.createPushgatewayProvider(), 111 | ]; 112 | } 113 | 114 | public static createAsyncOptionsProvider( 115 | options: PrometheusAsyncOptions, 116 | ): Provider { 117 | if (options.useFactory) { 118 | return { 119 | provide: PROMETHEUS_OPTIONS, 120 | // eslint-disable-next-line @typescript-eslint/unbound-method 121 | useFactory: options.useFactory, 122 | inject: options.inject || [], 123 | }; 124 | } 125 | 126 | const inject = options.useClass || options.useExisting; 127 | 128 | if (!inject) { 129 | throw new Error( 130 | "Invalid configuration. Must provide useClass or useExisting", 131 | ); 132 | } 133 | 134 | return { 135 | provide: PROMETHEUS_OPTIONS, 136 | async useFactory( 137 | optionsFactory: PrometheusOptionsFactory, 138 | ): Promise> { 139 | return optionsFactory.createPrometheusOptions(); 140 | }, 141 | inject: [inject], 142 | }; 143 | } 144 | 145 | private static configureServer( 146 | options: PrometheusOptionsWithDefaults, 147 | ): void { 148 | if (options.defaultMetrics.enabled) { 149 | promClient.collectDefaultMetrics(options.defaultMetrics.config); 150 | } 151 | 152 | if (Object.keys(options.defaultLabels).length > 0) { 153 | promClient.register.setDefaultLabels(options.defaultLabels); 154 | } 155 | 156 | Reflect.defineMetadata("path", options.path, options.controller); 157 | } 158 | 159 | private static configurePushgateway( 160 | url: string, 161 | options?: unknown, 162 | registry?: promClient.Registry, 163 | ): promClient.Pushgateway { 164 | return new promClient.Pushgateway(url, options, registry); 165 | } 166 | 167 | private static createPushgatewayProvider(): FactoryProvider { 168 | return { 169 | provide: promClient.Pushgateway, 170 | inject: [PROMETHEUS_OPTIONS], 171 | useFactory(options: PrometheusOptions) { 172 | if (options?.pushgateway !== undefined) { 173 | const { 174 | url, 175 | options: gatewayOptions, 176 | registry, 177 | } = options.pushgateway; 178 | 179 | return PrometheusModule.configurePushgateway( 180 | url, 181 | gatewayOptions, 182 | registry, 183 | ); 184 | } 185 | 186 | return null; 187 | }, 188 | }; 189 | } 190 | 191 | private static makeDefaultOptions( 192 | options?: PrometheusOptions, 193 | ): PrometheusOptionsWithDefaults { 194 | return { 195 | global: false, 196 | path: "/metrics", 197 | defaultMetrics: { 198 | enabled: true, 199 | config: {}, 200 | }, 201 | controller: PrometheusController, 202 | defaultLabels: {}, 203 | ...options, 204 | }; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /test/module.spec.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Module } from "@nestjs/common"; 2 | import { TestingModule } from "@nestjs/testing"; 3 | import { expect } from "chai"; 4 | import { Pushgateway, register } from "prom-client"; 5 | import { 6 | PrometheusModule, 7 | PrometheusOptions, 8 | PrometheusOptionsFactory, 9 | } from "../src"; 10 | import { 11 | Agent, 12 | App, 13 | createAsyncPrometheusModule, 14 | createPrometheusModule, 15 | } from "./utils"; 16 | 17 | describe("PrometheusModule", function () { 18 | let agent: Agent; 19 | let app: App; 20 | let testingModule: TestingModule; 21 | 22 | afterEach(async function () { 23 | register.clear(); 24 | 25 | if (app) { 26 | await app.close(); 27 | } 28 | 29 | if (testingModule) { 30 | await testingModule.close(); 31 | } 32 | }); 33 | 34 | describe("#register", function () { 35 | describe("with all defaults", function () { 36 | beforeEach(async function () { 37 | ({ agent, app } = await createPrometheusModule()); 38 | }); 39 | 40 | it("registers a /metrics endpoint", async function () { 41 | const response = await agent.get("/metrics"); 42 | 43 | expect(response).to.have.property("status").to.eql(200); 44 | }); 45 | 46 | it("collects default metrics", async function () { 47 | const response = await agent.get("/metrics"); 48 | 49 | expect(response) 50 | .to.have.property("text") 51 | .to.contain("process_cpu_user_seconds_total"); 52 | }); 53 | }); 54 | 55 | describe("when overriding the default path", function () { 56 | beforeEach(async function () { 57 | ({ agent, app } = await createPrometheusModule({ 58 | path: "/my-custom-endpoint", 59 | })); 60 | }); 61 | 62 | it("does not register the default endpoint", async function () { 63 | const response = await agent.get("/metrics"); 64 | 65 | expect(response).to.have.property("status").to.eql(404); 66 | }); 67 | 68 | it("registers the custom endpoint", async function () { 69 | const response = await agent.get("/my-custom-endpoint"); 70 | 71 | expect(response).to.have.property("status").to.eql(200); 72 | }); 73 | 74 | it("collects default metrics", async function () { 75 | const response = await agent.get("/my-custom-endpoint"); 76 | 77 | expect(response) 78 | .to.have.property("text") 79 | .to.contain("process_cpu_user_seconds_total"); 80 | }); 81 | }); 82 | }); 83 | 84 | describe("#registerAsync", function () { 85 | @Injectable() 86 | class OptionsService implements PrometheusOptionsFactory { 87 | createPrometheusOptions() { 88 | return {}; 89 | } 90 | } 91 | 92 | @Module({ 93 | providers: [OptionsService], 94 | exports: [OptionsService], 95 | }) 96 | class OptionsModule {} 97 | 98 | describe("useExisting", function () { 99 | beforeEach(async function () { 100 | ({ agent, app } = await createAsyncPrometheusModule({ 101 | imports: [OptionsModule], 102 | useExisting: OptionsService, 103 | inject: [OptionsService], 104 | })); 105 | }); 106 | 107 | it("registers a /metrics endpoint", async function () { 108 | const response = await agent.get("/metrics"); 109 | 110 | expect(response).to.have.property("status").to.eql(200); 111 | expect(response) 112 | .to.have.property("text") 113 | .to.contain("process_cpu_user_seconds_total"); 114 | }); 115 | }); 116 | 117 | describe("useClass", function () { 118 | beforeEach(async function () { 119 | ({ agent, app } = await createAsyncPrometheusModule({ 120 | useClass: OptionsService, 121 | inject: [OptionsService], 122 | })); 123 | }); 124 | 125 | it("registers a /metrics endpoint", async function () { 126 | const response = await agent.get("/metrics"); 127 | 128 | expect(response).to.have.property("status").to.eql(200); 129 | expect(response) 130 | .to.have.property("text") 131 | .to.contain("process_cpu_user_seconds_total"); 132 | }); 133 | }); 134 | 135 | describe("useFactory", function () { 136 | @Injectable() 137 | class MyConfigService { 138 | options(): PrometheusOptions { 139 | return { 140 | path: "/my/custom/path/metrics", 141 | pushgateway: { 142 | url: "http://127.0.0.1:9091", 143 | }, 144 | }; 145 | } 146 | } 147 | 148 | @Module({ 149 | providers: [MyConfigService], 150 | exports: [MyConfigService], 151 | }) 152 | class MyConfigModule {} 153 | 154 | beforeEach(async function () { 155 | ({ agent, app, testingModule } = await createAsyncPrometheusModule({ 156 | imports: [MyConfigModule], 157 | inject: [MyConfigService], 158 | useFactory(config: MyConfigService) { 159 | return config.options(); 160 | }, 161 | })); 162 | }); 163 | 164 | it("registers a custom endpoint", async function () { 165 | const response = await agent.get("/my/custom/path/metrics"); 166 | 167 | expect(response).to.have.property("status").to.eql(200); 168 | expect(response) 169 | .to.have.property("text") 170 | .to.contain("process_cpu_user_seconds_total"); 171 | }); 172 | 173 | it("should register the push gateway", function () { 174 | const gateway = testingModule.get(Pushgateway); 175 | 176 | expect(gateway).to.be.instanceOf(Pushgateway); 177 | expect(gateway).to.have.property("gatewayUrl", "http://127.0.0.1:9091"); 178 | }); 179 | }); 180 | }); 181 | 182 | describe("#createAsyncOptionsProvider", function () { 183 | it("throws an error if useClass or useExisting are not provided", function () { 184 | expect(() => { 185 | PrometheusModule.createAsyncProviders({}); 186 | }).to.throw( 187 | "Invalid configuration. Must provide useClass or useExisting", 188 | ); 189 | }); 190 | }); 191 | 192 | describe("#createAsyncOptionsProvider", function () { 193 | it("throws an error if useClass or useExisting are not provided", function () { 194 | expect(() => { 195 | PrometheusModule.createAsyncOptionsProvider({}); 196 | }).to.throw( 197 | "Invalid configuration. Must provide useClass or useExisting", 198 | ); 199 | }); 200 | }); 201 | }); 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NestJS Prometheus 2 | 3 | ![](https://github.com/willsoto/nestjs-prometheus/workflows/tests/badge.svg) 4 | 5 | 6 | 7 | - [Installation](#installation) 8 | - [Usage](#usage) 9 | - [Changing the metrics http endpoint](#changing-the-metrics-http-endpoint) 10 | - [Disabling default metrics collection](#disabling-default-metrics-collection) 11 | - [Configuring the default metrics](#configuring-the-default-metrics) 12 | - [Injecting individual metrics](#injecting-individual-metrics) 13 | - [Setting default labels](#setting-default-labels) 14 | - [Prefixing custom metrics](#prefixing-custom-metrics) 15 | - [Option 1 (recommended)](#option-1-recommended) 16 | - [Option 2 (not recommended)](#option-2-not-recommended) 17 | - [Available metrics](#available-metrics) 18 | - [Counter](#counter) 19 | - [Gauge](#gauge) 20 | - [Histogram](#histogram) 21 | - [Summary](#summary) 22 | - [Providing a custom controller](#providing-a-custom-controller) 23 | - [Pushgateway](#pushgateway) 24 | 25 | 26 | 27 | ## Installation 28 | 29 | ```bash 30 | yarn add @willsoto/nestjs-prometheus prom-client 31 | ``` 32 | 33 | ```bash 34 | npm install @willsoto/nestjs-prometheus prom-client 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```typescript 40 | import { Module } from "@nestjs/common"; 41 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 42 | 43 | @Module({ 44 | imports: [PrometheusModule.register()], 45 | }) 46 | export class AppModule {} 47 | ``` 48 | 49 | By default, this will register a `/metrics` endpoint that will return the [default metrics](https://github.com/siimon/prom-client#default-metrics). 50 | 51 | ### Changing the metrics http endpoint 52 | 53 | ```typescript 54 | import { Module } from "@nestjs/common"; 55 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 56 | 57 | @Module({ 58 | imports: [ 59 | PrometheusModule.register({ 60 | path: "/mymetrics", 61 | }), 62 | ], 63 | }) 64 | export class AppModule {} 65 | ``` 66 | 67 | ### Disabling default metrics collection 68 | 69 | ```typescript 70 | import { Module } from "@nestjs/common"; 71 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 72 | 73 | @Module({ 74 | imports: [ 75 | PrometheusModule.register({ 76 | defaultMetrics: { 77 | enabled: false, 78 | }, 79 | }), 80 | ], 81 | }) 82 | export class AppModule {} 83 | ``` 84 | 85 | ### Configuring the default metrics 86 | 87 | ```typescript 88 | import { Module } from "@nestjs/common"; 89 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 90 | 91 | @Module({ 92 | imports: [ 93 | PrometheusModule.register({ 94 | defaultMetrics: { 95 | // See https://github.com/siimon/prom-client#configuration 96 | config: {}, 97 | }, 98 | }), 99 | ], 100 | }) 101 | export class AppModule {} 102 | ``` 103 | 104 | ## Injecting individual metrics 105 | 106 | ```typescript 107 | // module.ts 108 | import { Module } from "@nestjs/common"; 109 | import { 110 | PrometheusModule, 111 | makeCounterProvider, 112 | } from "@willsoto/nestjs-prometheus"; 113 | import { Service } from "./service"; 114 | 115 | @Module({ 116 | imports: [PrometheusModule.register()], 117 | providers: [ 118 | Service, 119 | makeCounterProvider({ 120 | name: "metric_name", 121 | help: "metric_help", 122 | }), 123 | ], 124 | }) 125 | export class AppModule {} 126 | ``` 127 | 128 | ```typescript 129 | // service.ts 130 | import { Injectable } from "@nestjs/common"; 131 | import { InjectMetric } from "@willsoto/nestjs-prometheus"; 132 | import { Counter } from "prom-client"; 133 | 134 | @Injectable() 135 | export class Service { 136 | constructor(@InjectMetric("metric_name") public counter: Counter) {} 137 | } 138 | ``` 139 | 140 | ## Setting default labels 141 | 142 | ```typescript 143 | import { Module } from "@nestjs/common"; 144 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 145 | 146 | @Module({ 147 | imports: [ 148 | PrometheusModule.register({ 149 | defaultLabels: { 150 | app: "My app", 151 | }, 152 | }), 153 | ], 154 | }) 155 | export class AppModule {} 156 | ``` 157 | 158 | See the [docs](https://github.com/siimon/prom-client#default-labels-segmented-by-registry) for more information. 159 | 160 | ## Prefixing custom metrics 161 | 162 | You can add a custom prefix to all custom metrics by providing the `customMetricPrefix` option to the module configuration. 163 | 164 | Some caveats: 165 | 166 | In order to have the custom metrics registered in different modules from where the `PrometheusModule` was registered, you must do one of a few things: 167 | 168 | ### Option 1 (recommended) 169 | 170 | 1. Add the `PrometheusModule` to the `exports` of the registering `Module`. It may be useful to create a `CommonModule` that registers and exports the `PrometheusModule`. 171 | 2. Import that module into whatever module you are creating the custom metrics. 172 | 173 | ### Option 2 (not recommended) 174 | 175 | 1. Mark the `PrometheusModule` as `global` 176 | 177 | ## Available metrics 178 | 179 | 180 | 181 | #### [Counter](https://github.com/siimon/prom-client#counter) 182 | 183 | ```typescript 184 | import { makeCounterProvider } from "@willsoto/nestjs-prometheus"; 185 | ``` 186 | 187 | #### [Gauge](https://github.com/siimon/prom-client#gauge) 188 | 189 | ```typescript 190 | import { makeGaugeProvider } from "@willsoto/nestjs-prometheus"; 191 | ``` 192 | 193 | #### [Histogram](https://github.com/siimon/prom-client#histogram) 194 | 195 | ```typescript 196 | import { makeHistogramProvider } from "@willsoto/nestjs-prometheus"; 197 | ``` 198 | 199 | #### [Summary](https://github.com/siimon/prom-client#summary) 200 | 201 | ```typescript 202 | import { makeSummaryProvider } from "@willsoto/nestjs-prometheus"; 203 | ``` 204 | 205 | 206 | ## Providing a custom controller 207 | 208 | If you need to implement any special logic or have access to the controller (e.g., to customize [Swagger](https://docs.nestjs.com/openapi/introduction)), 209 | you can provide your own controller (or subclass) of the default controller. 210 | 211 | Here is a basic example which should be enough to extend or customize in any way you might need. 212 | 213 | ```typescript 214 | // my-custom-controller.ts 215 | import { Controller, Get, Res } from "@nestjs/common"; 216 | import { PrometheusController } from "@willsoto/nestjs-prometheus"; 217 | import { Response } from "express"; 218 | 219 | @Controller() 220 | class MyCustomController extends PrometheusController { 221 | @Get() 222 | async index(@Res({ passthrough: true }) response: Response) { 223 | return super.index(response); 224 | } 225 | } 226 | ``` 227 | 228 | ```typescript 229 | import { Module } from "@nestjs/common"; 230 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 231 | import { MyCustomController } from "./my-custom-controller"; 232 | 233 | @Module({ 234 | imports: [ 235 | PrometheusModule.register({ 236 | controller: MyCustomController, 237 | }), 238 | ], 239 | }) 240 | export class AppModule {} 241 | ``` 242 | 243 | ## Pushgateway 244 | 245 | In order to enable Pushgateway for injection, provide the configuration under the `pushgateway` key. 246 | 247 | ```typescript 248 | import { Module } from "@nestjs/common"; 249 | import { PrometheusModule } from "@willsoto/nestjs-prometheus"; 250 | 251 | @Module({ 252 | imports: [ 253 | PrometheusModule.register({ 254 | pushgateway: { 255 | url: "http://127.0.0.1:9091", 256 | }, 257 | }), 258 | ], 259 | }) 260 | export class AppModule {} 261 | ``` 262 | 263 | ```typescript 264 | import { Injectable } from "@nestjs/common"; 265 | import * as client from "prom-client"; 266 | 267 | @Injectable() 268 | export class Service { 269 | constructor(private readonly pushgateway: client.Pushgateway) {} 270 | } 271 | ``` 272 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [6.0.2](https://github.com/willsoto/nestjs-prometheus/compare/v6.0.1...v6.0.2) (2025-01-17) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * allow nestjs 11 ([45a0ddf](https://github.com/willsoto/nestjs-prometheus/commit/45a0ddffda84f6974837b2b6cfb6598e701c6da4)) 7 | 8 | ## [6.0.1](https://github.com/willsoto/nestjs-prometheus/compare/v6.0.0...v6.0.1) (2024-06-06) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * don't allow controller to be declared on options ([6924ffa](https://github.com/willsoto/nestjs-prometheus/commit/6924ffa79f3bac84255263659c7d1c253fc9dfa2)), closes [#2279](https://github.com/willsoto/nestjs-prometheus/issues/2279) 14 | 15 | # [6.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.5.1...v6.0.0) (2023-10-10) 16 | 17 | 18 | ### Features 19 | 20 | * support prom-client v15 ([cd62351](https://github.com/willsoto/nestjs-prometheus/commit/cd62351247255121b3f690f1c4072ac2dbddab8a)) 21 | 22 | 23 | ### BREAKING CHANGES 24 | 25 | * dropped support for clients less than v15 26 | 27 | Signed-off-by: Will Soto 28 | 29 | ## [5.5.1](https://github.com/willsoto/nestjs-prometheus/compare/v5.5.0...v5.5.1) (2023-09-23) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * **metrics:** mark PROMETHEUS_OPTIONS as optional ([ba6b75b](https://github.com/willsoto/nestjs-prometheus/commit/ba6b75b2d2fa43cb154ff11cd3576f6c68b34001)), closes [#1900](https://github.com/willsoto/nestjs-prometheus/issues/1900) 35 | 36 | # [5.5.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.4.0...v5.5.0) (2023-09-15) 37 | 38 | 39 | ### Features 40 | 41 | * allow the module to be registered as global ([113c02a](https://github.com/willsoto/nestjs-prometheus/commit/113c02abd155a4b91d7ab9367b3158dcda3604a3)) 42 | 43 | # [5.4.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.3.0...v5.4.0) (2023-09-10) 44 | 45 | 46 | ### Features 47 | 48 | * add prefix to all injected metrics ([2375e42](https://github.com/willsoto/nestjs-prometheus/commit/2375e42c4b40203e9d09917ce6dd91390bb913b8)) 49 | 50 | # [5.3.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.2.1...v5.3.0) (2023-08-12) 51 | 52 | 53 | ### Features 54 | 55 | * support useFactory ([b4608da](https://github.com/willsoto/nestjs-prometheus/commit/b4608da57f70b3ce2ce765caf769de71a6376c18)), closes [#1776](https://github.com/willsoto/nestjs-prometheus/issues/1776) 56 | 57 | ## [5.2.1](https://github.com/willsoto/nestjs-prometheus/compare/v5.2.0...v5.2.1) (2023-07-14) 58 | 59 | 60 | ### Bug Fixes 61 | 62 | * pushgateway injection ([#1810](https://github.com/willsoto/nestjs-prometheus/issues/1810)) ([64cc5ae](https://github.com/willsoto/nestjs-prometheus/commit/64cc5aef8106aceaa4bdf16775cdff25ad404afc)), closes [#1780](https://github.com/willsoto/nestjs-prometheus/issues/1780) [#1809](https://github.com/willsoto/nestjs-prometheus/issues/1809) 63 | 64 | # [5.2.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.1.2...v5.2.0) (2023-06-18) 65 | 66 | 67 | ### Features 68 | 69 | * remove explicit types from InjectMetric ([2b6f32f](https://github.com/willsoto/nestjs-prometheus/commit/2b6f32fe9b61e0a2002f8c767a32ce4e8f6ca81b)), closes [#1770](https://github.com/willsoto/nestjs-prometheus/issues/1770) 70 | 71 | ## [5.1.2](https://github.com/willsoto/nestjs-prometheus/compare/v5.1.1...v5.1.2) (2023-05-22) 72 | 73 | 74 | ### Bug Fixes 75 | 76 | * add passthrough: true to make custom controllers work again with v5 ([#1739](https://github.com/willsoto/nestjs-prometheus/issues/1739)) ([5e83125](https://github.com/willsoto/nestjs-prometheus/commit/5e83125e30286bb3a61eb10a03d5d311f57c5d57)) 77 | 78 | ## [5.1.1](https://github.com/willsoto/nestjs-prometheus/compare/v5.1.0...v5.1.1) (2023-04-07) 79 | 80 | 81 | ### Bug Fixes 82 | 83 | * decorator types ([#1685](https://github.com/willsoto/nestjs-prometheus/issues/1685)) ([6f8a52e](https://github.com/willsoto/nestjs-prometheus/commit/6f8a52eed0efe1e0af1e1c764e32ee67b22e0f67)), closes [#1667](https://github.com/willsoto/nestjs-prometheus/issues/1667) 84 | 85 | # [5.1.0](https://github.com/willsoto/nestjs-prometheus/compare/v5.0.0...v5.1.0) (2023-01-08) 86 | 87 | 88 | ### Features 89 | 90 | * **pushgateway:** add support for Pushgateway ([f797636](https://github.com/willsoto/nestjs-prometheus/commit/f7976360436d3c02ccafe1590ab7ddc23f633bfe)), closes [#1628](https://github.com/willsoto/nestjs-prometheus/issues/1628) 91 | 92 | # [5.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.7.0...v5.0.0) (2022-12-19) 93 | 94 | 95 | ### Bug Fixes 96 | 97 | * **controller:** removes response.send from route handler ([#1622](https://github.com/willsoto/nestjs-prometheus/issues/1622)) ([bfa6c70](https://github.com/willsoto/nestjs-prometheus/commit/bfa6c7095368bd463e3fdf32f9cc7560c58a682a)) 98 | 99 | 100 | ### BREAKING CHANGES 101 | 102 | * **controller:** For users that have a custom subclass, you will need to adjust the method to `return super.index(response);` as the base class no longer sends a response. 103 | 104 | # [4.7.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.6.0...v4.7.0) (2022-07-10) 105 | 106 | 107 | ### Features 108 | 109 | * **nestjs:** support v9 ([5bb4711](https://github.com/willsoto/nestjs-prometheus/commit/5bb4711957b4d347732314ed38e115f429b829f7)), closes [#1475](https://github.com/willsoto/nestjs-prometheus/issues/1475) 110 | 111 | # [4.6.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.5.0...v4.6.0) (2022-03-09) 112 | 113 | 114 | ### Features 115 | 116 | * ability to set defaultLabels ([7fd289a](https://github.com/willsoto/nestjs-prometheus/commit/7fd289abd35f13a3ddd802e4c519d43210808858)), closes [#1209](https://github.com/willsoto/nestjs-prometheus/issues/1209) 117 | * upgrade packages ([79a67f1](https://github.com/willsoto/nestjs-prometheus/commit/79a67f1508a155c1ee8684d7ea6cd2625265ac9f)) 118 | 119 | # [4.5.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.4.0...v4.5.0) (2022-02-28) 120 | 121 | 122 | ### Features 123 | 124 | * upgrade packages ([662ec6c](https://github.com/willsoto/nestjs-prometheus/commit/662ec6c2245816ab9f7ba69d101f406a815d94c3)) 125 | 126 | # [4.4.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.3.0...v4.4.0) (2021-11-30) 127 | 128 | 129 | ### Features 130 | 131 | * add node-tests reusable workflow ([efd3c89](https://github.com/willsoto/nestjs-prometheus/commit/efd3c89f3ad9b5462b84ecd20c2106d766c083e9)) 132 | 133 | # [4.3.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.2.0...v4.3.0) (2021-11-28) 134 | 135 | 136 | ### Features 137 | 138 | * upgrade packages ([6ab5a68](https://github.com/willsoto/nestjs-prometheus/commit/6ab5a684b73d54c137a0f39f998b7936a03609ac)) 139 | 140 | # [4.2.0](https://github.com/willsoto/nestjs-prometheus/compare/v4.1.0...v4.2.0) (2021-10-30) 141 | 142 | 143 | ### Features 144 | 145 | * **releases:** add changelog to releases ([bc95220](https://github.com/willsoto/nestjs-prometheus/commit/bc9522007058c74a11ce727f48e85ba7202a0e8e)) 146 | 147 | # Changelog 148 | 149 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 150 | 151 | ## [4.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v2.0.1...v4.0.0) (2021-07-15) 152 | 153 | 154 | ### ⚠ BREAKING CHANGES 155 | 156 | * many methods are now async due to upstream changes 157 | * esModuleInterop has been disabled due to #671 158 | 159 | ### Features 160 | 161 | * upgrade to prom-client v13 ([cb04088](https://github.com/willsoto/nestjs-prometheus/commit/cb04088c5780ab2cf851aed19945ddcc8832f2df)), closes [#671](https://github.com/willsoto/nestjs-prometheus/issues/671) 162 | 163 | ## [3.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v2.0.1...v3.0.0) (2020-12-23) 164 | 165 | 166 | ### ⚠ BREAKING CHANGES 167 | 168 | * many methods are now async due to upstream changes 169 | * esModuleInterop has been disabled due to #671 170 | 171 | ### Features 172 | 173 | * upgrade to prom-client v13 ([cb04088](https://github.com/willsoto/nestjs-prometheus/commit/cb04088c5780ab2cf851aed19945ddcc8832f2df)), closes [#671](https://github.com/willsoto/nestjs-prometheus/issues/671) 174 | 175 | ### [2.0.1](https://github.com/willsoto/nestjs-prometheus/compare/v2.0.0...v2.0.1) (2020-11-07) 176 | 177 | 178 | ### Bug Fixes 179 | 180 | * **controller:** don't include Express types ([e4a022c](https://github.com/willsoto/nestjs-prometheus/commit/e4a022cde8e0e9aae84ec2be098442217f9f8849)), closes [#530](https://github.com/willsoto/nestjs-prometheus/issues/530) 181 | 182 | ## [2.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v1.1.0...v2.0.0) (2020-10-09) 183 | 184 | 185 | ### ⚠ BREAKING CHANGES 186 | 187 | * shouldn't affect anybody, but if people relied on there being an ESM version 188 | it is gone now 189 | 190 | Signed-off-by: Will Soto 191 | 192 | ### Bug Fixes 193 | 194 | * remove esm version ([a6c7545](https://github.com/willsoto/nestjs-prometheus/commit/a6c7545df30cac94c7fea2ff434093cf929ff57b)) 195 | 196 | ## [1.1.0](https://github.com/willsoto/nestjs-prometheus/compare/v1.0.0...v1.1.0) (2020-10-09) 197 | 198 | 199 | ### Features 200 | 201 | * add support for custom controllers ([92b1f8a](https://github.com/willsoto/nestjs-prometheus/commit/92b1f8a087332978ad09bbd624a9953fa9056ad0)), closes [#507](https://github.com/willsoto/nestjs-prometheus/issues/507) 202 | 203 | ## [1.0.0](https://github.com/willsoto/nestjs-prometheus/compare/v0.1.3...v1.0.0) (2020-10-06) 204 | 205 | ### [0.1.3](https://github.com/willsoto/nestjs-prometheus/compare/v0.1.2...v0.1.3) (2020-08-25) 206 | 207 | 208 | ### Features 209 | 210 | * add support for fastify ([0ff55d9](https://github.com/willsoto/nestjs-prometheus/commit/0ff55d9d1b8e06e98d31027c7b2d30521976bcc9)) 211 | 212 | ### [0.1.2](https://github.com/willsoto/nestjs-prometheus/compare/v0.1.1...v0.1.2) (2020-08-13) 213 | 214 | ### [0.1.1](https://github.com/willsoto/nestjs-prometheus/compare/v0.1.0...v0.1.1) (2020-03-07) 215 | 216 | ## [0.1.0](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.7...v0.1.0) (2020-02-22) 217 | 218 | 219 | ### ⚠ BREAKING CHANGES 220 | 221 | * prom-client breaking changes 222 | include changes to types, so this is a major version to be safe. 223 | See https://github.com/siimon/prom-client/releases/tag/v12.0.0 224 | 225 | Signed-off-by: Will Soto 226 | 227 | ### Features 228 | 229 | * upgrade prom-client to v12 ([75709d3](https://github.com/willsoto/nestjs-prometheus/commit/75709d3f634af0e4ae869ba548e5213316bedf39)) 230 | 231 | ### [0.0.7](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.6...v0.0.7) (2020-01-13) 232 | 233 | ### [0.0.6](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.5...v0.0.6) (2019-11-27) 234 | 235 | 236 | ### Bug Fixes 237 | 238 | * **workflows/publish:** publish is not a script ([be01dfb](https://github.com/willsoto/nestjs-prometheus/commit/be01dfbcf2cbb29d982a045f75611cd5a19be21b)) 239 | 240 | ### [0.0.5](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.4...v0.0.5) (2019-11-27) 241 | 242 | 243 | ### Bug Fixes 244 | 245 | * **workflows/publish:** remove login step ([7c27bc9](https://github.com/willsoto/nestjs-prometheus/commit/7c27bc99975ef38e8de1f2090d6f04ff41cea725)) 246 | 247 | ### [0.0.4](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.3...v0.0.4) (2019-11-27) 248 | 249 | ### Bug Fixes 250 | 251 | - **workflows/publish:** remove scope ([9eb3295](https://github.com/willsoto/nestjs-prometheus/commit/9eb32958101bd2e530999c41ab2a28e86672cfd6)) 252 | 253 | ### [0.0.3](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.2...v0.0.3) (2019-11-27) 254 | 255 | ### Bug Fixes 256 | 257 | - **workflows:** interpolate github.ref ([a85aede](https://github.com/willsoto/nestjs-prometheus/commit/a85aede98e7900ddf7dcfc0d8daf65e1a435bd8d)) 258 | - **workflows/publish:** login to the correct scope ([9854da3](https://github.com/willsoto/nestjs-prometheus/commit/9854da37c6556d12c93010c0ba77bec9773b3271)) 259 | 260 | ### [0.0.2](https://github.com/willsoto/nestjs-prometheus/compare/v0.0.1...v0.0.2) (2019-11-26) 261 | 262 | ### 0.0.1 (2019-11-26) 263 | 264 | ### Features 265 | 266 | - add publish workflow ([ba6cba2](https://github.com/willsoto/nestjs-prometheus/commit/ba6cba29d7ef9c1937a27fde3611e843ac4884cc)) 267 | - **all:** initial commit ([a895bfd](https://github.com/willsoto/nestjs-prometheus/commit/a895bfda96bfd8de3dd021ad1c06116bea76648e)) 268 | - **module:** add support for registerAsync ([036d776](https://github.com/willsoto/nestjs-prometheus/commit/036d776603b78ad1a9d60a32a040d9957bbb4cc3)) 269 | 270 | ### Bug Fixes 271 | 272 | - **docs:** switch to using deploy keys ([8c0b22c](https://github.com/willsoto/nestjs-prometheus/commit/8c0b22c55a3f3aff9cfc5cd0a2080da49a34a53d)) 273 | --------------------------------------------------------------------------------