diff --git a/exporter/loggingexporter/known_sync_error.go b/exporter/loggingexporter/known_sync_error.go new file mode 100644 index 0000000000000..9118d5e31fdca --- /dev/null +++ b/exporter/loggingexporter/known_sync_error.go @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !windows + +package loggingexporter + +import ( + "syscall" +) + +// knownSyncError returns true if the given error is one of the known +// non-actionable errors returned by Sync on Linux and macOS: +// +// Linux: +// - sync /dev/stdout: invalid argument +// +// macOS: +// - sync /dev/stdout: inappropriate ioctl for device +// +func knownSyncError(err error) bool { + switch err { + case syscall.EINVAL, syscall.ENOTSUP, syscall.ENOTTY: + return true + } + return false +} diff --git a/exporter/loggingexporter/known_sync_error_windows.go b/exporter/loggingexporter/known_sync_error_windows.go new file mode 100644 index 0000000000000..ef26294c03ac7 --- /dev/null +++ b/exporter/loggingexporter/known_sync_error_windows.go @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build windows + +package loggingexporter + +import "golang.org/x/sys/windows" + +// knownSyncError returns true if the given error is one of the known +// non-actionable errors returned by Sync on Windows: +// +// - sync /dev/stderr: The handle is invalid. +// +func knownSyncError(err error) bool { + return err == windows.ERROR_INVALID_HANDLE +} diff --git a/exporter/loggingexporter/logging_exporter.go b/exporter/loggingexporter/logging_exporter.go index 75512d0381692..0b5379d951a8a 100644 --- a/exporter/loggingexporter/logging_exporter.go +++ b/exporter/loggingexporter/logging_exporter.go @@ -20,7 +20,6 @@ import ( "os" "strconv" "strings" - "syscall" "go.uber.org/zap" @@ -507,18 +506,12 @@ func (s *loggingExporter) pushLogData( func loggerSync(logger *zap.Logger) func(context.Context) error { return func(context.Context) error { - // Currently Sync() on stdout and stderr return errors on Linux and macOS, - // respectively: - // - // - sync /dev/stdout: invalid argument - // - sync /dev/stdout: inappropriate ioctl for device - // + // Currently Sync() return a different error depending on the OS. // Since these are not actionable ignore them. err := logger.Sync() if osErr, ok := err.(*os.PathError); ok { wrappedErr := osErr.Unwrap() - switch wrappedErr { - case syscall.EINVAL, syscall.ENOTSUP, syscall.ENOTTY: + if knownSyncError(wrappedErr) { err = nil } }