func event(serviceName string, methodName string, request proto.Message, response proto.Message, err error, duration time.Duration) *Call { call := &Call{ Service: serviceName, Method: methodName, Duration: prototime.DurationToProto(duration), } if request != nil { call.Request = request.String() } if response != nil { call.Response = response.String() } if err != nil { call.Error = err.Error() } return call }
func override(ctx context.Context, service, method string, in, out proto.Message) error { stats := ctx.Value(statsKey).(*requestStats) stats.wg.Add(1) defer stats.wg.Done() if service == "__go__" { return appengine.APICall(ctx, service, method, in, out) } // NOTE: This limits size of stack traces to 65KiB. b := make([]byte, 65536) i := runtime.Stack(b, false) stat := rpcStat{ Service: service, Method: method, Start: time.Now(), Offset: time.Since(stats.Start), StackData: string(b[0:i]), } err := appengine.APICall(ctx, service, method, in, out) stat.Duration = time.Since(stat.Start) stat.In = in.String() stat.Out = out.String() stat.Cost = getCost(out) if len(stat.In) > ProtoMaxBytes { stat.In = stat.In[:ProtoMaxBytes] + "..." } if len(stat.Out) > ProtoMaxBytes { stat.Out = stat.Out[:ProtoMaxBytes] + "..." } stats.lock.Lock() stats.RPCStats = append(stats.RPCStats, stat) stats.Cost += stat.Cost stats.lock.Unlock() return err }
func override(ctx context.Context, service, method string, in, out proto.Message) error { stats := stats(ctx) stats.wg.Add(1) defer stats.wg.Done() if service == "__go__" { return appengine.APICall(ctx, service, method, in, out) } stat := rpcStat{ Service: service, Method: method, Start: time.Now(), Offset: time.Since(stats.Start), StackData: string(debug.Stack()), } err := appengine.APICall(ctx, service, method, in, out) stat.Duration = time.Since(stat.Start) stat.In = in.String() stat.Out = out.String() stat.Cost = getCost(out) if len(stat.In) > ProtoMaxBytes { stat.In = stat.In[:ProtoMaxBytes] + "..." } if len(stat.Out) > ProtoMaxBytes { stat.Out = stat.Out[:ProtoMaxBytes] + "..." } stats.lock.Lock() stats.RPCStats = append(stats.RPCStats, stat) stats.Cost += stat.Cost stats.lock.Unlock() return err }