Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
nextjs-prometheus
Advanced tools
This module provides prometheus instrumentation for server-side rendering via getServerSideProps, middleware, api
Note: Due to his nature the minimum supported Next.js version is 12.0.9. If you are using Next.js middleware the minimum supported version is 12.2.0. Currently is not supporting the new App Route. Open a new issue if you need such support.
nextjs-prometheus is instrumenting prometheus by monkey-patching the nextJS modules responsibile for SSR operations. It is currently wrapping:
It is also collecting the child process metrics using collectDefaultMetrics from prom-client
Disclaimer monkey-patching relies on the internal implementation of a module, which may change over time, leading to compatibility and maintenance issues.
Monkey-patching for Application Performance Monitoring (APM) provides a powerful and flexible approach, enabling seamless integration and deep insights into your application's inner workings without disrupting its original structure, ultimately enhancing observability and optimizing performance.
To use this library you can add the following script to your package.json
"start": "NODE_OPTIONS='--require nextjs-prometheus' next start",
Another aproach would be to wrap the method you wanna track in a HOF. Here I leave an example for getServerSideProps.
// withPrometheusMetrics.js
function withPrometheusMetrics(getServerSidePropsFunction) {
return async function (context) {
const start = process.hrtime();
// Call the original getServerSideProps function
const result = await getServerSidePropsFunction(context);
// Calculate the duration of the call
const diff = process.hrtime(start);
const duration = diff[0] + diff[1] / 1e9;
// Update Prometheus metrics
getServerSidePropsCounter.inc();
getServerSidePropsHistogram.observe(duration);
return result;
};
}
module.exports = withPrometheusMetrics;
You can then use the HOF inside your pages.
// pages/yourPage.js
import withPrometheusMetrics from '../withPrometheusMetrics';
export async function getServerSideProps(context) {
// Your original getServerSideProps logic
}
export default withPrometheusMetrics(getServerSideProps);
FAQs
Observability of a nextjs application w/ Prometheus
The npm package nextjs-prometheus receives a total of 0 weekly downloads. As such, nextjs-prometheus popularity was classified as not popular.
We found that nextjs-prometheus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.