-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/airbytehq/airbyte
- Loading branch information
Showing
88 changed files
with
1,017 additions
and
463 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import logging | ||
import sys | ||
|
||
from airbyte_cdk.utils.traced_exception import AirbyteTracedException | ||
|
||
|
||
def init_uncaught_exception_handler(logger: logging.Logger) -> None: | ||
""" | ||
Handles uncaught exceptions by emitting an AirbyteTraceMessage and making sure they are not | ||
printed to the console without having secrets removed. | ||
""" | ||
|
||
def hook_fn(exception_type, exception_value, traceback_): | ||
# For developer ergonomics, we want to see the stack trace in the logs when we do a ctrl-c | ||
if issubclass(exception_type, KeyboardInterrupt): | ||
sys.__excepthook__(exception_type, exception_value, traceback_) | ||
return | ||
|
||
logger.fatal(exception_value, exc_info=exception_value) | ||
|
||
# emit an AirbyteTraceMessage for any exception that gets to this spot | ||
traced_exc = ( | ||
exception_value | ||
if issubclass(exception_type, AirbyteTracedException) | ||
else AirbyteTracedException.from_exception(exception_value) | ||
) | ||
|
||
traced_exc.emit_message() | ||
|
||
sys.excepthook = hook_fn |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import traceback | ||
from datetime import datetime | ||
|
||
from airbyte_cdk.models import AirbyteErrorTraceMessage, AirbyteMessage, AirbyteTraceMessage, FailureType, TraceType | ||
from airbyte_cdk.models import Type as MessageType | ||
from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets | ||
|
||
|
||
class AirbyteTracedException(Exception): | ||
""" | ||
An exception that should be emitted as an AirbyteTraceMessage | ||
""" | ||
|
||
def __init__( | ||
self, | ||
internal_message: str = None, | ||
message: str = None, | ||
failure_type: FailureType = FailureType.system_error, | ||
exception: BaseException = None, | ||
): | ||
""" | ||
:param internal_message: the internal error that caused the failure | ||
:param message: a user-friendly message that indicates the cause of the error | ||
:param failure_type: the type of error | ||
:param exception: the exception that caused the error, from which the stack trace should be retrieved | ||
""" | ||
self.internal_message = internal_message | ||
self.message = message | ||
self.failure_type = failure_type | ||
self._exception = exception | ||
super().__init__(internal_message) | ||
|
||
def as_airbyte_message(self) -> AirbyteMessage: | ||
""" | ||
Builds an AirbyteTraceMessage from the exception | ||
""" | ||
now_millis = datetime.now().timestamp() * 1000.0 | ||
|
||
trace_exc = self._exception or self | ||
stack_trace_str = "".join(traceback.TracebackException.from_exception(trace_exc).format()) | ||
|
||
trace_message = AirbyteTraceMessage( | ||
type=TraceType.ERROR, | ||
emitted_at=now_millis, | ||
error=AirbyteErrorTraceMessage( | ||
message=self.message or "Something went wrong in the connector. See the logs for more details.", | ||
internal_message=self.internal_message, | ||
failure_type=self.failure_type, | ||
stack_trace=stack_trace_str, | ||
), | ||
) | ||
|
||
return AirbyteMessage(type=MessageType.TRACE, trace=trace_message) | ||
|
||
def emit_message(self): | ||
""" | ||
Prints the exception as an AirbyteTraceMessage. | ||
Note that this will be called automatically on uncaught exceptions when using the airbyte_cdk entrypoint. | ||
""" | ||
message = self.as_airbyte_message().json(exclude_unset=True) | ||
filtered_message = filter_secrets(message) | ||
print(filtered_message) | ||
|
||
@classmethod | ||
def from_exception(cls, exc: Exception, *args, **kwargs) -> "AirbyteTracedException": | ||
""" | ||
Helper to create an AirbyteTracedException from an existing exception | ||
:param exc: the exception that caused the error | ||
""" | ||
return cls(internal_message=str(exc), exception=exc, *args, **kwargs) |
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.