Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
nextjs-prometheus
Advanced tools
Readme
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 48 weekly downloads. As such, nextjs-prometheus popularity was classified as not popular.
We found that nextjs-prometheus demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.