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

Transactions are not recorded for service #3411

Closed
pawan-1999 opened this issue Jun 9, 2023 · 2 comments
Closed

Transactions are not recorded for service #3411

pawan-1999 opened this issue Jun 9, 2023 · 2 comments
Assignees
Labels
agent-nodejs Make available for APM Agents project planning. community

Comments

@pawan-1999
Copy link

pawan-1999 commented Jun 9, 2023

Hi Team,

Transactions are not recorded for service but we can see the metrics

When we see the overview of the service we cannot see any data for that service but the name and entry is been added to the kibana UI. also I can see the metrics of that service. I want to trace the transactions for the service but it is not logged.

Steps to reproduce the behavior:

  1. Using the below hello world code (https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30)
const express = require('express')
const app = express()

// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({

// Override the service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: 'test-nodejs-app',

// Use if APM Server requires a secret token
secretToken: '',

// Set the custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://apm-server.com:8200',

capture_body: 'all',

// Set the service environment
environment: 'test'
})
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Server ready'))
  1. Then curl http://localhost:3000
  2. Then I got the entry of the service on Kibana UI in APM.
  3. But I cannot see any transactions or any other overview just I can see the metrics for that service

Expected behavior

It should show the transaction when I hit on http://localhost:3000

Environment

  • OS: Linux
  • Node.js version: v16.13.1
  • APM Server version: apm-server version 7.17.9 (amd64), libbeat 7.17.9 [71a8b4c241eb5b4609862c8354d2aa2270f6c568 built 2023-01-31 04:33:06 +0000 UTC]
  • Agent version: 3.46.0

How are you starting the agent? (please tick one of the boxes)

  • Using this: Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))

package.json dependencies:

  "dependencies": {
    "elastic-apm-node": "^3.46.0",
    "express": "^4.18.2",
    "http-errors": "^2.0.0"
  }
}

Thanks & Regards
Pawan Gupta

@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Jun 9, 2023
@trentm
Copy link
Member

trentm commented Jun 9, 2023

Hi @pawan-1999. Thanks for the question.

The issue here is that you are starting the APM agent after Express has already been loaded. For the APM agent to be able to instrument the express module, it needs to be started before require('express'). So if you change your script to something like this, it should work:

// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
    serviceName: 'test-nodejs-app',
    secretToken: '',
    serverUrl: 'http://apm-server.com:8200',
    capture_body: 'all',
    environment: 'test'
})

const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Server ready'))

https://www.elastic.co/guide/en/apm/agent/nodejs/current/starting-the-agent.html documents the issue with starting the APM agent too late.

We have an older issue to try to automatically warn about this kind of situation: #2578
I hope to implement that soon.

a separate note

This is unrelated, but a separate warning that you have the captureBody config var (https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#capture-body) incorrectly spelled as capture_body. You'll need captureBody: 'all' for that to work.

Cheers.

@trentm trentm closed this as completed Jun 9, 2023
@trentm trentm removed the triage label Jun 9, 2023
@trentm trentm self-assigned this Jun 9, 2023
@pawan-1999
Copy link
Author

Thanks for helping. it worked and also thanks for adding it up in the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community
Projects
None yet
Development

No branches or pull requests

2 participants