Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reply to to end newrelic segment #15

Closed
wants to merge 2 commits into from

Conversation

guhmerces
Copy link
Collaborator

@guhmerces guhmerces commented Jun 10, 2022

The proposal of this PR is to refactor and wrap the "reply" function in order to finish newrelic segments as soon as the seneca action is complete.

Some results on the screenshots for the test below :

(async () => {
  await NewRelic.startBackgroundTransaction('Friday02', async() => {
    await Seneca({ legacy: false })
    .test()
    .use('promisify')
    .use(Plugin, {
      enabled: true,
      segment: {
      enabled: true
      }
    }).add('hello:world', async (_msg, reply) => {
      sleepSync(5500)
      return reply(null, { ok: true })
    }).add('bom:dia', async (_msg, reply) => {
      sleepSync(6500)
      return reply(null, { ok: true })
    }).message('good:morning', async (_msg, reply) => {
      sleepSync(2100)
      return ({ ok: true })
    }).act('hello:world', (_err, _out) => {
      console.log('please check the New Relic UI')
    }).act('bom:dia', (_err, _out) => {
      console.log('please check the New Relic UI')
    }).post('good:morning')
  })
  NewRelic.getTransaction().end()
  })();

Result :

image
image

@coveralls
Copy link

coveralls commented Jun 10, 2022

Pull Request Test Coverage Report for Build 2476122412

  • 0 of 12 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 20.432%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/newrelic.ts 0 12 0.0%
Totals Coverage Status
Change from base Build 2462510935: 0.4%
Covered Lines: 102
Relevant Lines: 498

💛 - Coveralls

@lilsweetcaligula
Copy link
Collaborator

The reason the code in the example works is because you are using sleepSync which busy-waits synchronously. There is no problem with synchronous code inside of the NewRelic.startSegment's handler. There is, however, a problem with a-synchronous code inside of the handler.

@guhmerces guhmerces closed this Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants