Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adonis5-prometheus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis5-prometheus - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

3

build/src/CollectPerformanceMetrics.d.ts

@@ -8,3 +8,4 @@ /// <reference types="@adonisjs/http-server/build/adonis-typings" />

constructor(metrics: Metrics, config: any);
handle({ request, response }: HttpContextContract, next: () => Promise<void>): Promise<void>;
handle({ request, response, route }: HttpContextContract, next: () => Promise<void>): Promise<void>;
private afterRequest;
}

@@ -9,19 +9,42 @@ "use strict";

}
async handle({ request, response }, next) {
const { enabled: enableHttpMetric } = this.config.httpMetric;
const enableThroughputMetric = this.config.throughputMetric.enabled;
async handle({ request, response, route }, next) {
const httpMetricOptions = this.config.httpMetric;
/**
* Start HTTP request timer.
* Start HTTP request timer ( if route not excluded ) with the
* given options for url parsing.
* The timer will be stopped when the request is finished.
*/
let stopHttpRequestTimer;
if (enableHttpMetric) {
stopHttpRequestTimer = this.metrics.httpMetric.startTimer({
method: request.method(),
url: request.url(),
});
if (httpMetricOptions.enabled) {
const includeRouteParams = httpMetricOptions.includeRouteParams;
const includeQueryParams = httpMetricOptions.includeQueryParams;
const excludedRoutes = httpMetricOptions.excludedRoutes || [];
if (!excludedRoutes.includes(route?.pattern)) {
let url = includeRouteParams ? request.url() : route?.pattern;
if (includeQueryParams && request.parsedUrl.query) {
url += `?${request.parsedUrl.query}`;
}
stopHttpRequestTimer = this.metrics.httpMetric.startTimer({
method: request.method(),
url,
});
}
}
/**
* Continue execution.
* Execute request and track metrics for the request.
* If the request fails with any error, we have to catch
* this errror, track metricks, then rethrow the error.
*/
await next();
try {
await next();
this.afterRequest(response.response.statusCode, stopHttpRequestTimer);
}
catch (err) {
this.afterRequest(err.status || 500, stopHttpRequestTimer);
throw err;
}
}
async afterRequest(statusCode, stopHttpRequestTimer) {
const enableThroughputMetric = this.config.throughputMetric.enabled;
const httpMetricOptions = this.config.httpMetric;
/**

@@ -35,6 +58,8 @@ * Track request throughput..

*/
if (enableHttpMetric) {
stopHttpRequestTimer({
statusCode: response.response.statusCode,
});
if (httpMetricOptions.enabled && stopHttpRequestTimer) {
let statusCodeStr = statusCode.toString();
if (httpMetricOptions.shouldGroupStatusCode) {
statusCodeStr = statusCodeStr[0] + 'xx';
}
stopHttpRequestTimer({ statusCode: statusCodeStr });
}

@@ -41,0 +66,0 @@ }

@@ -1,2 +0,2 @@

export default {
const prometheusConfig {
/*

@@ -38,3 +38,5 @@ |--------------------------------------------------------------------------

name: 'adonis_http_request_durations',
includeQueryParams: true,
includeQueryParams: false,
includeRouteParams: false,
shouldGroupStatusCode: true,
help: 'Total time each HTTP request takes.',

@@ -44,2 +46,3 @@ labelNames: ['method', 'url', 'statusCode'],

prefix: '',
excludedRoutes: ["/metrics", "/health"],
},

@@ -75,1 +78,3 @@

}
export default prometheusConfig
{
"name": "adonis5-prometheus",
"version": "0.0.2",
"version": "0.0.3",
"description": "Prometheus wrapper for Adonis 5",

@@ -5,0 +5,0 @@ "main": "build/providers/PrometheusProvider.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc