Skip to content

Commit 9370c5a

Browse files
authored
Implement resource serialization for stdoutlog (#5213)
1 parent 6e92163 commit 9370c5a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

exporters/stdout/stdoutlog/exporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestExporterExport(t *testing.T) {
174174
func getJSON(now time.Time) string {
175175
serializedNow, _ := json.Marshal(now)
176176

177-
return "{\"Timestamp\":" + string(serializedNow) + ",\"ObservedTimestamp\":" + string(serializedNow) + ",\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{},\"Attributes\":[{\"Key\":\"key\",\"Value\":{}},{\"Key\":\"key2\",\"Value\":{}},{\"Key\":\"key3\",\"Value\":{}},{\"Key\":\"key4\",\"Value\":{}},{\"Key\":\"key5\",\"Value\":{}},{\"Key\":\"bool\",\"Value\":{}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":{},\"Scope\":{\"Name\":\"\",\"Version\":\"\",\"SchemaURL\":\"\"},\"AttributeValueLengthLimit\":0,\"AttributeCountLimit\":0}\n"
177+
return "{\"Timestamp\":" + string(serializedNow) + ",\"ObservedTimestamp\":" + string(serializedNow) + ",\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{},\"Attributes\":[{\"Key\":\"key\",\"Value\":{}},{\"Key\":\"key2\",\"Value\":{}},{\"Key\":\"key3\",\"Value\":{}},{\"Key\":\"key4\",\"Value\":{}},{\"Key\":\"key5\",\"Value\":{}},{\"Key\":\"bool\",\"Value\":{}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":null,\"Scope\":{\"Name\":\"\",\"Version\":\"\",\"SchemaURL\":\"\"},\"AttributeValueLengthLimit\":0,\"AttributeCountLimit\":0}\n"
178178
}
179179

180180
func getJSONs(now time.Time) string {
@@ -219,7 +219,7 @@ func getPrettyJSON(now time.Time) string {
219219
"TraceID": "0102030405060708090a0b0c0d0e0f10",
220220
"SpanID": "0102030405060708",
221221
"TraceFlags": "01",
222-
"Resource": {},
222+
"Resource": null,
223223
"Scope": {
224224
"Name": "",
225225
"Version": "",

exporters/stdout/stdoutlog/record.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ type recordJSON struct {
2424
TraceID trace.TraceID
2525
SpanID trace.SpanID
2626
TraceFlags trace.TraceFlags
27-
Resource resource.Resource
27+
Resource *resource.Resource
2828
Scope instrumentation.Scope
2929
AttributeValueLengthLimit int
3030
AttributeCountLimit int
3131
}
3232

3333
func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
34+
res := r.Resource()
3435
newRecord := recordJSON{
3536
Severity: r.Severity(),
3637
SeverityText: r.SeverityText(),
@@ -42,7 +43,7 @@ func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
4243

4344
Attributes: make([]log.KeyValue, 0, r.AttributesLen()),
4445

45-
Resource: r.Resource(),
46+
Resource: &res,
4647
Scope: r.InstrumentationScope(),
4748
}
4849

0 commit comments

Comments
 (0)