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 optional field transaction.sampled #441

Merged
merged 5 commits into from
Jan 5, 2018
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
1 change: 1 addition & 0 deletions docs/data/elasticsearch/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
},
"name": "GET /api/types",
"result": "success",
"sampled": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove from the minimal example as it is not a required field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a minimal example?

"type": "request"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"service": {
"name": "service1",
"agent": {
"name": "python",
"version": "1.0"
"name": "python",
"version": "1.0"
}
},
"transactions": [
Expand All @@ -15,4 +15,4 @@
"timestamp": "2017-05-09T15:04:05.999999Z"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"service": {
"name": "service1",
"agent": {
"name": "python",
"version": "1.0"
"name": "python",
"version": "1.0"
},
"language": {
"name": "javascript"
"name": "javascript"
}
},
"transactions": [
Expand All @@ -18,4 +18,4 @@
"timestamp": "2017-05-30T18:53:27.154Z"
}
]
}
}
6 changes: 3 additions & 3 deletions docs/data/intake-api/generated/transaction/minimal_span.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"service": {
"name": "service1",
"agent": {
"name": "python",
"version": "1.0"
"name": "python",
"version": "1.0"
}
},
"transactions": [
Expand All @@ -23,4 +23,4 @@
]
}
]
}
}
6 changes: 5 additions & 1 deletion docs/data/intake-api/generated/transaction/null_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
"timestamp": "2017-05-30T18:53:27.154Z",
"result": "200",
"context": null,
"spans": null
"spans": null,
"sampled": null
},
{
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
"name": "GET /api/types",
"type": "request",
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42Z",
"sampled": null,
"context": {
"request": null,
"response": null,
Expand All @@ -53,6 +55,7 @@
"type": "request",
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": null,
"context": {
"request": {
"socket": null,
Expand Down Expand Up @@ -93,6 +96,7 @@
"type": "request",
"duration": 13.980558,
"timestamp": "2017-05-30T18:53:42.281Z",
"sampled": null,
"context": {
"request": {
"socket": {
Expand Down
8 changes: 6 additions & 2 deletions docs/data/intake-api/generated/transaction/payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"duration": 32.592981,
"result": "success",
"timestamp": "2017-05-30T18:53:27.154Z",
"sampled": true,
"context": {
"request": {
"socket": {
Expand Down Expand Up @@ -195,15 +196,17 @@
"duration": 13.980558,
"result": "failure",
"timestamp": "2017-05-30T18:53:42.281Z",
"spans": []
"spans": [],
"sampled": true
},
{
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
"name": "GET /api/types",
"type": "request",
"duration": 13.980558,
"result": "200",
"timestamp": "2017-05-30T18:53:42Z"
"timestamp": "2017-05-30T18:53:42Z",
"sampled": false
},
{
"id": "85925e55-b43f-4340-a8e0-df1906ecbfa9",
Expand All @@ -212,6 +215,7 @@
"duration": 13.980558,
"result": "200",
"timestamp": "2017-05-30T18:53:42.281999Z",
"sampled": true,
"spans": [
{
"name": "SELECT FROM product_types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"spans": []
}
]
}
}
8 changes: 8 additions & 0 deletions docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ type: object
A user-defined mapping of groups of marks.


[float]
=== `transaction.sampled`

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.


[[exported-fields-beat]]
== Beat fields

Expand Down
4 changes: 4 additions & 0 deletions docs/spec/transactions/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
}
},
"additionalProperties": false
},
"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."
}
},
"required": ["id", "name", "duration", "type", "timestamp"]
Expand Down
4 changes: 4 additions & 0 deletions processor/transaction/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
description: >
A user-defined mapping of groups of marks.

- name: sampled
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.

- key: apm-span
title: APM Span
Expand Down
8 changes: 8 additions & 0 deletions processor/transaction/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Event struct {
Context common.MapStr
Spans []Span
Marks common.MapStr
Sampled *bool
}

func (t *Event) DocType() string {
Expand All @@ -32,6 +33,13 @@ func (t *Event) Transform() common.MapStr {
enh.Add(tx, "type", t.Type)
enh.Add(tx, "result", t.Result)
enh.Add(tx, "marks", t.Marks)

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

return tx
}

Expand Down
4 changes: 4 additions & 0 deletions processor/transaction/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestEventTransform(t *testing.T) {

id := "123"
result := "tx result"
sampled := false

tests := []struct {
Event Event
Expand All @@ -29,6 +30,7 @@ func TestEventTransform(t *testing.T) {
"name": "",
"type": "",
"duration": common.MapStr{"us": 0},
"sampled": true,
},
Msg: "Empty Event",
},
Expand All @@ -42,13 +44,15 @@ func TestEventTransform(t *testing.T) {
Duration: 65.98,
Context: common.MapStr{"foo": "bar"},
Spans: []Span{},
Sampled: &sampled,
},
Output: common.MapStr{
"id": id,
"name": "mytransaction",
"type": "tx",
"result": "tx result",
"duration": common.MapStr{"us": 65980},
"sampled": false,
},
Msg: "Full Event",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
},
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
},
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
},
"name": "GET /api/types",
"result": "success",
"sampled": true,
"type": "request"
}
},
Expand Down Expand Up @@ -331,6 +332,7 @@
"id": "85925e55-b43f-4340-a8e0-df1906ecbf7a",
"name": "GET /api/types",
"result": "failure",
"sampled": true,
"type": "request"
}
},
Expand Down Expand Up @@ -381,6 +383,7 @@
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
"name": "GET /api/types",
"result": "200",
"sampled": false,
"type": "request"
}
},
Expand Down Expand Up @@ -431,6 +434,7 @@
"id": "85925e55-b43f-4340-a8e0-df1906ecbfa9",
"name": "GET /api/types",
"result": "200",
"sampled": true,
"type": "request"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79",
"name": "GET /api/types",
"result": "200",
"sampled": true,
"type": "request"
}
},
Expand Down Expand Up @@ -59,6 +60,7 @@
},
"id": "85925e55-b43f-4340-a8e0-df1906ecbf78",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
},
Expand Down Expand Up @@ -118,6 +120,7 @@
},
"id": "85925e55-b43f-4340-a8e0-df1906ecbfa9",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
},
Expand Down Expand Up @@ -177,6 +180,7 @@
},
"id": "85925e55-b43f-4340-a8e0-df1906ecbf7a",
"name": "GET /api/types",
"sampled": true,
"type": "request"
}
},
Expand Down
3 changes: 3 additions & 0 deletions processor/transaction/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": true,
},
}

Expand All @@ -55,6 +56,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": true,
},
"context": common.MapStr{
"system": common.MapStr{
Expand All @@ -79,6 +81,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": true,
},
"context": common.MapStr{
"foo": "bar", "user": common.MapStr{"id": "55"},
Expand Down
4 changes: 4 additions & 0 deletions processor/transaction/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ var transactionSchema = `{
}
},
"additionalProperties": false
},
"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."
}
},
"required": ["id", "name", "duration", "type", "timestamp"]
Expand Down
6 changes: 3 additions & 3 deletions tests/data/valid/transaction/minimal_payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"service": {
"name": "service1",
"agent": {
"name": "python",
"version": "1.0"
"name": "python",
"version": "1.0"
}
},
"transactions": [
Expand All @@ -15,4 +15,4 @@
"timestamp": "2017-05-09T15:04:05.999999Z"
}
]
}
}
Loading