MCPcopy Index your code
hub / github.com/coder/slog / TestStackdriver

Function TestStackdriver

sloggers/slogstackdriver/slogstackdriver_test.go:29–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestStackdriver(t *testing.T) {
30 t.Parallel()
31
32 tp := sdktrace.NewTracerProvider()
33 tracer := tp.Tracer("tracer")
34 ctx, span := tracer.Start(bg, "trace")
35 span.End()
36 _ = tp.Shutdown(bg)
37 b := &bytes.Buffer{}
38 l := slog.Make(slogstackdriver.Sink(b))
39 l = l.Named("meow")
40 l.Error(ctx, "line1\n\nline2", slog.F("wowow", "me\nyou"))
41
42 projectID, _ := metadataClient(t).ProjectID()
43
44 j := entryjson.Filter(b.String(), "timestampSeconds")
45 j = entryjson.Filter(j, "timestampNanos")
46 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/v3/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"}
47`, slogstackdriverTestFile, projectID, span.SpanContext().TraceID(), span.SpanContext().SpanID(), span.SpanContext().IsSampled())
48 assert.Equal(t, "entry", exp, j)
49}
50
51func TestSevMapping(t *testing.T) {
52 t.Parallel()

Callers

nothing calls this directly

Calls 7

SinkFunction · 0.92
FilterFunction · 0.92
EqualFunction · 0.92
metadataClientFunction · 0.85
NamedMethod · 0.80
StringMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected