Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sloggers/slogstackdriver/slogstackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (s stackdriverSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
// https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/configuration#special-fields
e := slog.M(
slog.F("logging.googleapis.com/severity", sev(ent.Level)),
slog.F("severity", sev(ent.Level)),
slog.F("message", ent.Message),
// Unfortunately, both of these fields are required.
slog.F("timestampSeconds", ent.Time.Unix()),
Expand Down
2 changes: 1 addition & 1 deletion sloggers/slogstackdriver/slogstackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestStackdriver(t *testing.T) {

j := entryjson.Filter(b.String(), "timestampSeconds")
j = entryjson.Filter(j, "timestampNanos")
exp := fmt.Sprintf(`{"logging.googleapis.com/severity":"ERROR","message":"line1\n\nline2","logging.googleapis.com/sourceLocation":{"file":"%v","line":40,"function":"cdr.dev/slog/sloggers/slogstackdriver_test.TestStackdriver"},"logging.googleapis.com/operation":{"producer":"meow"},"logging.googleapis.com/trace":"projects/%v/traces/%v","logging.googleapis.com/spanId":"%v","logging.googleapis.com/trace_sampled":%v,"wowow":"me\nyou"}
exp := fmt.Sprintf(`{"logging.googleapis.com/severity":"ERROR","severity":"ERROR","message":"line1\n\nline2","logging.googleapis.com/sourceLocation":{"file":"%v","line":40,"function":"cdr.dev/slog/sloggers/slogstackdriver_test.TestStackdriver"},"logging.googleapis.com/operation":{"producer":"meow"},"logging.googleapis.com/trace":"projects/%v/traces/%v","logging.googleapis.com/spanId":"%v","logging.googleapis.com/trace_sampled":%v,"wowow":"me\nyou"}
`, slogstackdriverTestFile, projectID, span.SpanContext().TraceID(), span.SpanContext().SpanID(), span.SpanContext().IsSampled())
assert.Equal(t, "entry", exp, j)
}
Expand Down