Skip to content

Commit

Permalink
Do not omit empty arrays in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri Shkuro committed Jun 2, 2017
1 parent 1843ed8 commit 8c1b3e9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
23 changes: 18 additions & 5 deletions model/converter/json/fixtures/ui_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"traceID": "1",
"spanID": "2",
"operationName": "test-general-conversion",
"references": [],
"startTime": 1485467191639875,
"duration": 5,
"tags": [],
"logs": [
{
"timestamp": 1485467191639875,
Expand All @@ -29,12 +31,14 @@
]
}
],
"processID": "p1"
"processID": "p1",
"warnings": null
},
{
"traceID": "1",
"spanID": "2",
"operationName": "some-operation",
"references": [],
"startTime": 1485467191639875,
"duration": 5,
"tags": [
Expand Down Expand Up @@ -64,7 +68,9 @@
"value": "AAAwOQ=="
}
],
"processID": "p1"
"logs": [],
"processID": "p1",
"warnings": null
},
{
"traceID": "1",
Expand All @@ -79,7 +85,10 @@
],
"startTime": 1485467191639875,
"duration": 5,
"processID": "p2"
"tags": [],
"logs": [],
"processID": "p2",
"warnings": null
},
{
"traceID": "1",
Expand All @@ -104,6 +113,8 @@
],
"startTime": 1485467191639875,
"duration": 5,
"tags": [],
"logs": [],
"processID": "p2",
"warnings": [
"some span warning"
Expand All @@ -112,10 +123,12 @@
],
"processes": {
"p1": {
"serviceName": "service-x"
"serviceName": "service-x",
"tags": []
},
"p2": {
"serviceName": "service-y"
"serviceName": "service-y",
"tags": []
}
},
"warnings": [
Expand Down
20 changes: 15 additions & 5 deletions model/json/fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
"traceID": "abc0",
"spanID": "abc0",
"operationName": "root-span",
"references": null,
"startTime": 1000,
"duration": 500,
"processID": "p1"
"tags": null,
"logs": null,
"processID": "p1",
"warnings": null
},
{
"traceID": "abc0",
Expand Down Expand Up @@ -56,7 +60,8 @@
]
}
],
"processID": "p2"
"processID": "p2",
"warnings": null
},
{
"traceID": "abc0",
Expand All @@ -71,12 +76,16 @@
],
"startTime": 1000,
"duration": 500,
"processID": "p2"
"tags": null,
"logs": null,
"processID": "p2",
"warnings": null
}
],
"processes": {
"p1": {
"serviceName": "service_1"
"serviceName": "service_1",
"tags": null
},
"p2": {
"serviceName": "service_2",
Expand All @@ -88,5 +97,6 @@
}
]
}
}
},
"warnings": null
}
14 changes: 7 additions & 7 deletions model/json/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Trace struct {
TraceID TraceID `json:"traceID"`
Spans []Span `json:"spans"`
Processes map[ProcessID]Process `json:"processes"`
Warnings []string `json:"warnings,omitempty"`
Warnings []string `json:"warnings"`
}

// Span is a span denoting a piece of work in some infrastructure
Expand All @@ -72,13 +72,13 @@ type Span struct {
SpanID SpanID `json:"spanID"`
Flags uint32 `json:"flags,omitempty"`
OperationName string `json:"operationName"`
References []Reference `json:"references,omitempty"`
References []Reference `json:"references"`
StartTime uint64 `json:"startTime"` // microseconds since Unix epoch
Duration uint64 `json:"duration"` // microseconds
Tags []KeyValue `json:"tags,omitempty"`
Logs []Log `json:"logs,omitempty"`
Tags []KeyValue `json:"tags"`
Logs []Log `json:"logs"`
ProcessID ProcessID `json:"processID"`
Warnings []string `json:"warnings,omitempty"`
Warnings []string `json:"warnings"`
}

// Reference is a reference from one span to another
Expand All @@ -91,13 +91,13 @@ type Reference struct {
// Process is the process emitting a set of spans
type Process struct {
ServiceName string `json:"serviceName"`
Tags []KeyValue `json:"tags,omitempty"`
Tags []KeyValue `json:"tags"`
}

// Log is a log emitted in a span
type Log struct {
Timestamp uint64 `json:"timestamp"`
Fields []KeyValue `json:"fields,omitempty"`
Fields []KeyValue `json:"fields"`
}

// KeyValue is a a key-value pair with typed value.
Expand Down
5 changes: 4 additions & 1 deletion model/json/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func TestModel(t *testing.T) {
err = encoder.Encode(&trace)
require.NoError(t, err)

assert.Equal(t, string(in), string(out.Bytes()))
if !assert.Equal(t, string(in), string(out.Bytes())) {
err := ioutil.WriteFile("fixture-actual.json", out.Bytes(), 0644)
assert.NoError(t, err)
}
}

func TestFromFileErrors(t *testing.T) {
Expand Down

0 comments on commit 8c1b3e9

Please sign in to comment.