Skip to content

Commit

Permalink
chore: support otel logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ucpr committed Jul 13, 2024
1 parent 40b8525 commit 16e4fcb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/google/wire v0.5.0
github.com/hamba/avro/v2 v2.18.0
github.com/prometheus/client_golang v1.17.0
github.com/remychantenay/slog-otel v1.3.2
github.com/sethvargo/go-envconfig v1.0.1
github.com/stretchr/testify v1.9.0
go.mongodb.org/mongo-driver v1.13.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/remychantenay/slog-otel v1.3.2 h1:ZBx8qnwfLJ6e18Vba4e9Xp9B7khTmpIwFsU1sAmActw=
github.com/remychantenay/slog-otel v1.3.2/go.mod h1:gKW4tQ8cGOKoA+bi7wtYba/tcJ6Tc9XyQ/EW8gHA/2E=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
Expand Down
10 changes: 10 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"runtime"
"strings"

slogotel "github.com/remychantenay/slog-otel"
)

//nolint:gochecknoglobals
Expand All @@ -30,6 +32,8 @@ const (
formatJSON format = "json"
// formatText is the text format.
formatText format = "text"
// formatOtel is the OpenTelemetry format.
formatOtel format = "otel"
)

// logger is the global logger.
Expand Down Expand Up @@ -78,6 +82,12 @@ func newHandler(opts newHandlerOptions) slog.Handler {
Level: SeverityInfo,
ReplaceAttr: attrReplacerForDefault,
})
case formatOtel:
return slogotel.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
Level: SeverityInfo,
ReplaceAttr: attrReplacerForDefault,
}))
}

return slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Expand Down

0 comments on commit 16e4fcb

Please sign in to comment.