mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package interceptor
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hanzoai/tasks/common/api"
|
|
"github.com/hanzoai/tasks/common/dynamicconfig"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/rpc/interceptor/logtags"
|
|
"github.com/hanzoai/tasks/common/tasktoken"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type SlowRequestLoggerInterceptor struct {
|
|
logger log.Logger
|
|
workflowTags *logtags.WorkflowTags
|
|
slowRequestThreshold dynamicconfig.DurationPropertyFn
|
|
}
|
|
|
|
func NewSlowRequestLoggerInterceptor(
|
|
logger log.Logger,
|
|
slowRequestThreshold dynamicconfig.DurationPropertyFn,
|
|
) *SlowRequestLoggerInterceptor {
|
|
return &SlowRequestLoggerInterceptor{
|
|
logger: logger,
|
|
workflowTags: logtags.NewWorkflowTags(tasktoken.NewSerializer(), logger),
|
|
slowRequestThreshold: slowRequestThreshold,
|
|
}
|
|
}
|
|
|
|
func (i *SlowRequestLoggerInterceptor) Intercept(
|
|
ctx context.Context,
|
|
request any,
|
|
info *grpc.UnaryServerInfo,
|
|
handler grpc.UnaryHandler,
|
|
) (any, error) {
|
|
// Long-polled methods aren't useful logged.
|
|
if api.GetMethodMetadata(info.FullMethod).Polling == api.PollingNone {
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
elapsed := time.Since(startTime)
|
|
if elapsed > i.slowRequestThreshold() {
|
|
i.logSlowRequest(request, info, elapsed)
|
|
}
|
|
}()
|
|
}
|
|
|
|
return handler(ctx, request)
|
|
}
|
|
|
|
func (i *SlowRequestLoggerInterceptor) logSlowRequest(
|
|
request any,
|
|
info *grpc.UnaryServerInfo,
|
|
elapsed time.Duration,
|
|
) {
|
|
method := info.FullMethod
|
|
|
|
tags := i.workflowTags.Extract(request, method)
|
|
tags = append(tags, tag.Duration("duration", elapsed))
|
|
tags = append(tags, tag.String("method", method))
|
|
|
|
i.logger.Warn("Slow gRPC call", tags...)
|
|
}
|