Skip to content

Commit

Permalink
Support dropped span_count on transactions. (elastic#448)
Browse files Browse the repository at this point in the history
Adds count to index.

closes elastic#280.
  • Loading branch information
simitt committed Jan 8, 2018
1 parent 120bd45 commit 2032e04
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ https://github.com/elastic/apm-server/compare/71df0d96445df35afe27f38bcf734a0828
- Support for `transaction.marks` {pull}430[430]
- Support for sourcemap mapping on incoming frontend requests {pull}381[381]
- Support for `transaction.marks` {pull}430[430].
- Support for `transaction.span_count.dropped.total` {pull}448[448].

==== Deprecated

Expand Down
5 changes: 5 additions & 0 deletions docs/data/elasticsearch/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
"name": "GET /api/types",
"result": "success",
"sampled": true,
"span_count": {
"dropped": {
"total": 2
}
},
"type": "request"
}
}
12 changes: 11 additions & 1 deletion docs/data/intake-api/generated/transaction/null_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"result": "200",
"context": null,
"spans": null,
"sampled": null
"sampled": null,
"span_count": null
},
{
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
Expand All @@ -42,6 +43,7 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42Z",
"sampled": null,
"span_count": {},
"context": {
"request": null,
"response": null,
Expand All @@ -57,6 +59,9 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": null,
"span_count": {
"dropped": null
},
"context": {
"request": {
"socket": null,
Expand Down Expand Up @@ -98,6 +103,11 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281Z",
"sampled": null,
"span_count": {
"dropped": {
"total": null
}
},
"context": {
"request": {
"socket": {
Expand Down
10 changes: 10 additions & 0 deletions docs/data/intake-api/generated/transaction/payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"result": "success",
"timestamp": "2017-05-30T18:53:27.154Z",
"sampled": true,
"span_count": {
"dropped": {
"total": 2
}
},
"context": {
"request": {
"socket": {
Expand Down Expand Up @@ -218,6 +223,11 @@
"result": "200",
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": true,
"span_count": {
"dropped": {
"total": 258
}
},
"spans": [
{
"name": "SELECT FROM product_types",
Expand Down
9 changes: 9 additions & 0 deletions docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,15 @@ type: boolean
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context. Defaults to true.
[float]
=== `transaction.span_count.dropped.total`
type: long
The total amount of dropped spans for this transaction.
[[exported-fields-beat]]
== Beat fields
Expand Down
14 changes: 14 additions & 0 deletions docs/spec/transactions/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@
"sampled": {
"type": ["boolean", "null"],
"description": "Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have 'spans' or 'context'. Defaults to true."
},
"span_count": {
"type": ["object", "null"],
"properties": {
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["number","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["id", "name", "duration", "type", "timestamp"]
Expand Down
10 changes: 10 additions & 0 deletions processor/transaction/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
type: boolean
description: >
Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have spans or context. Defaults to true.
- name: span_count
type: group
fields:
- name: dropped
type: group
fields:
- name: total
type: long
description: The total amount of dropped spans for this transaction.


- key: apm-span
title: APM Span
Expand Down
37 changes: 26 additions & 11 deletions processor/transaction/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,42 @@ type Event struct {
Spans []Span
Marks common.MapStr
Sampled *bool
SpanCount SpanCount `mapstructure:"span_count"`
}
type SpanCount struct {
Dropped Dropped
}
type Dropped struct {
Total *int
}

func (t *Event) DocType() string {
func (ev *Event) DocType() string {
return "transaction"
}

func (t *Event) Transform() common.MapStr {
func (ev *Event) Transform() common.MapStr {
enh := utility.NewMapStrEnhancer()
tx := common.MapStr{"id": t.Id}
enh.Add(tx, "name", t.Name)
enh.Add(tx, "duration", utility.MillisAsMicros(t.Duration))
enh.Add(tx, "type", t.Type)
enh.Add(tx, "result", t.Result)
enh.Add(tx, "marks", t.Marks)

if t.Sampled == nil {
tx := common.MapStr{"id": ev.Id}
enh.Add(tx, "name", ev.Name)
enh.Add(tx, "duration", utility.MillisAsMicros(ev.Duration))
enh.Add(tx, "type", ev.Type)
enh.Add(tx, "result", ev.Result)
enh.Add(tx, "marks", ev.Marks)

if ev.Sampled == nil {
enh.Add(tx, "sampled", true)
} else {
enh.Add(tx, "sampled", t.Sampled)
enh.Add(tx, "sampled", ev.Sampled)
}

if ev.SpanCount.Dropped.Total != nil {
s := common.MapStr{
"dropped": common.MapStr{
"total": *ev.SpanCount.Dropped.Total,
},
}
enh.Add(tx, "span_count", s)
}
return tx
}

Expand Down
15 changes: 9 additions & 6 deletions processor/transaction/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestEventTransform(t *testing.T) {
id := "123"
result := "tx result"
sampled := false
dropped := 5

tests := []struct {
Event Event
Expand Down Expand Up @@ -45,14 +46,16 @@ func TestEventTransform(t *testing.T) {
Context: common.MapStr{"foo": "bar"},
Spans: []Span{},
Sampled: &sampled,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
},
Output: common.MapStr{
"id": id,
"name": "mytransaction",
"type": "tx",
"result": "tx result",
"duration": common.MapStr{"us": 65980},
"sampled": false,
"id": id,
"name": "mytransaction",
"type": "tx",
"result": "tx result",
"duration": common.MapStr{"us": 65980},
"span_count": common.MapStr{"dropped": common.MapStr{"total": 5}},
"sampled": false,
},
Msg: "Full Event",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
"name": "GET /api/types",
"result": "success",
"sampled": true,
"span_count": {
"dropped": {
"total": 2
}
},
"type": "request"
}
},
Expand Down Expand Up @@ -443,6 +448,11 @@
"name": "GET /api/types",
"result": "200",
"sampled": true,
"span_count": {
"dropped": {
"total": 258
}
},
"type": "request"
}
},
Expand Down
14 changes: 14 additions & 0 deletions processor/transaction/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,20 @@ var transactionSchema = `{
"sampled": {
"type": ["boolean", "null"],
"description": "Transactions that are 'sampled' will include all available information. Transactions that are not sampled will not have 'spans' or 'context'. Defaults to true."
},
"span_count": {
"type": ["object", "null"],
"properties": {
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["number","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["id", "name", "duration", "type", "timestamp"]
Expand Down
12 changes: 11 additions & 1 deletion tests/data/valid/transaction/null_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"result": "200",
"context": null,
"spans": null,
"sampled": null
"sampled": null,
"span_count": null
},
{
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
Expand All @@ -42,6 +43,7 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42Z",
"sampled": null,
"span_count": {},
"context": {
"request": null,
"response": null,
Expand All @@ -57,6 +59,9 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": null,
"span_count": {
"dropped": null
},
"context": {
"request": {
"socket": null,
Expand Down Expand Up @@ -98,6 +103,11 @@
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281Z",
"sampled": null,
"span_count": {
"dropped": {
"total": null
}
},
"context": {
"request": {
"socket": {
Expand Down
10 changes: 10 additions & 0 deletions tests/data/valid/transaction/payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"result": "success",
"timestamp": "2017-05-30T18:53:27.154Z",
"sampled": true,
"span_count": {
"dropped": {
"total": 2
}
},
"context": {
"request": {
"socket": {
Expand Down Expand Up @@ -218,6 +223,11 @@
"result": "200",
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": true,
"span_count": {
"dropped": {
"total": 258
}
},
"spans": [
{
"name": "SELECT FROM product_types",
Expand Down

0 comments on commit 2032e04

Please sign in to comment.