Skip to content

Commit

Permalink
[v2] Require dt ids for errors if one is given. (elastic#1398)
Browse files Browse the repository at this point in the history
* [v2] Require dt ids for errors if one is given.

Change json spec to require `transaction_id`, `trace_id` and `parent_id`
as soon as one of them is given.
  • Loading branch information
simitt authored and Ron cohen committed Oct 15, 2018
1 parent d8f44af commit 101f066
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
17 changes: 13 additions & 4 deletions docs/spec/errors/v2_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,31 @@
"maxLength": 1024
},
"trace_id": {
"description": "Hex encoded 128 random bits ID of the correlated trace.",
"description": "Hex encoded 128 random bits ID of the correlated trace. Must be present if transaction_id and parent_id are set.",
"type": ["string", "null"],
"maxLength": 1024
},
"transaction_id": {
"type": ["string", "null"],
"description": "Hex encoded 64 random bits ID of the correlated transaction.",
"description": "Hex encoded 64 random bits ID of the correlated transaction. Must be present if trace_id and parent_id are set.",
"maxLength": 1024
},
"parent_id": {
"description": "Hex encoded 64 random bits ID of the parent transaction or span.",
"description": "Hex encoded 64 random bits ID of the parent transaction or span. Must be present if trace_id and transaction_id are set.",
"type": ["string", "null"],
"maxLength": 1024
}
},
"required": ["id"]
"allOf": [
{ "required": ["id"] },
{ "if": {"required": ["transaction_id"]},
"then": { "required": ["trace_id"], "properties": {"trace_id": { "type": "string" }}} },
{ "if": {"required": ["trace_id"]},
"then": { "required": ["parent_id"], "properties": {"parent_id": { "type": "string" }}} },
{ "if": {"required": ["parent_id"]},
"then": { "required": ["transaction_id"], "properties": {"transaction_id": { "type": "string" }}} }

]
}
]
}
17 changes: 13 additions & 4 deletions model/error/generated/schema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,31 @@ const ModelSchema = `{
"maxLength": 1024
},
"trace_id": {
"description": "Hex encoded 128 random bits ID of the correlated trace.",
"description": "Hex encoded 128 random bits ID of the correlated trace. Must be present if transaction_id and parent_id are set.",
"type": ["string", "null"],
"maxLength": 1024
},
"transaction_id": {
"type": ["string", "null"],
"description": "Hex encoded 64 random bits ID of the correlated transaction.",
"description": "Hex encoded 64 random bits ID of the correlated transaction. Must be present if trace_id and parent_id are set.",
"maxLength": 1024
},
"parent_id": {
"description": "Hex encoded 64 random bits ID of the parent transaction or span.",
"description": "Hex encoded 64 random bits ID of the parent transaction or span. Must be present if trace_id and transaction_id are set.",
"type": ["string", "null"],
"maxLength": 1024
}
},
"required": ["id"]
"allOf": [
{ "required": ["id"] },
{ "if": {"required": ["transaction_id"]},
"then": { "required": ["trace_id"], "properties": {"trace_id": { "type": "string" }}} },
{ "if": {"required": ["trace_id"]},
"then": { "required": ["parent_id"], "properties": {"parent_id": { "type": "string" }}} },
{ "if": {"required": ["parent_id"]},
"then": { "required": ["transaction_id"], "properties": {"transaction_id": { "type": "string" }}} }
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@
"processor": {
"event": "error",
"name": "error"
},
"transaction": {
"id": "0000555544446666"
}
},
{
Expand Down Expand Up @@ -364,6 +361,9 @@
},
"trace": {
"id": "0123456789abcdeffedcba0123456789"
},
"transaction": {
"id": "1234567890987654"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions testdata/intake-v2/errors.ndjson
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"metadata": {"process": {"ppid": 6789, "pid": 1234, "argv": ["node", "server.js"], "title": "node"}, "system": {"platform": "darwin", "hostname": "prod1.example.com", "architecture": "x64"}, "service": {"name": "1234_service-12a3", "language": {"version": "8", "name": "ecmascript"}, "agent": {"version": "3.14.0", "name": "elastic-node"}, "environment": "staging", "framework": {"version": "1.2.3", "name": "Express"}, "version": "5.1.3", "runtime": {"version": "8.0.0", "name": "node"}}}}
{"error": {"id": "0123456789012345", "timestamp": "2017-05-09T15:04:05.999999Z", "culprit": "my.module.function_name","log": { "message": "My service could not talk to the database named foobar", "param_message": "My service could not talk to the database named %s", "logger_name": "my.logger.name", "level": "warning", "stacktrace": [ { "abs_path": "/real/file/name.py", "filename": "/webpack/file/name.py", "function": "foo", "vars": { "key": "value" }, "pre_context": ["line1", "line2"], "context_line": "line3","library_frame": false,"lineno": 3,"module": "App::MyModule","colno": 4,"post_context": ["line4","line5" ]},{"filename": "lib/instrumentation/index.js","lineno": 102,"function": "instrumented","abs_path": "/Users/watson/code/node_modules/elastic/lib/instrumentation/index.js","vars": {"key": "value"},"pre_context": [" var trans = this.currentTransaction",""," return instrumented",""," function instrumented () {"," var prev = ins.currentTransaction", " ins.currentTransaction = trans"],"context_line": " var result = original.apply(this, arguments)","post_context": [" ins.currentTransaction = prev"," return result","}","}","","Instrumentation.prototype._recoverTransaction = function (trans) {"," if (this.currentTransaction === trans) return"]}]},"exception": {"message": "The username root is unknown","type": "DbError","module": "__builtins__","code": 42,"handled": false,"attributes": {"foo": "bar" },"stacktrace": [{ "abs_path": "/real/file/name.py","filename": "file/name.py","function": "foo","vars": {"key": "value"},"pre_context": ["line1","line2"],"context_line": "line3", "library_frame": true,"lineno": 3,"module": "App::MyModule","colno": 4,"post_context": ["line4","line5"]},{"filename": "lib/instrumentation/index.js","lineno": 102,"function": "instrumented","abs_path": "/Users/watson/code/node_modules/elastic/lib/instrumentation/index.js","vars": {"key": "value"},"pre_context": [" var trans = this.currentTransaction",""," return instrumented",""," function instrumented () {", " var prev = ins.currentTransaction"," ins.currentTransaction = trans"],"context_line": " var result = original.apply(this, arguments)","post_context": [" ins.currentTransaction = prev"," return result","}","}","","Instrumentation.prototype._recoverTransaction = function (trans) {"," if (this.currentTransaction === trans) return"]}]},"context": {"request": {"socket": {"remote_address": "12.53.12.1","encrypted": true},"http_version": "1.1","method": "POST","url": {"protocol": "https:","full": "https://www.example.com/p/a/t/h?query=string#hash","hostname": "www.example.com","port": "8080","pathname": "/p/a/t/h","search": "?query=string", "hash": "#hash","raw": "/p/a/t/h?query=string#hash"},"headers": {"user-agent": "Mozilla Chrome Edge","content-type": "text/html","cookie": "c1=v1; c2=v2","some-other-header": "foo","array": ["foo","bar","baz"]}, "cookies": {"c1": "v1", "c2": "v2" },"env": {"SERVER_SOFTWARE": "nginx", "GATEWAY_INTERFACE": "CGI/1.1"},"body": "Hello World"},"response": { "status_code": 200, "headers": { "content-type": "application/json" },"headers_sent": true, "finished": true }, "user": { "id": 99, "username": "foo", "email": "[email protected]"},"tags": {"organization_uuid": "9f0e9d64-c185-4d21-a6f4-4673ed561ec8"}, "custom": {"my_key": 1,"some_other_value": "foo bar","and_objects": {"foo": ["bar","baz" ] }}}, "transaction": {"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79" }}}
{ "error": {"id": "cdefab0123456789", "transaction_id": "0000555544446666", "timestamp": "2018-08-09T14:59:05.999Z","exception": {"message": "Cannot read property 'baz' no defined"}}}
{ "error": {"id": "abcdef0123456789", "trace_id": "0123456789abcdeffedcba0123456789", "parent_id": "9632587410abcdef", "timestamp": "2018-08-09T15:04:05.999Z","log": {"level": "custom log level","message": "Cannot read property 'baz' of undefined"}}}
{ "error": {"id": "cdefab0123456789", "timestamp": "2018-08-09T14:59:05.999Z","exception": {"message": "Cannot read property 'baz' no defined"}}}
{ "error": {"id": "abcdef0123456789", "trace_id": "0123456789abcdeffedcba0123456789", "parent_id": "9632587410abcdef", "transaction_id": "1234567890987654", "timestamp": "2018-08-09T15:04:05.999Z","log": {"level": "custom log level","message": "Cannot read property 'baz' of undefined"}}}

0 comments on commit 101f066

Please sign in to comment.