From 9370c5a01f957e1eaf27f631cf99768e084c4cd7 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Mon, 22 Apr 2024 04:33:26 -0700 Subject: [PATCH] Implement resource serialization for stdoutlog (#5213) --- exporters/stdout/stdoutlog/exporter_test.go | 4 ++-- exporters/stdout/stdoutlog/record.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/exporters/stdout/stdoutlog/exporter_test.go b/exporters/stdout/stdoutlog/exporter_test.go index 489e5abc69e..7856b9b2fdd 100644 --- a/exporters/stdout/stdoutlog/exporter_test.go +++ b/exporters/stdout/stdoutlog/exporter_test.go @@ -174,7 +174,7 @@ func TestExporterExport(t *testing.T) { func getJSON(now time.Time) string { serializedNow, _ := json.Marshal(now) - 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" + 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" } func getJSONs(now time.Time) string { @@ -219,7 +219,7 @@ func getPrettyJSON(now time.Time) string { "TraceID": "0102030405060708090a0b0c0d0e0f10", "SpanID": "0102030405060708", "TraceFlags": "01", - "Resource": {}, + "Resource": null, "Scope": { "Name": "", "Version": "", diff --git a/exporters/stdout/stdoutlog/record.go b/exporters/stdout/stdoutlog/record.go index 134fffbe61c..868a1e88491 100644 --- a/exporters/stdout/stdoutlog/record.go +++ b/exporters/stdout/stdoutlog/record.go @@ -24,13 +24,14 @@ type recordJSON struct { TraceID trace.TraceID SpanID trace.SpanID TraceFlags trace.TraceFlags - Resource resource.Resource + Resource *resource.Resource Scope instrumentation.Scope AttributeValueLengthLimit int AttributeCountLimit int } func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON { + res := r.Resource() newRecord := recordJSON{ Severity: r.Severity(), SeverityText: r.SeverityText(), @@ -42,7 +43,7 @@ func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON { Attributes: make([]log.KeyValue, 0, r.AttributesLen()), - Resource: r.Resource(), + Resource: &res, Scope: r.InstrumentationScope(), }