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