diff --git a/pkg/winperfcounters/watcher.go b/pkg/winperfcounters/watcher.go index 727d35ccd30c..6a1e11d04ba7 100644 --- a/pkg/winperfcounters/watcher.go +++ b/pkg/winperfcounters/watcher.go @@ -7,6 +7,7 @@ package winperfcounters // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/winperfcounters" import ( + "errors" "fmt" "time" @@ -104,8 +105,8 @@ func (pc *perfCounter) Path() string { func (pc *perfCounter) ScrapeData() ([]CounterValue, error) { if err := pc.query.CollectData(); err != nil { - pdhErr, ok := err.(*win_perf_counters.PdhError) - if !ok || pdhErr.ErrorCode != win_perf_counters.PDH_CALC_NEGATIVE_DENOMINATOR { + var pdhErr *win_perf_counters.PdhError + if !errors.As(err, &pdhErr) || pdhErr.ErrorCode != win_perf_counters.PDH_CALC_NEGATIVE_DENOMINATOR { return nil, fmt.Errorf("failed to collect data for performance counter '%s': %w", pc.path, err) }