Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add database link field to spans #2504

Merged
merged 2 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
"action": "query",
"db": {
"instance": "customers",
"link": "other.db.com",
"statement": "SELECT * FROM product_types WHERE user_id=?",
"type": "sql",
"user": {
Expand Down
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Upgrade Go to 1.12.7 {pull}2483[2483].
- Add config option to disable sourcemapping {pull}2488[2488].
- Store service environment for spans {pull}2500[2500].
- Index span.db.link field as keyword {pull}2504[2504].

[float]
==== Removed
Expand Down
1 change: 1 addition & 0 deletions docs/data/elasticsearch/generated/spans.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"action": "query",
"db": {
"instance": "customers",
"link": "other.db.com",
"statement": "SELECT * FROM product_types WHERE user_id=?",
"type": "sql",
"user": {
Expand Down
11 changes: 11 additions & 0 deletions docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,17 @@ type: boolean

--


*`span.db.link`*::
+
--
Database link.


type: keyword

--

[[exported-fields-apm-transaction]]
== APM Transaction fields

Expand Down
13 changes: 9 additions & 4 deletions docs/spec/spans/span.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ "$ref": "../timestamp_epoch.json" },
{ "$ref": "../span_type.json" },
{ "$ref": "../span_subtype.json" },
{
{
"properties": {
"id": {
"description": "Hex encoded 64 random bits ID of the span.",
Expand All @@ -15,16 +15,16 @@
},
"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.",
"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.",
"type": "string",
"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.",
"type": "string",
"maxLength": 1024
},
Expand All @@ -49,6 +49,11 @@
"type": ["string", "null"],
"description": "Database instance name"
},
"link": {
"type": ["string", "null"],
"maxLength": 1024,
"description": "Database link"
},
"statement": {
"type": ["string", "null"],
"description": "A database statement (e.g. query) for the given database type"
Expand Down
2 changes: 1 addition & 1 deletion include/fields.go

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion model/span/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fields:

- name: id
type: keyword
type: keyword
description: >
The ID of the span stored as hex encoded string.

Expand Down Expand Up @@ -52,3 +52,12 @@
description: >
Indicates whether the span was executed synchronously or asynchronously.

- name: db
type: group
dynamic: false
fields:

- name: link
type: keyword
description: >
Database link.
3 changes: 3 additions & 0 deletions model/span/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type db struct {
Statement *string
Type *string
UserName *string
Link *string
}

func DecodeDb(input interface{}, err error) (*db, error) {
Expand All @@ -106,6 +107,7 @@ func DecodeDb(input interface{}, err error) (*db, error) {
decoder.StringPtr(dbInput, "statement"),
decoder.StringPtr(dbInput, "type"),
decoder.StringPtr(dbInput, "user"),
decoder.StringPtr(dbInput, "link"),
}
return &db, decoder.Err
}
Expand All @@ -121,6 +123,7 @@ func (db *db) fields() common.MapStr {
if db.UserName != nil {
utility.Set(fields, "user", common.MapStr{"name": db.UserName})
}
utility.Set(fields, "link", db.Link)
return fields
}

Expand Down
6 changes: 3 additions & 3 deletions model/span/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func TestDecodeSpan(t *testing.T) {
name, spType := "foo", "db"
start, duration := 1.2, 3.4
method, statusCode, url := "get", 200, "http://localhost"
instance, statement, dbType, user := "db01", "select *", "sql", "joe"
instance, statement, dbType, user, link := "db01", "select *", "sql", "joe", "other.db.com"
context := map[string]interface{}{
"a": "b",
"tags": map[string]interface{}{"a": "tag", "tag.key": 17},
"http": map[string]interface{}{"method": "GET", "status_code": json.Number("200"), "url": url},
"db": map[string]interface{}{"instance": instance, "statement": statement, "type": dbType, "user": user},
"db": map[string]interface{}{"instance": instance, "statement": statement, "type": dbType, "user": user, "link": link},
}
subtype := "postgresql"
action, action2 := "query", "query.custom"
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestDecodeSpan(t *testing.T) {
ParentId: parentId,
TransactionId: &transactionId,
Http: &http{Method: &method, StatusCode: &statusCode, Url: &url},
Db: &db{Instance: &instance, Statement: &statement, Type: &dbType, UserName: &user},
Db: &db{Instance: &instance, Statement: &statement, Type: &dbType, UserName: &user, Link: &link},
},
},
} {
Expand Down
13 changes: 9 additions & 4 deletions model/span/generated/schema/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ModelSchema = `{
"maxLength": 1024
}
} },
{
{
"properties": {
"id": {
"description": "Hex encoded 64 random bits ID of the span.",
Expand All @@ -61,16 +61,16 @@ const ModelSchema = `{
},
"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.",
"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.",
"type": "string",
"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.",
"type": "string",
"maxLength": 1024
},
Expand All @@ -95,6 +95,11 @@ const ModelSchema = `{
"type": ["string", "null"],
"description": "Database instance name"
},
"link": {
"type": ["string", "null"],
"maxLength": 1024,
"description": "Database link"
},
"statement": {
"type": ["string", "null"],
"description": "A database statement (e.g. query) for the given database type"
Expand Down
1 change: 1 addition & 0 deletions processor/stream/package_tests/span_attrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func TestKeywordLimitationOnSpanAttrs(t *testing.T) {
{Template: "parent.id", Mapping: "parent_id"},
{Template: "trace.id", Mapping: "trace_id"},
{Template: "span.id", Mapping: "id"},
{Template: "span.db.link", Mapping: "context.db.link"},
{Template: "span.", Mapping: ""},
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"action": "query",
"db": {
"instance": "customers",
"link": "other.db.com",
"statement": "SELECT * FROM product_types WHERE user_id=?",
"type": "sql",
"user": {
Expand Down
2 changes: 1 addition & 1 deletion testdata/intake-v2/spans.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{"span": {"trace_id": "abcdef0123456789abcdef9876543210", "parent_id": "0000000011111111", "id": "1234abcdef567895", "transaction_id": "ab45781d265894fe", "name": "GET /api/types", "type": "request", "start": 22, "duration": 32.592981, "timestamp": 1532976822281000,"context":{"service":{"environment":"prod","agent":{}}}}}
{"span": {"trace_id": "abcdef0123456789abcdef9876543210", "parent_id": "abcdefabcdef7890", "id": "0123456a89012345", "transaction_id": "ab23456a89012345", "name": "GET /api/types", "type": "request.http", "start": 1.845, "duration": 3.5642981, "stacktrace": [], "context":{"tags": {"tag1": "value1", "tag2": 123, "tag3": 12.34, "tag4": true, "tag5": null},"service":{}}}}}
{"span": {"trace_id": "abcdef0123456789abcdef9876543210", "parent_id": "ababcdcdefefabde", "id": "abcde56a89012345", "transaction_id": null, "name": "get /api/types", "sync": false, "type": "request", "subtype": "http", "action": "call", "start": 0, "duration": 13.9802981, "stacktrace": null, "context": null }}
{"span": {"trace_id": "abcdef0123456789abcdef9876543210", "parent_id": "abcdef0123456789", "id": "1234567890aaaade", "sync": true, "name": "SELECT FROM product_types", "type": "db.postgresql.query", "start": 2.83092, "duration": 3.781912, "stacktrace": [{ "filename": "net.js", "lineno": 547},{"filename": "file2.js", "lineno": 12, "post_context": [ " ins.currentTransaction = prev", "}"]}, { "function": "onread", "abs_path": "net.js", "filename": "net.js", "lineno": 547, "library_frame": true, "vars": { "key": "value" }, "module": "some module", "colno": 4, "context_line": "line3", "pre_context": [ " var trans = this.currentTransaction", "" ], "post_context": [ " ins.currentTransaction = prev", " return result"] }], "context": { "db": { "instance": "customers", "statement": "SELECT * FROM product_types WHERE user_id=?", "type": "sql", "user": "readonly_user" }, "http": { "url": "http://localhost:8000", "status_code": 200, "method": "GET" },"service":{"name":"service1","agent":{"version":"2.2","name":"elastic-ruby", "ephemeral_id": "justanid"}}}}}
{"span": {"trace_id": "abcdef0123456789abcdef9876543210", "parent_id": "abcdef0123456789", "id": "1234567890aaaade", "sync": true, "name": "SELECT FROM product_types", "type": "db.postgresql.query", "start": 2.83092, "duration": 3.781912, "stacktrace": [{ "filename": "net.js", "lineno": 547},{"filename": "file2.js", "lineno": 12, "post_context": [ " ins.currentTransaction = prev", "}"]}, { "function": "onread", "abs_path": "net.js", "filename": "net.js", "lineno": 547, "library_frame": true, "vars": { "key": "value" }, "module": "some module", "colno": 4, "context_line": "line3", "pre_context": [ " var trans = this.currentTransaction", "" ], "post_context": [ " ins.currentTransaction = prev", " return result"] }], "context": { "db": { "instance": "customers", "statement": "SELECT * FROM product_types WHERE user_id=?", "type": "sql", "user": "readonly_user", "link": "other.db.com" }, "http": { "url": "http://localhost:8000", "status_code": 200, "method": "GET" },"service":{"name":"service1","agent":{"version":"2.2","name":"elastic-ruby", "ephemeral_id": "justanid"}}}}}