I am trying to monitor my express API with apm-agent-nodejs (version 1.12.0)
Everything seems to works fine (no errors) but going to http://localhost:5601/app/apm show No services were found
, I don't have any search filter and the date range is Last 24 hours
.
If I click on the Setup instructions
then click on Check apm server status
button I have : You have correctly setup APM-Server
and Check agent status button
return Data successfully received from one or more agents
but I can't figure out how to have data about the HTTP calls made to the API.
My docker-compose.yml :
version: "3.3"
services:
api:
build: .
env_file:
- .env
volumes:
- .:/app
- /app/node_modules
ports:
- "9000:9000"
command: sh -c "mkdir -p dist && touch ./dist/app.js && yarn run start"
transpiler:
build: .
volumes:
- .:/app
- /app/node_modules
command: yarn run transpile -w
mongo:
image: mongo:4.0
ports:
- "27017"
command: mongod
volumes:
- ./data:/data/db
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.1
volumes:
- ./esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
ports:
- "9300:9300"
- "9200:9200"
kibana:
image: docker.elastic.co/kibana/kibana:6.4.1
ports:
- "5601:5601"
apm-server:
image: docker.elastic.co/apm/apm-server:6.4.1
ports:
- 8200:8200
volumes:
- ./apm-server.yml:/usr/share/apm-server/apm-server.yml
volumes:
esdata:
The ./apm-server.yml file :
apm-server:
host: "0.0.0.0:8200"
output.elasticsearch:
hosts: ["elasticsearch:9200"]
setup.kibana:
host: "kibana:5601"
logging.level: debug
The entrypoint file of the app with the agent :
import * as apm from 'elastic-apm-node/start'
import * as express from 'express'
import * as http from 'http'
import * as mongoose from 'mongoose'
import config from './config/environment'
import expressConfig from './config/express'
import routesConfig from './routes'
// Connect to database
(mongoose.Promise as any) = global.Promise
mongoose.connect(config.mongo.uri, { useNewUrlParser: true })
// Setup server
const app: express.Application = express()
const server: http.Server = http.createServer(app)
expressConfig(app)
routesConfig(app)
server.listen(config.port, config.ip, () => {
console.log('Express server listening on %d, in %s mode', config.port, app.get('env'))
})
export default app
If I add :
app.use(apm.middleware.connect())
after routesConfig(app)
Then I have the following log :
intercepted request event call to http.Server.prototype.emit
setting transaction result { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22',
result: 'success' }
start transaction { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22',
name: undefined,
type: undefined }
shimming express.Router.Layer.handle function
shimming express.Router.Layer.handle function
shimming express.Router.Layer.handle function
shimming express.Router.Layer.handle function
setting transaction result { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22',
result: 'HTTP 3xx' }
setting default transaction name: GET /api/v1/ping { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22' }
adding transaction to queue { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22' }
setting timer to flush queue: 5051ms
ended transaction { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22',
type: 'request',
result: 'HTTP 3xx',
name: 'GET /api/v1/ping' }
flushing queue
sending transactions payload
transaction already ended - cannot build new span { id: '34b65a8f-cc50-4e48-aaed-46406ab70f22' }
intercepted call to http.request { id: null }
Error: connect EINVAL 0.0.32.8:80 - Local (0.0.0.0:0)
at internalConnect (net.js:884:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:294:19)
at GetAddrInfoReqWrap.emitLookup (net.js:1031:9)
at GetAddrInfoReqWrap.elasticAPMCallbackWrapper [as callback] (/app/node_modules/elastic-apm-node/lib/instrumentation/index.js:189:27)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:62:10)
The elastic-apm-node.js file (used to configure the agent) :
module.exports = {
// Overwrite service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: 'test',
// Use if APM Server requires a token
secretToken: '',
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: '0.0.0.0:8200',
logLevel: 'debug'
}
After running docker-compose up
I do a few requests to http://localhost:9000/api/v1/ping/
basic GET url which return :
{
"ping": "pong"
}
with the HTTP code 200. But after waiting few minutes there is still no data.
In the kibana dev console
GET apm*/_search
{
"query": {
"term": {
"processor.name": "transaction"
}
}
}
produces
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
And curl localhost:8200
outputs 404 page not found