Files
tasks/client/frontend/metric_client.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

68 lines
2.0 KiB
Go

package frontend
import (
"context"
"time"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"github.com/hanzoai/tasks/common/headers"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
"github.com/hanzoai/tasks/common/metrics"
)
var _ workflowservice.WorkflowServiceClient = (*metricClient)(nil)
type metricClient struct {
client workflowservice.WorkflowServiceClient
metricsHandler metrics.Handler
throttledLogger log.Logger
}
// NewMetricClient creates a new instance of workflowservice.WorkflowServiceClient that emits metrics
func NewMetricClient(
client workflowservice.WorkflowServiceClient,
metricsHandler metrics.Handler,
throttledLogger log.Logger,
) workflowservice.WorkflowServiceClient {
return &metricClient{
client: client,
metricsHandler: metricsHandler,
throttledLogger: throttledLogger,
}
}
func (c *metricClient) startMetricsRecording(
ctx context.Context,
operation string,
) (metrics.Handler, time.Time) {
caller := headers.GetCallerInfo(ctx).CallerName
handler := c.metricsHandler.WithTags(metrics.OperationTag(operation), metrics.NamespaceTag(caller), metrics.ServiceRoleTag(metrics.FrontendRoleTagValue))
metrics.ClientRequests.With(handler).Record(1)
return handler, time.Now().UTC()
}
func (c *metricClient) finishMetricsRecording(
handler metrics.Handler,
startTime time.Time,
err error,
) {
if err != nil {
switch err.(type) {
case *serviceerror.Canceled,
*serviceerror.DeadlineExceeded,
*serviceerror.NotFound,
*serviceerror.QueryFailed,
*serviceerror.NamespaceNotFound,
*serviceerror.WorkflowNotReady,
*serviceerror.WorkflowExecutionAlreadyStarted:
// noop - not interest and too many logs
default:
c.throttledLogger.Info("frontend client encountered error", tag.Error(err), tag.ServiceErrorType(err))
}
metrics.ClientFailures.With(handler).Record(1, metrics.ServiceErrorTypeTag(err))
}
metrics.ClientLatency.With(handler).Record(time.Since(startTime))
}