Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Custom instrumentation NodeJS not showing segments in dashboard single trace


#1

I would appreciate any help on this.

I am using custom instrumentation with NodeJS for New Relic web transactions tracing.

My current code implementation is this:

    exports.retrieve = function (req, res) {

        let lockedData = {};
        header.setHeaders(res);

        newrelic.startSegment('service.isItemActive()', true, () => {
          return service.isItemActive(req.params.worklistItemId)
        }).then(() => {
             newrelic.startSegment('service.checkItemLock()', true, () => {
              return service.checkItemLock(req.params.worklistItemId, req.query.email)
            }).then((_lockedData) => {
              lockedData = _lockedData;
              newrelic.startSegment('PDFService.getPDFReport()', true, () => {
                return PDFService.getPDFReport(req.params.worklistItemId, req.query.email, 'preview')
              }).then(function(result){
                const data = {
                  pdf: result.pdf,
                  lockedData: lockedData,
                  queueId: result.queueId,
                  onHold: result.onHold,
                  pdfLoad: result.pdfLoad
                };
                return res.status(200).send(data);
              })
            })
          })

};

But in the New Relic dashboard, I am only able to see the first segment logged (when you click in a transaction to see all the segments logged)

service.isItemActive()

Neither service.checkItemLock() nor PDFService.getPDFReport() would show up in the NR dashboard. I have tried to wrap all the method in a web transaction but still only able to see the first segment logged.

Thank you


#2

Hi there @atorres1- thanks for posting to the community!

I appreciate the code snippet. Do you think you could also send a permalink to show me where you are seeing the first segment logged displaying for your application?

Thank you kindly!

–Sara


#3

Hi sschultz

https://rpm.newrelic.com/accounts/1854710/applications/230215783/transactions?tw[end]=1552906342&tw[start]=1552904542&type=app#id=5b225765625472616e73616374696f6e2f457870726573736a732f4745542f2f6170692f7472662f7265706f72742f3a776f726b6c6973744974656d4964222c22225d


#4

Hey @atorres1- thanks for the additional info!

I’ve been digging into this issue, and I’m going to need to gather some sensitive info (such as trace level logs) to continue troubleshooting. This is the next step for us because we ruled out the following-

  1. Your response is clearly sent at the end of the sequence and our promise instrumentation should reinstate its own context, so this does not make me think it’s a problem with the context of the current transaction being lost.

  2. There doesn’t appear to be an issue with how you are calling startSegment in your code.

However, I recommend making an update such as the following just for best practice use of our API:

exports.retrieve = function(req, res) {

  let lockedData = {};
  header.setHeaders(res);

  newrelic.startSegment('service.isItemActive()', true, () => {
    return service.isItemActive(req.params.worklistItemId)
  }).then(() => {
    return newrelic.startSegment('service.checkItemLock()', true, () => {
      return service.checkItemLock(req.params.worklistItemId, req.query.email)
    })
  }).then((_lockedData) => {
    lockedData = _lockedData;
    return newrelic.startSegment('PDFService.getPDFReport()', true, () => {
      return PDFService.getPDFReport(req.params.worklistItemId, req.query.email, 'preview')
    })
  }).then(function(result) {
    const data = {
      pdf: result.pdf,
      lockedData: lockedData,
      queueId: result.queueId,
      onHold: result.onHold,
      pdfLoad: result.pdfLoad
    };
    return res.status(200).send(data);
  })
};

This change will return the result of calling startSegment. However, I don’t think the symptom of missing segments would be caused by this.

Given all that, I’ll be opening a ticket for you on our end so I can safely gather more info. We will continue troubleshooting from that platform- however, we love to encourage folks to circle back to their original post in the forum to share the solution in the end. This will help others who may have the same question as you and stumble upon this post.

Keep your eyes out for a message coming your way from us.

Cheers!

Sara