Skip to content

Commit d963b30

Browse files
committed
Add trace example
1 parent 2622d5f commit d963b30

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

example_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"testing"
99

10+
"go.opencensus.io/trace"
1011
"golang.org/x/xerrors"
1112

1213
"cdr.dev/slog"
@@ -48,26 +49,19 @@ func Example_testing() {
4849

4950
slogtest.Info(t, "my message here",
5051
slog.F("field_name", "something or the other"),
51-
slog.F("some_map", slog.M(
52-
slog.F("nested_fields", "wowow"),
53-
)),
54-
slog.Error(
55-
xerrors.Errorf("wrap1: %w",
56-
xerrors.Errorf("wrap2: %w",
57-
io.EOF,
58-
),
59-
),
60-
),
6152
)
6253

63-
// t.go:55: 2019-12-05 21:20:31.218 [INFO] <examples_test.go:42> my message here {"field_name": "something or the other", "some_map": {"nested_fields": "wowow"}} ...
64-
// "error": wrap1:
65-
// cdr.dev/slog_test.TestExample
66-
// /Users/nhooyr/src/cdr/slog/examples_test.go:48
67-
// - wrap2:
68-
// cdr.dev/slog_test.TestExample
69-
// /Users/nhooyr/src/cdr/slog/examples_test.go:49
70-
// - EOF
54+
// t.go:55: 2019-12-05 21:20:31.218 [INFO] <examples_test.go:42> my message here {"field_name": "something or the other"}
55+
}
56+
57+
func Example_tracing() {
58+
log := sloghuman.Make(os.Stdout)
59+
60+
ctx, _ := trace.StartSpan(context.Background(), "spanName")
61+
62+
log.Info(ctx, "my msg", slog.F("hello", "hi"))
63+
64+
// 2019-12-09 21:59:48.110 [INFO] <example_test.go:62> my msg {"trace": "f143d018d00de835688453d8dc55c9fd", "span": "f214167bf550afc3", "hello": "hi"}
7165
}
7266

7367
func ExampleWith() {

0 commit comments

Comments
 (0)