Skip to content

Commit

Permalink
add log at request start
Browse files Browse the repository at this point in the history
  • Loading branch information
wbrowne committed Sep 25, 2024
1 parent d44c599 commit 22cb3d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions backend/adapter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func tracingWrapper(next handlerWrapperFunc) handlerWrapperFunc {
func logWrapper(next handlerWrapperFunc) handlerWrapperFunc {
return func(ctx context.Context) (RequestStatus, error) {
start := time.Now()

ctxLogger := Logger.FromContext(ctx)
logFunc := ctxLogger.Debug
logFunc("Plugin Request Started")

status, err := next(ctx)

logParams := []any{
Expand All @@ -133,8 +138,6 @@ func logWrapper(next handlerWrapperFunc) handlerWrapperFunc {

logParams = append(logParams, "statusSource", string(errorSourceFromContext(ctx)))

ctxLogger := Logger.FromContext(ctx)
logFunc := ctxLogger.Debug
if status > RequestStatusCancelled {
logFunc = ctxLogger.Error
}
Expand Down
6 changes: 3 additions & 3 deletions backend/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ var NewLoggerWith = func(args ...interface{}) log.Logger {
}

func withContextualLogAttributes(ctx context.Context, pCtx PluginContext) context.Context {
args := []any{"pluginID", pCtx.PluginID}
args := []any{"pluginId", pCtx.PluginID}

endpoint := EndpointFromContext(ctx)
if !endpoint.IsEmpty() {
args = append(args, "endpoint", string(endpoint))
}

if tid := trace.SpanContextFromContext(ctx).TraceID(); tid.IsValid() {
args = append(args, "traceID", tid.String())
args = append(args, "traceId", tid.String())
}
if pCtx.DataSourceInstanceSettings != nil {
args = append(
args,
"dsName", pCtx.DataSourceInstanceSettings.Name,
"dsUID", pCtx.DataSourceInstanceSettings.UID,
"dsUid", pCtx.DataSourceInstanceSettings.UID,
)
if pCtx.User != nil {
args = append(args, "uname", pCtx.User.Name)
Expand Down

0 comments on commit 22cb3d6

Please sign in to comment.