question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow customization of the message sent in recordRpc (express-middleware)

See original GitHub issue

Hello! At the moment, message sent in recordRpc is a combination of req.method and req.route.path as can be seen here: https://github.com/openzipkin/zipkin-js/blob/aeb5d09beaa3b3dd634200625f236c76ea4630d0/packages/zipkin-instrumentation-express/src/expressMiddleware.js#L58

It would be a great improvement to allow the customization of this message. Maybe through a method passed as an argument of expressMiddleware function (like tracer, servicename and port). This method could accept req object as argument to have access to properties like req.originalUrl or req.baseUrl With this improvement examples like this could be achieved.

const customMessage = function customMessage(req) {
     return 'Custom message: '.concat(serviceName, ' ').concat(req.method, ' ')
     .concat(req.baseUrl).concat(req.route.path);
};
// Add zipkin middleware
app.use(zipkinMiddleware({ tracer, serviceName, customMessage }));

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DavidGarNavcommented, May 15, 2019

Thanks for your responses @jcchavezs and @ghermeto. I will try to explain the need to customize the Rpc.

Our API framework does not allow us to include the whole endpoint inside req.route.path in consequence we are not able to distinguise two endpoints from two different services in Zipkin.

Lets say:

  • Service 1:

    • method = post
    • originaUrl = api/servcie1/get
    • req.baseUrl = api/service1
    • req.route.path = /add
  • Service 2:

    • method = post
    • originaUrl = api/servcie2/get
    • req.baseUrl = api/service2
    • req.route.path = /add

With the actual behaviour of express-middleware recordRpc method will send the same message for both services (post /add). If we want to apply metrics based on this field both services will be considered the same, which is a mistake. Unfortunately recode our routing system to avoid this problem is not possible, that’s why we request this change.

I can’t see how the spanCustomizer could help to solve this problem becuse if recordRpc method is not replaced, the same message will be sent anyway.

A possible implementation of the change that we request could be: Add customMessage argument to https://github.com/openzipkin/zipkin-js/blob/aeb5d09beaa3b3dd634200625f236c76ea4630d0/packages/zipkin-instrumentation-express/src/expressMiddleware.js#L30

Result:

module.exports = function expressMiddleware({tracer, serviceName, port = 0, customMessage = null}) {

Replace code inside if statement at https://github.com/openzipkin/zipkin-js/blob/aeb5d09beaa3b3dd634200625f236c76ea4630d0/packages/zipkin-instrumentation-express/src/expressMiddleware.js#L57-L59

Result:

if (req.route) {
    if (customMessage) {
        tracer.recordRpc(customMessage(req));
    } else {
        tracer.recordRpc(`${req.method} ${req.route.path}`);
    }
}

I hope that this explanation helps to understand our request.

Thank you

0reactions
jcchavezscommented, Jul 24, 2019

Awesome @DavidGarNav!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing middleware for use in Express apps - Express.js
Every time the app receives a request, it prints the message “LOGGED” to the terminal. The order of middleware loading is important: middleware...
Read more >
Complete Guide to Express Middleware - Reflectoring
Middleware in Express are functions that come into play after the server receives the request and before the response is sent to the...
Read more >
How To Create a Custom Middleware in Express.js
You can enable your custom middleware in your Express server by applying the built-in Express.js middleware, .use() . In your server.js file, ...
Read more >
Cannot send audio using `RecordRTC.js` to backend
Please try this: sendMMS() { var fileType = 'audio'; // or "audio" var fileName = 'abcde.wav'; // or "wav" let formData = new...
Read more >
WebRTC API - MDN Web Docs - Mozilla
Most streams consist of at least one audio track and likely also a video track, and can be used to send and receive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found