Skip to content

Commit

Permalink
[v2] Require span_count.total on transactions.
Browse files Browse the repository at this point in the history
implements elastic#1241
  • Loading branch information
simitt committed Sep 3, 2018
1 parent 1c3b7d7 commit 584a3b1
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 69 deletions.
14 changes: 0 additions & 14 deletions docs/spec/transactions/common_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@
"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": ["integer","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["duration", "type"]
Expand Down
14 changes: 14 additions & 0 deletions docs/spec/transactions/v1_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
"$ref": "./../spans/v1_span.json"
},
"minItems": 0
},
"span_count": {
"type": ["object", "null"],
"properties": {
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["integer","null"],
"description": "number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["id"]
Expand Down
22 changes: 21 additions & 1 deletion docs/spec/transactions/v2_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@
"description": "Hex encoded 64 random bits ID of the parent transaction or span.",
"type": ["string", "null"],
"maxLength": 1024
},
"span_count": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"description": "Number of correlated spans that are recorded."

},
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["integer","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
},
"required": ["total"]
}
},
"required": ["id", "trace_id"]
"required": ["id", "trace_id","span_count"]
}
]
}
20 changes: 13 additions & 7 deletions model/transaction/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Event struct {
}
type SpanCount struct {
Dropped Dropped
Total *int
}
type Dropped struct {
Total *int
Expand Down Expand Up @@ -145,7 +146,9 @@ func decodeEvent(input interface{}, err error) (*Event, map[string]interface{},
Context: decoder.MapStr(raw, "context"),
Marks: decoder.MapStr(raw, "marks"),
Sampled: decoder.BoolPtr(raw, "sampled"),
SpanCount: SpanCount{Dropped: Dropped{Total: decoder.IntPtr(raw, "total", "span_count", "dropped")}},
SpanCount: SpanCount{
Dropped: Dropped{Total: decoder.IntPtr(raw, "total", "span_count", "dropped")},
Total: decoder.IntPtr(raw, "total", "span_count")},
}
return &e, raw, decoder.Err
}
Expand All @@ -168,13 +171,16 @@ func (t *Event) fields(tctx *transform.Context) common.MapStr {
utility.Add(tx, "sampled", t.Sampled)
}

if t.SpanCount.Dropped.Total != nil {
s := common.MapStr{
"dropped": common.MapStr{
"total": *t.SpanCount.Dropped.Total,
},
if t.SpanCount.Dropped.Total != nil || t.SpanCount.Total != nil {
spanCount := common.MapStr{}

if t.SpanCount.Dropped.Total != nil {
utility.Add(spanCount, "dropped", common.MapStr{"total": *t.SpanCount.Dropped.Total})
}
if t.SpanCount.Total != nil {
utility.Add(spanCount, "total", *t.SpanCount.Total)
}
utility.Add(tx, "span_count", s)
utility.Add(tx, "span_count", spanCount)
}
return tx
}
Expand Down
57 changes: 52 additions & 5 deletions model/transaction/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func TestTransactionEventDecode(t *testing.T) {
duration := 1.67
context := map[string]interface{}{"a": "b"}
marks := map[string]interface{}{"k": "b"}
dropped := 12
dropped, totalSpans := 12, 148
spanCount := map[string]interface{}{
"dropped": map[string]interface{}{
"total": 12.0,
},
"total": 148.0,
}
timestamp := "2017-05-30T18:53:27.154Z"
timestampParsed, _ := time.Parse(time.RFC3339, timestamp)
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestTransactionEventDecode(t *testing.T) {
Id: id, Type: trType, Name: &name, Result: &result,
Duration: duration, Timestamp: timestampParsed,
Context: context, Marks: marks, Sampled: &sampled,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
SpanCount: SpanCount{Total: &totalSpans, Dropped: Dropped{Total: &dropped}},
},
},
} {
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestEventTransform(t *testing.T) {
id := "123"
result := "tx result"
sampled := false
dropped := 5
dropped, total := 5, 14
name := "mytransaction"

tests := []struct {
Expand All @@ -152,6 +153,52 @@ func TestEventTransform(t *testing.T) {
},
Msg: "Empty Event",
},
{
Event: Event{
Id: id,
Type: "tx",
Duration: 65.98,
},
Output: common.MapStr{
"id": id,
"type": "tx",
"duration": common.MapStr{"us": 65980},
"sampled": true,
},
Msg: "SpanCount empty",
},
{
Event: Event{
Id: id,
Type: "tx",
Duration: 65.98,
SpanCount: SpanCount{Total: &total},
},
Output: common.MapStr{
"id": id,
"type": "tx",
"duration": common.MapStr{"us": 65980},
"span_count": common.MapStr{"total": 14},
"sampled": true,
},
Msg: "SpanCount only contains `total`",
},
{
Event: Event{
Id: id,
Type: "tx",
Duration: 65.98,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
},
Output: common.MapStr{
"id": id,
"type": "tx",
"duration": common.MapStr{"us": 65980},
"span_count": common.MapStr{"dropped": common.MapStr{"total": 5}},
"sampled": true,
},
Msg: "SpanCount only contains `dropped`",
},
{
Event: Event{
Id: id,
Expand All @@ -163,15 +210,15 @@ func TestEventTransform(t *testing.T) {
Context: common.MapStr{"foo": "bar"},
Spans: []*span.Event{},
Sampled: &sampled,
SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}},
SpanCount: SpanCount{Total: &total, Dropped: Dropped{Total: &dropped}},
},
Output: common.MapStr{
"id": id,
"name": "mytransaction",
"type": "tx",
"result": "tx result",
"duration": common.MapStr{"us": 65980},
"span_count": common.MapStr{"dropped": common.MapStr{"total": 5}},
"span_count": common.MapStr{"total": 14, "dropped": common.MapStr{"total": 5}},
"sampled": false,
},
Msg: "Full Event",
Expand Down
28 changes: 14 additions & 14 deletions model/transaction/generated/schema/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,6 @@ const PayloadSchema = `{
"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": ["integer","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["duration", "type"] },
Expand Down Expand Up @@ -595,6 +581,20 @@ const PayloadSchema = `{
]
},
"minItems": 0
},
"span_count": {
"type": ["object", "null"],
"properties": {
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["integer","null"],
"description": "number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["id"]
Expand Down
36 changes: 21 additions & 15 deletions model/transaction/generated/schema/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,6 @@ const ModelSchema = `{
"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": ["integer","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
}
}
},
"required": ["duration", "type"] },
Expand All @@ -288,9 +274,29 @@ const ModelSchema = `{
"description": "Hex encoded 64 random bits ID of the parent transaction or span.",
"type": ["string", "null"],
"maxLength": 1024
},
"span_count": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"description": "Number of correlated spans that are recorded."
},
"dropped": {
"type": ["object", "null"],
"properties": {
"total": {
"type": ["integer","null"],
"description": "Number of spans that have been dropped by the agent recording the transaction."
}
}
}
},
"required": ["total"]
}
},
"required": ["id", "trace_id"]
"required": ["id", "trace_id","span_count"]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
"id": "abcdef1478523690",
"result": "200",
"sampled": true,
"span_count": {
"total": 0
},
"trace_id": "01234567890123456789abcdefabcdef",
"type": "request"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"id": "1111222233334444",
"name": "tx1",
"sampled": true,
"span_count": {
"total": 14
},
"trace_id": "abcdefabcdef01234567890123456789",
"type": "request"
}
Expand Down
Loading

0 comments on commit 584a3b1

Please sign in to comment.