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