Elastic APM 中的事务
事务是具有与其关联的附加属性的特殊跨度。它们描述了由检测服务的 Elastic APM 代理捕获的事件。您可以将事务视为您在服务中测量的最高级别的工作。例如,事务可能是一个
- 对服务器的请求
- 批处理作业
- 后台作业
- 自定义事务类型
代理决定是否对事务进行采样,并提供控制采样行为的设置。如果进行了采样,事务的 跨度 将作为单独的文档发送和存储。在一个事务中,可以捕获 0 个、1 个或多个跨度。
事务包含
事件的时间戳
唯一的 ID、类型和名称
关于记录事件所在环境的数据
- Service(服务)- 环境、框架、语言等。
- Host(主机)- 架构、主机名、IP 等。
- Process(进程)- 参数、PID、PPID 等。
- URL - 完整路径、域、端口、查询等。
- User(用户) - (如果提供)电子邮件、ID、用户名等。
取决于代理的其他相关信息。例如:JavaScript RUM 代理会捕获事务标记,这些标记是相对于事务开始带有某些标签的时间点。
此外,代理还为用户提供了捕获自定义 metadata(元数据)的选项。元数据可以被索引 - labels,或不被索引 - custom。
事务在应用程序 UI 的 Transaction overview(事务概览)中按其 type 和 name 进行分组。如果您使用的是受支持的框架,APM 代理将自动为您处理命名。如果不是,或者您希望覆盖默认设置,所有代理都提供有 API 方法来手动设置 type 和 name。
type应该是服务域中具有特定相关性的关键词,例如request、backgroundjob等。name应该是单个服务范围内事务的通用称谓,例如GET /users/:id、UsersController#show等。
提示
大多数代理将关键字字段(例如 labels)限制为 1024 个字符,将非关键字字段(例如 span.db.statement)限制为 10,000 个字符。
事务与跨度一起存储在以下数据流中
- 应用程序跟踪:
traces-apm-<namespace> - RUM 和 iOS 代理应用程序跟踪:
traces-apm.rum-<namespace>
请参阅数据流(Data streams)以了解更多信息。
此示例展示了在 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": "https://: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"
}
}
]