Skip to content

Commit 9024e3d

Browse files
authored
Add transaction.sampled to error. (#1662) (#1664)
implements #1660
1 parent 504b58a commit 9024e3d

File tree

14 files changed

+82
-28
lines changed

14 files changed

+82
-28
lines changed

_meta/fields.common.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@
431431
value: "../app/kibana#/dashboard/3e3de700-7de0-11e7-b115-df9c90da2df1?_a=(query:(query_string:(analyze_wildcard:!t,query:'transaction.id:%22{{value}}%22')))"
432432
- min_version: 6.0.0-alpha1
433433
value: "../app/kibana#/dashboard/3e3de700-7de0-11e7-b115-df9c90da2df1?_a=(query:(language:lucene,query:'transaction.id:{{value}}'))"
434+
- name: sampled
435+
type: boolean
436+
description: >
437+
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context.
434438
435439
- name: trace
436440
type: group

changelogs/head.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ https://github.com/elastic/apm-server/compare/6.5\...6.x[View commits]
99
- Set some configuration defaults (setup.template.settings.index.*, logging.metrics.enabled) in code {pull}1494[1494].
1010
- Add `span.sync` property to intake json spec and index field in ES. {pull}1548[1548].
1111
- Make `service.framework` properties optional and nullable {pull}1546[1546].
12+
- Add `transaction.sampled` to errors {pull}1662[1662].
1213

1314
[float]
1415
==== Bug fixes

docs/data/elasticsearch/generated/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@
491491
"id": "0123456789abcdeffedcba0123456789"
492492
},
493493
"transaction": {
494-
"id": "1234567890987654"
494+
"id": "1234567890987654",
495+
"sampled": true
495496
}
496497
}
497498
]

docs/fields.asciidoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,16 @@ format: url
740740
The transaction ID.
741741
742742
743+
--
744+
745+
*`transaction.sampled`*::
746+
+
747+
--
748+
type: boolean
749+
750+
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context.
751+
752+
743753
--
744754
745755
@@ -1527,16 +1537,6 @@ type: object
15271537
15281538
--
15291539
1530-
*`transaction.sampled`*::
1531-
+
1532-
--
1533-
type: boolean
1534-
1535-
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context. Defaults to true.
1536-
1537-
1538-
--
1539-
15401540
15411541
15421542
*`transaction.span_count.dropped.total`*::

docs/spec/errors/v2_error.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
"description": "Hex encoded 64 random bits ID of the parent transaction or span. Must be present if trace_id and transaction_id are set.",
2828
"type": ["string", "null"],
2929
"maxLength": 1024
30+
},
31+
"transaction": {
32+
"type": ["object", "null"],
33+
"description": "Data for correlating errors with transactions",
34+
"properties": {
35+
"sampled": {
36+
"type": ["boolean", "null"],
37+
"description": "Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have 'spans' or 'context'. Defaults to true."
38+
}
39+
}
3040
}
3141
},
3242
"allOf": [

include/fields.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/error/event.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Event struct {
7474
TraceId *string
7575
ParentId *string
7676

77+
TransactionSampled *bool
78+
7779
data common.MapStr
7880
v2Event bool
7981
}
@@ -119,6 +121,7 @@ func V2DecodeEvent(input interface{}, err error) (transform.Transformable, error
119121
e.TransactionId = decoder.StringPtr(raw, "transaction_id")
120122
e.ParentId = decoder.StringPtr(raw, "parent_id")
121123
e.TraceId = decoder.StringPtr(raw, "trace_id")
124+
e.TransactionSampled = decoder.BoolPtr(raw, "sampled", "transaction")
122125
return e, decoder.Err
123126
}
124127

@@ -196,7 +199,13 @@ func (e *Event) Transform(tctx *transform.Context) []beat.Event {
196199
}
197200
tctx.Metadata.Merge(fields)
198201

199-
utility.AddId(fields, "transaction", e.TransactionId)
202+
if e.TransactionSampled != nil || (e.TransactionId != nil && *e.TransactionId != "") {
203+
transaction := common.MapStr{}
204+
utility.Add(transaction, "id", e.TransactionId)
205+
utility.Add(transaction, "sampled", e.TransactionSampled)
206+
utility.Add(fields, "transaction", transaction)
207+
}
208+
200209
utility.AddId(fields, "parent", e.ParentId)
201210
utility.AddId(fields, "trace", e.TraceId)
202211

model/error/event_test.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,11 @@ func TestVersionedErrorEventDecode(t *testing.T) {
370370
timestampEpoch := json.Number("1496170407154000")
371371
parentId, traceId := "0123456789abcdef", "01234567890123456789abcdefabcdef"
372372
transaction, transactionId := "01234", "abcdefabcdef0000"
373+
sampled := true
373374
input := map[string]interface{}{
374375
"timestamp": timestamp,
375376
"transaction_id": "abcdefabcdef0000",
376-
"transaction": map[string]interface{}{"id": "01234"},
377+
"transaction": map[string]interface{}{"id": "01234", "sampled": true},
377378
"parent_id": parentId,
378379
"trace_id": traceId,
379380
}
@@ -386,11 +387,12 @@ func TestVersionedErrorEventDecode(t *testing.T) {
386387

387388
// test V2
388389
e2 := &Event{
389-
Timestamp: timestampParsed,
390-
TransactionId: &transactionId,
391-
ParentId: &parentId,
392-
TraceId: &traceId,
393-
v2Event: true,
390+
Timestamp: timestampParsed,
391+
TransactionId: &transactionId,
392+
TransactionSampled: &sampled,
393+
ParentId: &parentId,
394+
TraceId: &traceId,
395+
v2Event: true,
394396
}
395397
input["timestamp"] = timestampEpoch
396398
transformable, err = V2DecodeEvent(input, nil)
@@ -566,6 +568,7 @@ func TestEvents(t *testing.T) {
566568
}
567569
exMsg := "exception message"
568570
trId := "945254c5-67a5-417e-8a4e-aa29efcbfb79"
571+
sampledTrue, sampledFalse := true, false
569572

570573
tests := []struct {
571574
Tranformable transform.Transformable
@@ -588,6 +591,23 @@ func TestEvents(t *testing.T) {
588591
},
589592
Msg: "Payload with valid Event.",
590593
},
594+
{
595+
Tranformable: &Event{Timestamp: timestamp, TransactionSampled: &sampledFalse},
596+
Output: common.MapStr{
597+
"transaction": common.MapStr{"sampled": false},
598+
"context": common.MapStr{
599+
"service": common.MapStr{
600+
"agent": common.MapStr{"name": "", "version": ""},
601+
"name": "myservice",
602+
},
603+
},
604+
"error": common.MapStr{
605+
"grouping_key": "d41d8cd98f00b204e9800998ecf8427e",
606+
},
607+
"processor": common.MapStr{"event": "error", "name": "error"},
608+
},
609+
Msg: "Payload with valid Event.",
610+
},
591611
{
592612
Tranformable: &Event{
593613
Timestamp: timestamp,
@@ -597,7 +617,8 @@ func TestEvents(t *testing.T) {
597617
Message: &exMsg,
598618
Stacktrace: m.Stacktrace{&m.StacktraceFrame{Filename: "myFile"}},
599619
},
600-
TransactionId: &trId,
620+
TransactionId: &trId,
621+
TransactionSampled: &sampledTrue,
601622
},
602623

603624
Output: common.MapStr{
@@ -625,7 +646,7 @@ func TestEvents(t *testing.T) {
625646
},
626647
},
627648
"processor": common.MapStr{"event": "error", "name": "error"},
628-
"transaction": common.MapStr{"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79"},
649+
"transaction": common.MapStr{"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79", "sampled": true},
629650
},
630651
Msg: "Payload with Event with Context.",
631652
},

model/error/generated/schema/error.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ const ModelSchema = `{
445445
"description": "Hex encoded 64 random bits ID of the parent transaction or span. Must be present if trace_id and transaction_id are set.",
446446
"type": ["string", "null"],
447447
"maxLength": 1024
448+
},
449+
"transaction": {
450+
"type": ["object", "null"],
451+
"description": "Data for correlating errors with transactions",
452+
"properties": {
453+
"sampled": {
454+
"type": ["boolean", "null"],
455+
"description": "Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have 'spans' or 'context'. Defaults to true."
456+
}
457+
}
448458
}
449459
},
450460
"allOf": [

model/transaction/_meta/fields.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
scaling_factor: 1000000
5252
dynamic: true
5353

54-
- name: sampled
55-
type: boolean
56-
description: >
57-
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context. Defaults to true.
5854

5955
- name: span_count
6056
type: group

0 commit comments

Comments
 (0)