MCPcopy Index your code
hub / github.com/coder/coder / LogEntry

Method LogEntry

coderd/tracing/slog.go:21–42  ·  view source on GitHub ↗

LogEntry implements slog.Sink. All entries are added as events to the span in the context. If no span is present, the entry is dropped.

(ctx context.Context, e slog.SinkEntry)

Source from the content-addressed store, hash-verified

19// LogEntry implements slog.Sink. All entries are added as events to the span
20// in the context. If no span is present, the entry is dropped.
21func (SlogSink) LogEntry(ctx context.Context, e slog.SinkEntry) {
22 span := trace.SpanFromContext(ctx)
23 if !span.IsRecording() {
24 // If the span is a noopSpan or isn't recording, we don't want to
25 // compute the attributes (which is expensive) below.
26 return
27 }
28
29 attributes := []attribute.KeyValue{
30 attribute.String("slog.time", e.Time.Format(time.RFC3339Nano)),
31 attribute.String("slog.logger", strings.Join(e.LoggerNames, ".")),
32 attribute.String("slog.level", e.Level.String()),
33 attribute.String("slog.message", e.Message),
34 attribute.String("slog.func", e.Func),
35 attribute.String("slog.file", e.File),
36 attribute.Int64("slog.line", int64(e.Line)),
37 }
38 attributes = append(attributes, slogFieldsToAttributes(e.Fields)...)
39
40 name := fmt.Sprintf("log: %s: %s", e.Level, e.Message)
41 span.AddEvent(name, trace.WithAttributes(attributes...))
42}
43
44// Sync implements slog.Sink. No-op as syncing is handled externally by otel.
45func (SlogSink) Sync() {}

Callers 1

Test_SlogSinkFunction · 0.95

Calls 6

slogFieldsToAttributesFunction · 0.85
IsRecordingMethod · 0.80
Int64Method · 0.80
AddEventMethod · 0.80
FormatMethod · 0.65
StringMethod · 0.45

Tested by 1

Test_SlogSinkFunction · 0.76