diff --git a/metric/system/process/process.go b/metric/system/process/process.go index a499182ff..b3746b93a 100644 --- a/metric/system/process/process.go +++ b/metric/system/process/process.go @@ -229,7 +229,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) { // OS-specific entrypoint, get basic info so we can at least run matchProcess status, err := GetInfoForPid(procStats.Hostfs, pid) if err != nil { - return status, true, fmt.Errorf("GetInfoForPid: %w", err) + return status, true, fmt.Errorf("GetInfoForPid failed for pid %d: %w", pid, err) } if procStats.skipExtended { return status, true, nil @@ -250,7 +250,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) { status, err = FillPidMetrics(procStats.Hostfs, pid, status, procStats.isWhitelistedEnvVar) if err != nil { if !errors.Is(err, NonFatalErr{}) { - return status, true, fmt.Errorf("FillPidMetrics: %w", err) + return status, true, fmt.Errorf("FillPidMetrics failed for PID %d: %w", pid, err) } wrappedErr = errors.Join(wrappedErr, fmt.Errorf("non-fatal error fetching PID metrics for %d, metrics are valid, but partial: %w", pid, err)) procStats.logger.Debugf(wrappedErr.Error()) @@ -282,7 +282,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) { status, err = FillMetricsRequiringMoreAccess(pid, status) if err != nil { - return status, true, fmt.Errorf("FillMetricsRequiringMoreAccess: %w", err) + return status, true, fmt.Errorf("FillMetricsRequiringMoreAccess failed for pid %d: %w", pid, err) } // Generate `status.Cmdline` here for compatibility because on Windows diff --git a/metric/system/process/process_windows.go b/metric/system/process/process_windows.go index 66862da2c..e19c02b3a 100644 --- a/metric/system/process/process_windows.go +++ b/metric/system/process/process_windows.go @@ -102,7 +102,7 @@ func FetchNumThreads(pid int) (int, error) { currentProcessHandle, err := syscall.GetCurrentProcess() if err != nil { - return 0, fmt.Errorf("GetCurrentProcess failed: %w", err) + return 0, fmt.Errorf("GetCurrentProcess failed for PID %d: %w", pid, err) } // The pseudo handle need not be closed when it is no longer // needed, calling CloseHandle has no effect. Adding here to @@ -114,7 +114,7 @@ func FetchNumThreads(pid int) (int, error) { var snapshotHandle syscall.Handle err = PssCaptureSnapshot(targetProcessHandle, PSSCaptureThreads, 0, &snapshotHandle) if err != nil { - return 0, fmt.Errorf("PssCaptureSnapshot failed: %w", err) + return 0, fmt.Errorf("PssCaptureSnapshot failed for PID %d: %w", pid, err) } info := PssThreadInformation{} @@ -189,28 +189,28 @@ func getProcArgs(pid int) ([]string, error) { false, uint32(pid)) if err != nil { - return nil, fmt.Errorf("OpenProcess failed: %w", err) + return nil, fmt.Errorf("OpenProcess failed for PID %d: %w", pid, err) } defer func() { _ = syscall.CloseHandle(handle) }() pbi, err := windows.NtQueryProcessBasicInformation(handle) if err != nil { - return nil, fmt.Errorf("NtQueryProcessBasicInformation failed: %w", err) + return nil, fmt.Errorf("NtQueryProcessBasicInformation failed for PID %d: %w", pid, err) } userProcParams, err := windows.GetUserProcessParams(handle, pbi) if err != nil { - return nil, fmt.Errorf("GetUserProcessParams failed: %w", err) + return nil, fmt.Errorf("GetUserProcessParams failed for PID %d: %w", pid, err) } argsW, err := windows.ReadProcessUnicodeString(handle, &userProcParams.CommandLine) if err != nil { - return nil, fmt.Errorf("ReadProcessUnicodeString failed: %w", err) + return nil, fmt.Errorf("ReadProcessUnicodeString failed for PID %d: %w", pid, err) } procList, err := windows.ByteSliceToStringSlice(argsW) if err != nil { - return nil, fmt.Errorf("ByteSliceToStringSlice failed: %w", err) + return nil, fmt.Errorf("ByteSliceToStringSlice failed for PID %d: %w", pid, err) } return procList, nil }