How to track class names of Parse Server with New Relic?

Viewed 184

When adding New Relic APM to track Parse Server, the calls to Cloud Code functions and Classes are displayed as:

/parse/classes/:className
/parse/functions/:functionName

Instead I want to display them as:

/parse/classes/myClass
/parse/functions/myFunction

For Cloud Code function calls I can set the transaction name:

Parse.Cloud.define("myFunction", async(request) => {
    newrelic.setTransactionName("myFunction");
    //...
});

But how can I track the names of all the calls to classes?

1 Answers

The New Relic Node.js agent has an auto-naming feature for transactions that can't be turned off*.

From the docs:

The only important thing to know about New Relic's support for Express, Restify, or Hapi is that if you're dissatisfied with the names it comes up with, you can use the API calls described below to come up with more descriptive names.

So the solution was to override these default name rules by adding custom name rules to newrelic.js. The trick is to use the regex group substitute as the name.

rules: {
    name: [
        // post /parse/classes/:classeName
        // get /parse/classes/:classeName/:objectId
        {
            pattern: '^(\/parse\/classes\/[_0-9A-Za-z]*)(\/.*)*',
            name: '\\1'
        },
        // post /parse/functions/:functionName
        {
            pattern: '^(\/parse\/functions\/.*)$',
            name: '\\1'
        },
        // post /parse/files/:filename
        // get /parse/files/:appId/:filename
        {
            pattern: '^(\/parse\/files)\/.*$',
            name: '\\1'
        }
    ]
}

The pattern above groups the calls by class name, ignoring the object ID that is sometimes appended. That makes it also unnecessary to add a setTransactionName for every Cloud Code function.


*It can be turned off for the Java agent, but that option does not seem to exists for the Node.js agent.

Related