Skip to content

Commit 3d9d970

Browse files
committed
docs: logging example fix to go sdk observability page
1 parent bbf0705 commit 3d9d970

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

docs/develop/go/platform/observability.mdx

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,32 +158,60 @@ workflow.WithActivityOptions(ctx, ao)
158158
159159
This field sets a custom Logger that is used for all logging actions of the instance of the Temporal Client.
160160
161-
Although the Go SDK does not support most third-party logging solutions natively, [our friends at Banzai Cloud](https://github.com/sagikazarmark) built the adapter package [logur](https://github.com/logur/logur) which makes it possible to use third party loggers with minimal overhead.
162-
Most of the popular logging solutions have existing adapters in Logur, but you can find a full list [in the Logur GitHub project](https://github.com/logur?q=adapter-).
161+
The Go SDK supports custom loggers via `log.NewStructuredLogger()`, which wraps Go's standard [`slog.Logger`](https://pkg.go.dev/log/slog) (Go 1.21+).
162+
Because most modern logging libraries (zap, zerolog, logrus, etc.) can back a `slog.Handler`, `slog` serves as the universal bridge to third-party loggers.
163163
164-
Here is an example of using Logur to support [Logrus](https://github.com/sirupsen/logrus):
164+
**Using slog directly:**
165165
166166
```go
167-
package main
168167
import (
169-
"go.temporal.io/sdk/client"
168+
"log/slog"
169+
"os"
170170

171-
"github.com/sirupsen/logrus"
172-
logrusadapter "logur.dev/adapter/logrus"
173-
"logur.dev/logur"
171+
"go.temporal.io/sdk/client"
172+
"go.temporal.io/sdk/log"
174173
)
175174

176175
func main() {
177-
// ...
178-
logger := logur.LoggerToKV(logrusadapter.New(logrus.New()))
179-
clientOptions := client.Options{
180-
Logger: logger,
181-
}
182-
temporalClient, err := client.Dial(clientOptions)
183-
// ...
176+
// ...
177+
slogHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})
178+
logger := log.NewStructuredLogger(slog.New(slogHandler))
179+
clientOptions := client.Options{
180+
Logger: logger,
181+
}
182+
temporalClient, err := client.Dial(clientOptions)
183+
// ...
184184
}
185185
```
186186
187+
**Bridging a third-party logger through slog (example with zap):**
188+
189+
```go
190+
import (
191+
"log/slog"
192+
193+
"go.uber.org/zap"
194+
"go.uber.org/zap/exp/zapslog"
195+
"go.temporal.io/sdk/client"
196+
"go.temporal.io/sdk/log"
197+
)
198+
199+
func main() {
200+
// ...
201+
zapLogger, _ := zap.NewProduction()
202+
handler := zapslog.NewHandler(zapLogger.Core())
203+
logger := log.NewStructuredLogger(slog.New(handler))
204+
clientOptions := client.Options{
205+
Logger: logger,
206+
}
207+
temporalClient, err := client.Dial(clientOptions)
208+
// ...
209+
}
210+
```
211+
212+
As an alternative, you can implement the `log.Logger` interface directly.
213+
The Temporal samples repo has a [zap adapter](https://github.com/temporalio/samples-go/blob/main/zapadapter/zap_adapter.go) that can be used as a reference.
214+
187215
## Visibility APIs {#visibility}
188216
189217
The term Visibility, within the Temporal Platform, refers to the subsystems and APIs that enable an operator to view Workflow Executions that currently exist within a Temporal Service.

0 commit comments

Comments
 (0)