@@ -7,10 +7,13 @@ import (
7
7
"os"
8
8
)
9
9
10
- func InitLogger () {
11
- jsonHandler := slog .NewJSONHandler (os .Stdout , & slog.HandlerOptions {
12
- Level : slog .LevelInfo ,
13
- })
10
+ func InitLogger (options * slog.HandlerOptions ) {
11
+ if options == nil {
12
+ options = & slog.HandlerOptions {
13
+ Level : slog .LevelInfo ,
14
+ }
15
+ }
16
+ jsonHandler := slog .NewJSONHandler (os .Stdout , options )
14
17
// Add span context attributes when Context is passed to logging calls.
15
18
instrumentedHandler := handlerWithSpanContext (jsonHandler )
16
19
// Set this handler as the global slog handler.
@@ -33,16 +36,16 @@ func (t *spanContextLogHandler) Handle(ctx context.Context, record slog.Record)
33
36
// Get the SpanContext from the golang Context.
34
37
spanContext := trace .SpanContextFromContext (ctx )
35
38
if spanContext .IsValid () {
36
- // Add trace context attributes following Cloud Logging structured log format described
37
- // in https://cloud.google.com/logging/ docs/structured-logging#special-payload-fields
39
+ // Add trace context attributes following OpenTelemetry structured log format described
40
+ // in https://opentelemetry.io/ docs/concepts/signals/traces/
38
41
record .AddAttrs (
39
- slog .Any ("logging.googleapis.com/trace " , spanContext .TraceID ()),
42
+ slog .Any ("trace_id " , spanContext .TraceID ()),
40
43
)
41
44
record .AddAttrs (
42
- slog .Any ("logging.googleapis.com/spanId " , spanContext .SpanID ()),
45
+ slog .Any ("span_id " , spanContext .SpanID ()),
43
46
)
44
47
record .AddAttrs (
45
- slog .Bool ("logging.googleapis.com/ trace_sampled" , spanContext .TraceFlags ().IsSampled ()),
48
+ slog .Bool ("trace_sampled" , spanContext .TraceFlags ().IsSampled ()),
46
49
)
47
50
}
48
51
return t .Handler .Handle (ctx , record )
0 commit comments