Skip to content

Commit

Permalink
Implement resource serialization for stdoutlog (#5213)
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM authored Apr 22, 2024
1 parent 6e92163 commit 9370c5a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions exporters/stdout/stdoutlog/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -219,7 +219,7 @@ func getPrettyJSON(now time.Time) string {
"TraceID": "0102030405060708090a0b0c0d0e0f10",
"SpanID": "0102030405060708",
"TraceFlags": "01",
"Resource": {},
"Resource": null,
"Scope": {
"Name": "",
"Version": "",
Expand Down
5 changes: 3 additions & 2 deletions exporters/stdout/stdoutlog/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}

Expand Down

0 comments on commit 9370c5a

Please sign in to comment.