Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging exporter ignore invalid handle on close #2994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions exporter/loggingexporter/known_sync_error.go
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions exporter/loggingexporter/known_sync_error_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 2 additions & 9 deletions exporter/loggingexporter/logging_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"os"
"strconv"
"strings"
"syscall"

"go.uber.org/zap"

Expand Down Expand Up @@ -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
}
}
Expand Down