-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchild.go
More file actions
39 lines (31 loc) · 789 Bytes
/
child.go
File metadata and controls
39 lines (31 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package supervisor
import (
"context"
"fmt"
"log/slog"
"github.com/wastedcode/supervisor/errors"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type Child struct {
logger *slog.Logger
span trace.Span
}
func (c Child) Log(ctx context.Context, msg string, attrs ...slog.Attr) {
c.logger.LogAttrs(ctx, slog.LevelInfo, msg, attrs...)
}
func (c Child) Debug(ctx context.Context, msg string, attrs ...slog.Attr) {
c.logger.LogAttrs(ctx, slog.LevelDebug, msg, attrs...)
}
func (c Child) End() {
c.span.End()
}
func (c Child) Error(err error) error {
if err == nil {
return nil
}
c.span.RecordError(err)
c.span.SetStatus(codes.Error, fmt.Sprintf("%s", err))
c.logger.Error(errors.FlattenDetails(err), slog.Any("err", newErrLog(err)))
return err
}