Skip to content

Commit

Permalink
Default 'sampled' to true
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron Cohen committed Jan 4, 2018
1 parent f38a939 commit 0680c9d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ A user-defined mapping of groups of marks.
type: boolean
Unsampled transactions have no spans.
Sampled transactions have spans. Defaults to true
[[exported-fields-beat]]
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/transactions/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
},
"sampled": {
"type": "boolean",
"description": "Sampled transactions have spans."
"description": "Sampled transactions have spans. Defaults to true."
}
},
"required": ["id", "name", "duration", "type", "timestamp", "sampled"]
"required": ["id", "name", "duration", "type", "timestamp"]
}
2 changes: 1 addition & 1 deletion processor/transaction/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
- name: sampled
type: boolean
description: >
Unsampled transactions have no spans.
Sampled transactions have spans. Defaults to true
- key: apm-span
title: APM Span
Expand Down
9 changes: 7 additions & 2 deletions processor/transaction/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Event struct {
Context common.MapStr
Spans []Span
Marks common.MapStr
Sampled bool
Sampled *bool
}

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

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

return tx
}
Expand Down
7 changes: 4 additions & 3 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,7 +30,7 @@ func TestEventTransform(t *testing.T) {
"name": "",
"type": "",
"duration": common.MapStr{"us": 0},
"sampled": false,
"sampled": true,
},
Msg: "Empty Event",
},
Expand All @@ -43,15 +44,15 @@ func TestEventTransform(t *testing.T) {
Duration: 65.98,
Context: common.MapStr{"foo": "bar"},
Spans: []Span{},
Sampled: true,
Sampled: &sampled,
},
Output: common.MapStr{
"id": id,
"name": "mytransaction",
"type": "tx",
"result": "tx result",
"duration": common.MapStr{"us": 65980},
"sampled": true,
"sampled": false,
},
Msg: "Full Event",
},
Expand Down
6 changes: 3 additions & 3 deletions processor/transaction/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": false,
"sampled": true,
},
}

Expand All @@ -56,7 +56,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": false,
"sampled": true,
},
"context": common.MapStr{
"system": common.MapStr{
Expand All @@ -81,7 +81,7 @@ func TestPayloadTransform(t *testing.T) {
"id": "",
"name": "",
"type": "",
"sampled": false,
"sampled": true,
},
"context": common.MapStr{
"foo": "bar", "user": common.MapStr{"id": "55"},
Expand Down
4 changes: 2 additions & 2 deletions processor/transaction/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@ var transactionSchema = `{
},
"sampled": {
"type": "boolean",
"description": "Sampled transactions have spans."
"description": "Sampled transactions have spans. Defaults to true."
}
},
"required": ["id", "name", "duration", "type", "timestamp", "sampled"]
"required": ["id", "name", "duration", "type", "timestamp"]
},
"minItems": 1
}
Expand Down
7 changes: 0 additions & 7 deletions tests/data/invalid/transaction/no_sampled.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func TestTransactionSchema(t *testing.T) {
{File: "no_duration.json", Error: `missing properties: "duration"`},
{File: "no_type.json", Error: `missing properties: "type"`},
{File: "no_timestamp.json", Error: `missing properties: "timestamp"`},
{File: "no_sampled.json", Error: `missing properties: "sampled"`},
{File: "invalid_id.json", Error: "[#/properties/id/pattern] does not match pattern"},
{File: "invalid_timestamp.json", Error: "is not valid \"date-time\""},
{File: "invalid_timestamp2.json", Error: "I[#/timestamp] S[#/properties/timestamp/pattern] does not match pattern"},
Expand Down

0 comments on commit 0680c9d

Please sign in to comment.