Files
tasks/common/rpc/dial_tracer.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

92 lines
2.3 KiB
Go

package rpc
import (
"context"
"net/http/httptrace"
"time"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
"github.com/hanzoai/tasks/common/metrics"
)
type dialTracer struct {
address string
metricsHandler metrics.Handler
logger log.Logger
}
// newDialTracer creates a dial tracer that logs errors during dial and produces metrics for different stages of the dial process (Connect)
func newDialTracer(
address string,
mh metrics.Handler,
logger log.Logger,
) *dialTracer {
l := log.With(
logger,
tag.String("service", "client"),
tag.String("address", address),
)
return &dialTracer{
address: address,
metricsHandler: mh,
logger: l,
}
}
func (d *dialTracer) beginNetworkDial(ctx context.Context) (context.Context, *networkDialTrace) {
ndt := &networkDialTrace{startedAt: time.Now()}
// Build a ClientTrace capturing TCP connections.
trace := &httptrace.ClientTrace{
ConnectStart: func(_, _ string) {
ndt.connectStart = time.Now()
},
ConnectDone: func(_ string, addr string, err error) {
// ConnectStart may not have been called if the address is reused
if !ndt.connectStart.IsZero() {
ndt.connectDuration = time.Since(ndt.connectStart)
}
ndt.connectAddr = addr
ndt.connectErr = err
},
}
return httptrace.WithClientTrace(ctx, trace), ndt
}
func (d *dialTracer) endNetworkDial(ndt *networkDialTrace, dialErr error) {
total := time.Since(ndt.startedAt)
if dialErr != nil {
fields := []tag.Tag{
tag.Duration("totalDuration", total),
tag.Error(dialErr),
tag.ErrorType(dialErr),
tag.Duration("connectDuration", ndt.connectDuration),
tag.String("connectAddr", ndt.connectAddr),
}
if ndt.connectErr != nil {
fields = append(fields, tag.String("connectErr", ndt.connectErr.Error()))
}
d.logger.Warn("network dial error", fields...)
metrics.ServiceDialErrorCount.With(d.metricsHandler).Record(1)
} else {
metrics.ServiceDialSuccessCount.With(d.metricsHandler).Record(1)
}
if ndt.connectDuration > 0 {
metrics.ServiceDialLatency.With(d.metricsHandler).Record(ndt.connectDuration)
}
}
type networkDialTrace struct {
startedAt time.Time
connectStart time.Time
connectDuration time.Duration
connectAddr string
connectErr error
}