Skip to main content

How to set ClientOptions in Go

Create an instance of Options from the go.temporal.io/sdk/client package and pass it the call to create a new Temporal Client.

FieldRequiredType
HostPortNostring
NamespaceNostring
LoggerNolog.Logger
MetricsHandlerNometrics.Handler
IdentityNostring
DataConverterNoconverter.DataConverter
ContextPropagatorsNo[]ContextPropagator
ConnectionOptionsNoConnectionOptions
HeadersProviderNoHeadersProvider
TrafficControllerNoTrafficController
InterceptorsNo[]ClientInterceptor

HostPort

How to set the Temporal Client's host:port connection in Go

clientOptions := client.Options{
HostPort: client.DefaultHostPort,
}
temporalClient, err := client.Dial(clientOptions)

The HostPort value is a gRPC address and therefore can also support a special-formatted address of <resolver>:///<value> that will use a registered resolver. By default all hosts returned from the resolver will be used in a round-robin fashion.

The "dns" resolver is registered by default. Using a dns:/// prefixed address will cause a periodic round-robin resolution of all IPs for all DNS addresses.

A custom resolver can be created to provide multiple hosts in other ways. For example, to manually provide multiple IPs to round-robin across, a google.golang.org/grpc/resolver/ manual resolver can be created and registered with a custom scheme:

builder := manual.NewBuilderWithScheme("myresolver")
builder.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: "1.2.3.4:1234"},{Addr: "2.3.4.5:2345"}}})
resolver.Register(builder)
temporalClient, err := client.Dial(client.Options{HostPort: "myresolver:///ignoredvalue"})

Other more advanced resolvers can also be registered.

Namespace

Set the Namespace field on an instance of the Client Options.

// ...
clientOptions := client.Options{
Namespace: "your-custom-namespace",
}
temporalClient, err := client.Dial(clientOptions)
// ...

Logger

How to use a custom logger in Go

This field sets a custom Logger that is used for all logging actions of the instance of the Temporal Client.

Although the Go SDK does not support most third-party logging solutions natively, our friends at Banzai Cloud built the adapter package logur which makes it possible to use third party loggers with minimal overhead. Most of the popular logging solutions have existing adapters in Logur, but you can find a full list in the Logur Github project.

Here is an example of using Logur to support Logrus:

package main
import (
"go.temporal.io/sdk/client"

"github.com/sirupsen/logrus"
logrusadapter "logur.dev/adapter/logrus"
"logur.dev/logur"
)

func main() {
// ...
logger := logur.LoggerToKV(logrusadapter.New(logrus.New()))
clientOptions := client.Options{
Logger: logger,
}
temporalClient, err := client.Dial(clientOptions)
// ...
}

MetricsHandler

Sets the metric scope, which metrics should be reported

Identity

Sets an identify that can be used to track this host for debugging

DataConverter

Sets DataConverter to customize serialization/deserialization of arguments in Temporal

ContextPropagators

Sets ContextPropagators that allows users to control the context information passed through a Workflow

  • Type: []ContextPropagator

ConnectionOptions

Sets options for server connection that allow users to control features of connections such as TLS settings

  • Type: ConnectionOptions

HeadersProvider

Sets custom request headers

  • Type: HeadersProvider

TrafficController

Set to induce artificial failures in test scenarios

  • Type: TrafficController

Interceptors