事务
编辑事务
编辑事务 是一种特殊的 span,它具有关联的附加属性。它们描述了由 Elastic APM 代理检测服务的事件。您可以将事务视为在服务中测量的最高级别工作。例如,事务可能是:
- 对您服务器的请求
- 批处理作业
- 后台作业
- 自定义事务类型
代理决定是否对事务进行采样,并提供设置来控制采样行为。如果已采样,则事务的 span 将作为单独的文档发送和存储。在一个事务中,可以捕获 0 个、1 个或多个 span。
事务包含:
- 事件的时间戳
- 唯一的 ID、类型和名称
-
关于记录事件的环境的数据
- 服务 - 环境、框架、语言等。
- 主机 - 架构、主机名、IP 等。
- 进程 - 参数、PID、PPID 等。
- URL - 全部、域名、端口、查询等。
- 用户 - (如果提供)电子邮件、ID、用户名等。
- 根据代理的不同而有所不同的其他相关信息。例如:JavaScript RUM 代理捕获事务标记,这些标记是相对于事务开始时间的一些带标签的时间点。
此外,代理还提供选项供用户捕获自定义 元数据。元数据可以被索引 - labels
,或者不被索引 - custom
。
事务在其 type
和 name
的基础上,在“应用程序”UI 的 事务概述 中进行分组。如果您使用的是受支持的框架,APM 代理将自动为您处理命名。如果您没有使用,或者您希望覆盖默认值,所有代理都具有手动设置 type
和 name
的 API 方法。
-
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": "[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" } } ]