Skip to content

Commit

Permalink
Ensure servicemethod is logged (#28)
Browse files Browse the repository at this point in the history
* Ensure method is logged

* Log the full method name in trace mode
  • Loading branch information
jackkleeman authored Aug 20, 2024
1 parent 558a12a commit 841b7c3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
45 changes: 44 additions & 1 deletion internal/wire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,50 @@ const (
type Type uint16

func (t Type) String() string {
return fmt.Sprintf("0x%04X", uint16(t))
switch t {
case StartMessageType:
return "StartMessage"
case CompletionMessageType:
return "CompletionMessage"
case SuspensionMessageType:
return "SuspensionMessage"
case ErrorMessageType:
return "ErrorMessage"
case EntryAckMessageType:
return "EntryAckMessage"
case EndMessageType:
return "EndMessage"
case InputEntryMessageType:
return "InputEntryMessage"
case OutputEntryMessageType:
return "OutputEntryMessage"
case GetStateEntryMessageType:
return "GetStateEntryMessage"
case SetStateEntryMessageType:
return "SetStateEntryMessage"
case ClearStateEntryMessageType:
return "ClearStateEntryMessage"
case ClearAllStateEntryMessageType:
return "ClearAllStateEntryMessage"
case GetStateKeysEntryMessageType:
return "GetStateKeysEntryMessage"
case SleepEntryMessageType:
return "SleepEntryMessage"
case CallEntryMessageType:
return "CallEntryMessage"
case OneWayCallEntryMessageType:
return "OneWayCallEntryMessage"
case AwakeableEntryMessageType:
return "AwakeableEntryMessage"
case CompleteAwakeableEntryMessageType:
return "CompleteAwakeableEntryMessage"
case RunEntryMessageType:
return "RunEntryMessage"
case SelectorEntryMessageType:
return "SelectorEntryMessage"
default:
return fmt.Sprintf("0x%04X", uint16(t))
}
}

func (t Type) UInt32() *uint32 {
Expand Down
10 changes: 8 additions & 2 deletions server/restate.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ type serviceMethod struct {

// takes care of function call
func (r *Restate) callHandler(serviceProtocolVersion protocol.ServiceProtocolVersion, service, method string, writer http.ResponseWriter, request *http.Request) {
logger := r.systemLog.With("method", slog.StringValue(fmt.Sprintf("%s/%s", service, method)))
serviceMethod := fmt.Sprintf("%s/%s", service, method)

logger := r.systemLog.With("method", slog.StringValue(serviceMethod))

writer.Header().Add("x-restate-server", xRestateServer)
writer.Header().Add("content-type", serviceProtocolVersionToHeaderValue(serviceProtocolVersion))
Expand All @@ -263,7 +265,11 @@ func (r *Restate) callHandler(serviceProtocolVersion protocol.ServiceProtocolVer

machine := state.NewMachine(handler, conn, request.Header)

if err := machine.Start(request.Context(), r.dropReplayLogs, r.logHandler); err != nil {
logHandler := r.logHandler.WithAttrs([]slog.Attr{
slog.String("method", serviceMethod),
})

if err := machine.Start(request.Context(), r.dropReplayLogs, logHandler); err != nil {
r.systemLog.LogAttrs(request.Context(), slog.LevelError, "Failed to handle invocation", log.Error(err))
}
}
Expand Down

0 comments on commit 841b7c3

Please sign in to comment.