事务
Elastic Stack Serverless
事务是一种特殊的 span,它们具有与之关联的附加属性。它们描述了由 Elastic APM 代理检测服务所捕获的事件。您可以将事务视为您在服务中测量的最高级别的工作。例如,事务可能是一个
- 对您服务器的请求
- 批处理作业
- 后台作业
- 自定义事务类型
代理决定是否对事务进行采样,并提供设置来控制采样行为。如果采样,则事务的 span 将作为单独的文档发送和存储。在一个事务中,可以捕获 0、1 或多个 span。
事务包含
事件的时间戳
唯一的 ID、类型和名称
有关记录事件的环境的数据
- 服务 - 环境、框架、语言等。
- 主机 - 架构、主机名、IP 等。
- 进程 - args、PID、PPID 等。
- URL - 完整 URL、域名、端口、查询等。
- 用户 -(如果提供)电子邮件、ID、用户名等。
取决于代理的其他相关信息。示例:JavaScript RUM 代理捕获事务标记,这些标记是相对于事务开始时间的点,并带有一些标签。
此外,代理还为用户提供捕获自定义 元数据的选项。元数据可以被索引 - labels
,或者不被索引 - custom
。
事务按其 type
和 name
在应用程序 UI 的 事务概述 中进行分组。如果您使用的是受支持的框架,APM 代理将自动为您处理命名。如果您没有使用,或者您希望覆盖默认值,则所有代理都有 API 方法来手动设置 type
和 name
。
type
应该是在服务领域中具有特定相关性的关键字,例如request
、backgroundjob
等。name
应该是在单个服务的范围内事务的通用指定,例如GET /users/:id
、UsersController#show
等。
提示
大多数代理将关键字字段(例如 labels
)限制为 1024 个字符,将非关键字字段(例如 span.db.statement
)限制为 10,000 个字符。
事务与 span 存储在以下数据流中
- 应用程序跟踪:
traces-apm-<namespace>
- RUM 和 iOS 代理应用程序跟踪:
traces-apm.rum-<namespace>
请参阅 数据流 以了解更多信息。
此示例展示了在 Elasticsearch 中索引时事务文档可能是什么样子。
展开 Elasticsearch 文档
[
{
"@timestamp": "2017-05-30T18:53:42.281Z",
"agent": {
"name": "elastic-node",
"version": "3.14.0"
},
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.12.0"
},
"event": {
"ingested": "2020-08-11T09:55:04.391451Z",
"outcome": "unknown"
},
"host": {
"architecture": "x64",
"ip": ["127.0.0.1"],
"os": {
"platform": "darwin"
}
},
"kubernetes": {
"namespace": "namespace1",
"pod": {
"name": "pod-name",
"uid": "pod-uid"
}
},
"observer": {
"hostname": "ix.lan",
"type": "apm-server",
"version": "8.0.0"
},
"process": {
"args": [
"node",
"server.js"
],
"pid": 1234,
"parent": {
"pid": 6789
},
"title": "node"
},
"processor": {
"event": "transaction",
"name": "transaction"
},
"service": {
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
},
"language": {
"name": "ecmascript",
"version": "8"
},
"name": "1234_service-12a3",
"node": {
"name": "container-id"
},
"runtime": {
"name": "node",
"version": "8.0.0"
},
"version": "5.1.3"
},
"timestamp": {
"us": 1496170422281000
},
"trace": {
"id": "85925e55b43f4340aaaaaaaaaaaaaaaa"
},
"transaction": {
"duration": {
"us": 13980
},
"id": "85925e55b43f4340",
"name": "GET /api/types",
"result": "failure",
"sampled": true,
"span_count": {
"started": 0
},
"type": "request"
},
"user": {
"email": "foo@bar.com",
"id": "123user",
"name": "foo"
}
},
{
"@timestamp": "2017-05-30T18:53:42.281Z",
"agent": {
"name": "elastic-node",
"version": "3.14.0"
},
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.12.0"
},
"event": {
"ingested": "2020-08-11T09:55:04.391639Z",
"outcome": "unknown"
},
"host": {
"architecture": "x64",
"ip": "127.0.0.1",
"os": {
"platform": "darwin"
}
},
"kubernetes": {
"namespace": "namespace1",
"pod": {
"name": "pod-name",
"uid": "pod-uid"
}
},
"observer": {
"ephemeral_id": "fb037b97-0027-401a-9dc4-17d162f2687f",
"hostname": "goat",
"id": "a4daf4ca-b280-4ede-90df-bf62482cec37",
"type": "apm-server",
"version": "8.0.0"
},
"process": {
"args": [
"node",
"server.js"
],
"pid": 1234,
"parent": {
"pid": 6789
},
"title": "node"
},
"processor": {
"event": "transaction",
"name": "transaction"
},
"service": {
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
},
"language": {
"name": "ecmascript",
"version": "8"
},
"name": "1234_service-12a3",
"node": {
"name": "container-id"
},
"runtime": {
"name": "node",
"version": "8.0.0"
},
"version": "5.1.3"
},
"timestamp": {
"us": 1496170422281999
},
"trace": {
"id": "85925e55b43f4342aaaaaaaaaaaaaaaa"
},
"transaction": {
"duration": {
"us": 13980
},
"id": "85925e55b43f4342",
"name": "GET /api/types",
"result": "200",
"sampled": true,
"span_count": {
"dropped": 258,
"started": 1
},
"type": "request"
},
"user": {
"email": "foo@bar.com",
"id": "123user",
"name": "foo"
}
},
{
"@timestamp": "2017-05-30T18:53:27.154Z",
"agent": {
"name": "js-base",
"version": "1.3"
},
"client": {
"geo": {
"continent_name": "North America",
"country_iso_code": "US",
"country_name": "United States",
"location": {
"lat": 37.751,
"lon": -97.822
}
},
"ip": "8.8.8.8"
},
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.12.0"
},
"event": {
"ingested": "2020-08-11T09:55:04.338986Z",
"outcome": "unknown"
},
"host": {
"architecture": "x64",
"ip": "127.0.0.1",
"os": {
"platform": "darwin"
}
},
"http": {
"request": {
"body": {
"original": {
"additional": {
"bar": 123,
"req": "additional information"
},
"str": "hello world"
}
},
"cookies": {
"c1": "v1",
"c2": "v2"
},
"env": {
"GATEWAY_INTERFACE": "CGI/1.1",
"SERVER_SOFTWARE": "nginx"
},
"headers": {
"Array": [
"foo",
"bar",
"baz"
],
"Content-Type": [
"text/html"
],
"Cookie": [
"c1=v1,c2=v2"
],
"Some-Other-Header": [
"foo"
],
"User-Agent": [
"Mozilla Chrome Edge"
]
},
"method": "POST",
"referrer": "http://localhost:8000/test/e2e/"
},
"response": {
"finished": true,
"headers": {
"Content-Type": [
"application/json"
]
},
"headers_sent": true,
"status_code": 200
},
"version": "1.1"
},
"kubernetes": {
"namespace": "namespace1",
"pod": {
"name": "pod-name",
"uid": "pod-uid"
}
},
"labels": {
"bool_error": false,
"number_code": 2,
"organization_uuid": "9f0e9d64-c185-4d21-a6f4-4673ed561ec8"
},
"observer": {
"ephemeral_id": "fb037b97-0027-401a-9dc4-17d162f2687f",
"hostname": "goat",
"id": "a4daf4ca-b280-4ede-90df-bf62482cec37",
"type": "apm-server",
"version": "8.0.0"
},
"process": {
"args": [
"node",
"server.js"
],
"pid": 1234,
"parent": {
"pid": 6789
},
"title": "node"
},
"processor": {
"event": "transaction",
"name": "transaction"
},
"service": {
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
},
"language": {
"name": "ecmascript",
"version": "8"
},
"name": "serviceabc",
"node": {
"name": "special-name"
},
"runtime": {
"name": "javascript",
"version": "8.0.0"
},
"version": "5.1.3"
},
"source": {
"ip": "8.8.8.8"
},
"timestamp": {
"us": 1496170407154000
},
"trace": {
"id": "945254c567a5417eaaaaaaaaaaaaaaaa"
},
"transaction": {
"custom": {
"(": "not a valid regex and that is fine",
"and_objects": {
"foo": [
"bar",
"baz"
]
},
"my_key": 1,
"some_other_value": "foo bar"
},
"duration": {
"us": 32592
},
"id": "945254c567a5417e",
"marks": {
"another_mark": {
"some_float": 10,
"some_long": 10
},
"navigationTiming": {
"appBeforeBootstrap": 608.9300000000001,
"navigationStart": -21
}
},
"name": "GET /api/types",
"result": "success",
"sampled": true,
"span_count": {
"dropped": 2,
"started": 4
},
"type": "request"
},
"url": {
"domain": "www.example.com",
"fragment": "#hash",
"full": "https://www.example.com/p/a/t/h?query=string#hash",
"original": "/p/a/t/h?query=string#hash",
"path": "/p/a/t/h",
"port": 8080,
"query": "?query=string",
"scheme": "https"
},
"user": {
"email": "foo@example.com",
"id": "99"
},
"user_agent": {
"device": {
"name": "Other"
},
"name": "Other",
"original": "Mozilla Chrome Edge"
}
}
]