Skip to content

Commit

Permalink
model/modeldecoder: {span,transaction}.outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Aug 11, 2020
1 parent 5974fa5 commit 17317c9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions model/modeldecoder/field/rum_v3_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var rumV3Mapping = map[string]string{
"module": "mo",
"name": "n",
"navigationTiming": "nt",
"outcome": "o",
"page": "p",
"param_message": "pmg",
"parent_id": "pid",
Expand Down
1 change: 1 addition & 0 deletions model/modeldecoder/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func decodeSpan(input Input, schema *jsonschema.Schema) (_ *model.Span, parentIn
decodeString(raw, fieldName("parent_id"), &event.ParentID)
decodeString(raw, fieldName("trace_id"), &event.TraceID)
decodeString(raw, fieldName("transaction_id"), &event.TransactionID)
decodeString(raw, fieldName("outcome"), &event.Outcome)

ctx := decoder.MapStr(raw, fieldName("context"))
if ctx != nil {
Expand Down
7 changes: 7 additions & 0 deletions model/modeldecoder/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestDecodeSpan(t *testing.T) {
instance, statement, dbType, user, link, rowsAffected := "db01", "select *", "sql", "joe", "other.db.com", 34
address, port := "localhost", 8080
destServiceType, destServiceName, destServiceResource := "db", "elasticsearch", "elasticsearch"
outcome := "success"
context := map[string]interface{}{
"a": "b",
"tags": map[string]interface{}{"a": "tag", "tag_key": 17},
Expand Down Expand Up @@ -191,6 +192,7 @@ func TestDecodeSpan(t *testing.T) {
"name": name, "type": "messaging", "subtype": subtype, "action": action, "start": start,
"duration": duration, "context": context, "timestamp": timestampEpoch, "stacktrace": stacktrace,
"id": id, "parent_id": parentID, "trace_id": traceID, "transaction_id": transactionID,
"outcome": outcome,
},
e: &m.Span{
Metadata: metadata,
Expand All @@ -201,6 +203,7 @@ func TestDecodeSpan(t *testing.T) {
Start: &start,
Duration: duration,
Timestamp: spanTime,
Outcome: outcome,
Stacktrace: m.Stacktrace{
&m.StacktraceFrame{Filename: tests.StringPtr("file")},
},
Expand Down Expand Up @@ -296,6 +299,10 @@ func TestDecodeSpanInvalid(t *testing.T) {
input: map[string]interface{}{"duration": -1.0},
err: "duration.*must be >= 0 but found -1",
},
"invalid outcome": {
input: map[string]interface{}{"outcome": `¯\_(ツ)_/¯`},
err: `outcome.*must be one of <nil>, "success", "failure", "unknown"`,
},
} {
t.Run(name, func(t *testing.T) {
input := make(map[string]interface{})
Expand Down
1 change: 1 addition & 0 deletions model/modeldecoder/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func decodeTransaction(input Input, schema *jsonschema.Schema) (*model.Transacti
decodeString(raw, fieldName("type"), &e.Type)
decodeString(raw, fieldName("name"), &e.Name)
decodeString(raw, fieldName("result"), &e.Result)
decodeString(raw, fieldName("outcome"), &e.Outcome)
decodeFloat64(raw, fieldName("duration"), &e.Duration)
if e.Timestamp.IsZero() {
e.Timestamp = input.RequestTime
Expand Down
17 changes: 13 additions & 4 deletions model/modeldecoder/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import (
)

var (
trID = "123"
trType = "type"
trName = "foo()"
trResult = "555"
trID = "123"
trType = "type"
trName = "foo()"
trResult = "555"
trOutcome = "success"

trDuration = 6.0

Expand Down Expand Up @@ -68,6 +69,7 @@ var fullTransactionInput = map[string]interface{}{
"duration": trDuration,
"timestamp": timestampEpoch,
"result": trResult,
"outcome": trOutcome,
"sampled": true,
"trace_id": traceID,
"parent_id": parentID,
Expand Down Expand Up @@ -118,6 +120,10 @@ func TestDecodeTransactionInvalid(t *testing.T) {
input: map[string]interface{}{"duration": -1.0},
err: "duration.*must be >= 0 but found -1",
},
"invalid outcome": {
input: map[string]interface{}{"outcome": `¯\_(ツ)_/¯`},
err: `outcome.*must be one of <nil>, "success", "failure", "unknown"`,
},
} {
t.Run(name, func(t *testing.T) {
input := make(map[string]interface{})
Expand Down Expand Up @@ -164,6 +170,7 @@ func TestTransactionDecodeRUMV3Marks(t *testing.T) {

func TestTransactionEventDecode(t *testing.T) {
id, trType, name, result := "123", "type", "foo()", "555"
outcome := "success"
requestTime := time.Now()
timestampParsed := time.Date(2017, 5, 30, 18, 53, 27, 154*1e6, time.UTC)
timestampEpoch := json.Number(fmt.Sprintf("%d", timestampParsed.UnixNano()/1000))
Expand Down Expand Up @@ -299,6 +306,7 @@ func TestTransactionEventDecode(t *testing.T) {
input: map[string]interface{}{
"timestamp": timestampEpoch,
"result": result,
"outcome": outcome,
"sampled": sampled,
"parent_id": parentID,
"marks": marks,
Expand All @@ -325,6 +333,7 @@ func TestTransactionEventDecode(t *testing.T) {
Type: trType,
Name: name,
Result: result,
Outcome: outcome,
ParentID: parentID,
TraceID: traceID,
Duration: duration,
Expand Down

0 comments on commit 17317c9

Please sign in to comment.