-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement global error handler for OpenTelemetry java
- Loading branch information
1 parent
2ec91e1
commit 2e7243d
Showing
16 changed files
with
216 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
api/src/main/java/io/opentelemetry/errorhandler/DefaultErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2019, 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. | ||
*/ | ||
|
||
package io.opentelemetry.errorhandler; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* Default implementation of {@link ErrorHandler}. By default, logs the full string of the error | ||
* with a level of "Warning". | ||
* | ||
* @since 0.1.0 | ||
*/ | ||
@ThreadSafe | ||
public final class DefaultErrorHandler implements ErrorHandler { | ||
private static final Logger logger = Logger.getLogger(DefaultErrorHandler.class.getName()); | ||
private static final ErrorHandler instance = new DefaultErrorHandler(); | ||
|
||
/** | ||
* Returns a {@code ErrorHandler} singleton that is the default implementation for {@link | ||
* ErrorHandler}. | ||
* | ||
* @return a {@code ErrorHandler} singleton that is the default implementation for {@link | ||
* ErrorHandler}. | ||
*/ | ||
public static ErrorHandler getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void handle(OpenTelemetryException e) { | ||
logger.log(Level.WARNING, e.getMessage(), e); | ||
} | ||
|
||
private DefaultErrorHandler() {} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/io/opentelemetry/errorhandler/ErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.opentelemetry.errorhandler; | ||
|
||
/** Handler handles irremediable events. */ | ||
public interface ErrorHandler { | ||
/** | ||
* Handle handles any error or exception deemed irremediable by an OpenTelemetry component. | ||
* | ||
* @param e The exception to be handled | ||
*/ | ||
void handle(OpenTelemetryException e); | ||
} |
19 changes: 19 additions & 0 deletions
19
api/src/main/java/io/opentelemetry/errorhandler/OpenTelemetryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.opentelemetry.errorhandler; | ||
|
||
/** | ||
* An {@code OpenTelemetryException} is an error or exception which is deemed irremediable by an | ||
* OpenTelemetry component. {@code OpenTelemetryExceptions} should be handled by the registered | ||
* OpenTelemetry {@link ErrorHandler} delegate. {@code OpenTelemetryExceptions} may be extended to | ||
* indicate that the exception comes from a specific OpenTelemetry component. | ||
*/ | ||
public class OpenTelemetryException extends RuntimeException { | ||
private static final long serialVersionUID = 0L; | ||
|
||
public OpenTelemetryException(String message) { | ||
super(message); | ||
} | ||
|
||
public OpenTelemetryException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
api/src/main/java/io/opentelemetry/errorhandler/spi/ErrorHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2019, 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. | ||
*/ | ||
|
||
package io.opentelemetry.errorhandler.spi; | ||
|
||
import io.opentelemetry.errorhandler.ErrorHandler; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* ErrorHandlerFactory is a service provider for a {@link ErrorHandler}. Fully qualified class name | ||
* of the implementation should be registered in {@code | ||
* META-INF/services/io.opentelemetry.errorhandler.spi.ErrorHandlerFactory}. <br> | ||
* <br> | ||
* A specific implementation can be selected by a system property {@code | ||
* io.opentelemetry.errorhandler.spi.ErrorHandlerFactory} with value of fully qualified class name. | ||
* | ||
* @see io.opentelemetry.OpenTelemetry | ||
*/ | ||
@ThreadSafe | ||
public interface ErrorHandlerFactory { | ||
|
||
/** | ||
* Creates a new ErrorHandler. | ||
* | ||
* @return a new ErrorHandler. | ||
* @since 0.1.0 | ||
*/ | ||
ErrorHandler create(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.