gpt4 book ai didi

node.js - 未在Node JS代理中记录APM服务器事务(快速)

转载 作者:行者123 更新时间:2023-12-02 22:34:57 25 4
gpt4 key购买 nike

描述错误

我遇到某个端点时未记录交易,但apm服务器获取度量标准数据。

重现

我在名为server.ts的第一个文件中启动了apm-server连接

const apm = elasticApmNode.start({
serviceName: 'Elk Stack',
serverUrl: '${process.env.APM_SERVER_HOST}',
captureBody: 'all',
});

使用装饰器创建快速路由,使用 app.use()实现路由
router.route('${route.path}')[route.method]([...middlewares.before, handler, ...middlewares.after, ...middlewares.error])
app.use('${uses}${prefix}', router);

我已经尝试通过使用 apm.startTransaction代码示例手动创建事务来解决此问题。
res.locals.apm.startTransaction(`${req.method.toUpperCase()} ${req.originalUrl}`, 'HTTP Request');
res.locals.apm.setTransactionName(`${req.method.toUpperCase()} ${req.originalUrl}`, 'HTTP Request');

但是交易仍然没有记录,实际上记录的交易范围但是 transaction对象只有 transaction.id元素。这是数据。
{
"_index": "apm-7.4.0-span-000002",
"_type": "_doc",
"_id": "qE6CsW4B-ATTlniHYhaa",
"_version": 1,
"_score": null,
"_source": {
"parent": {
"id": "e7a181e4404a3b3b"
},
"observer": {
"hostname": "c25837d06ef9",
"id": "25003f85-d836-49cc-b242-36241e59c3b8",
"ephemeral_id": "19bd8d86-e90a-40d2-8d3b-c4a2cfe3e182",
"type": "apm-server",
"version": "7.4.0",
"version_major": 7
},
"agent": {
"name": "nodejs",
"version": "3.2.0"
},
"trace": {
"id": "7da976d15b45dd660f47f21f60155902"
},
"@timestamp": "2019-11-28T10:15:39.471Z",
"ecs": {
"version": "1.1.0"
},
"service": {
"environment": "production",
"name": "Elk Stack"
},
"processor": {
"name": "transaction",
"event": "span"
},
"transaction": {
"id": "e7a181e4404a3b3b"
},
"timestamp": {
"us": 1574936139471892
},
"span": {
"duration": {
"us": 5802
},
"stacktrace": [
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/sequelize/lib/dialects/postgres/query.js",
"abs_path": "/var/www/app/node_modules/sequelize/lib/dialects/postgres/query.js",
"line": {
"number": 59
},
"function": "parameters.length.Promise"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/debuggability.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/debuggability.js",
"line": {
"number": 411
},
"function": "Promise._execute"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 518
},
"function": "Promise._resolveFromExecutor"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 103
},
"function": "Promise"
},
{
"exclude_from_grouping": false,
"library_frame": true,
"filename": "node_modules/sequelize/lib/dialects/postgres/query.js",
"abs_path": "/var/www/app/node_modules/sequelize/lib/dialects/postgres/query.js",
"line": {
"number": 59
},
"function": "run"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"abs_path": "/var/www/app/node_modules/sequelize/lib/sequelize.js",
"filename": "node_modules/sequelize/lib/sequelize.js",
"line": {
"number": 645
},
"function": "runHooks.then.then"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/util.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/util.js",
"line": {
"number": 16
},
"function": "tryCatcher"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 547
},
"function": "Promise._settlePromiseFromHandler"
},
{
"exclude_from_grouping": false,
"library_frame": true,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 604
},
"function": "Promise._settlePromise"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 649
},
"function": "Promise._settlePromise0"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/promise.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/promise.js",
"line": {
"number": 729
},
"function": "Promise._settlePromises"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/async.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/async.js",
"line": {
"number": 93
},
"function": "_drainQueueStep"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/async.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/async.js",
"line": {
"number": 86
},
"function": "_drainQueue"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules/bluebird/js/release/async.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/async.js",
"line": {
"number": 102
},
"function": "Async._drainQueues"
},
{
"exclude_from_grouping": false,
"library_frame": true,
"filename": "node_modules/bluebird/js/release/async.js",
"abs_path": "/var/www/app/node_modules/bluebird/js/release/async.js",
"line": {
"number": 15
},
"function": "Async.drainQueues"
},
{
"exclude_from_grouping": false,
"library_frame": true,
"filename": "timers.js",
"abs_path": "timers.js",
"line": {
"number": 810
},
"function": "runCallback"
},
{
"exclude_from_grouping": false,
"library_frame": true,
"filename": "timers.js",
"abs_path": "timers.js",
"line": {
"number": 768
},
"function": "tryOnImmediate"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "timers.js",
"abs_path": "timers.js",
"line": {
"number": 745
},
"function": "processImmediate"
}
],
"subtype": "postgresql",
"name": "INSERT INTO \"user\"",
"action": "query",
"id": "02a2368953f0f483",
"type": "db",
"sync": false,
"db": {
"statement": "INSERT INTO \"user\" (\"id\",\"name\",\"username\",\"email\",\"password\",\"birthdate\",\"phone\",\"createdDate\",\"updatedDate\") VALUES (DEFAULT,$1,$2,$3,$4,$5,$6,$7,$8) RETURNING *;",
"type": "sql"
}
}
},
"fields": {
"@timestamp": [
"2019-11-28T10:15:39.471Z"
]
},
"sort": [
1574936139471
]
}

预期的行为

像这样的APM页面

交易数据应如下所示(使用环回2的示例)

环境(请完成以下信息)
  • 操作系统:Linux(Windows中的Docker)
  • Node.js版本:8
  • APM服务器版本:7.4.0
  • 代理版本:3.2.0
  • 速成版:4.17.1

  • 您如何启动代理? (请勾选其中一个框)
  • [x]直接调用agent.start()(例如require('elastic-apm-node').start(...))
  • []从源代码
  • 中要求 elastic-apm-node/start
  • []带有-r elastic-apm-node/start的起始节点
  • 最佳答案

    我已经解决了这种情况,我将apm-server连接到了我的server.ts的第一个。 import'localenv'是此案的嫌疑人。

    Fixing case with place apm-server connect at first line of server

    关于node.js - 未在Node JS代理中记录APM服务器事务(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59086651/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com