ExpressJs Transaction Monitoring

ExpressJs

Code Execution Monitoring for Expressjs applications

Requirement

  • Expressjs >= 3.x

Install

Install the latest version of the module using the npm command below:

npm install @palzin-apm/palzin-nodejs --save

Configure the Ingestion Key and URL

You need an Ingestion Key and URL to create a Palzin Monitor (APM) instance. Obtain a new key by creating a project in your Palzin Monitor (APM) dashboard.

PALZIN_APM_INGESTION_KEY=[ingestion key]
PALZIN_APM_URL=[your palzin domain]

Initialization

It's important that Palzin is required in the first line of the script, before you require any other modules - i.e., before express, http, mysql, etc.

Attach the expressMiddleware() to your express app.

const palzin = require('@palzin-apm/palzin-nodejs')({
    url: 'xxxxxxxxx',
    ingestionKey: 'xxxxxxxxxxxxx'
});


// Init Fastify instance
const app = require('express')()

// Register Palzin Monitor integration
app.use(palzin.expressMiddleware());


/* ----------------------------------------------
 * The rest of the app
 ------------------------------------------------ */
app.get('/', function (req, res) {
    return res.send('Home Page!');
});

app.get('/posts/:id', function (req, res) {
    return res.send('Single Post Details!');
});

app.listen(3006);

// Continue with your code!
// ...

HTTP Request Monitoring

Send an HTTP request to your fastify app to see the first data in your dashboard.

Some of the most used modules will be autowired by default.

Exclude paths

If you want to turn off monitoring in some parts of your application you can pass a JSON object to the registering function with excludePaths property to define which routes you want to exclude:

app.use(palzin.expressMiddleware({
    excludePaths: [
        '/posts',
        '/posts/:id',
        '/admin'
    ]
}));

You can also use the wildcard character * to match a subset of your urls:

app.use(palzin.expressMiddleware({
    excludePaths: [
        // Single wildcard
        '/posts*',
        // More wildcards
        '/admin/*/posts*'
    ]
}))

Access the Palzin Monitor instance

Palzin Monitor will decorate the request instance with a new property to access Palzin Monitor anywhere in your application:

app.get('/', (request, response) => {
request.palzin.addSegment(...);
});

It's mandatory to call the Palzin Monitor instance inside your request instance to allow automatic tasks identification.

Custom Segments

By default, Palzin Monitor (APM) reports many different tasks based on the application's dependencies. However, you can "wrap" specific parts of your code that you consider relevant to create a more complete picture of the executed statements during an execution cycle and their performance.

Learn more about custom segments.

Last updated: 1 year ago

Want to get started with Palzin Monitor? We offer a no-strings-attached
15 days trial. No credit card required.

It takes less than a minutes to setup your first monitoring.