@@ -54,6 +54,8 @@ class RequestSession(object):
5454 ``requests.Session`` to be used to make the HTTP requests.
5555 :param Ddtrace ddtrace: (optional) DataDog function to be used to trace, track and
5656 send metrics for individual HTTP requests.
57+ :param bool datadog_errors: (optional) If true, errors will be sent to DataDog.
58+ Defaults to ``False``.
5759 :param str ddtrace_service_name: (optional) Service name passed to DataDog DdTrace. Set to "booking_api_requests"
5860 by default.
5961 :param Statsd statsd: (optional) Datadog module to log metrics.
@@ -84,6 +86,7 @@ def __init__(
8486 user_agent = None , # type: Optional[str]
8587 user_agent_components = None , # type: Optional[UserAgentComponents]
8688 ddtrace = None , # type: Optional[Ddtrace]
89+ datadog_errors = False , # type: bool
8790 statsd = None , # type: Optional[Statsd]
8891 sentry_client = None , # type: Optional[SentryClient]
8992 logger = None , # type: Optional[Callable]
@@ -118,6 +121,7 @@ def __init__(
118121 self .user_agent_components = user_agent_components
119122 self .ddtrace = ddtrace
120123 self .ddtrace_service_name = ddtrace_service_name
124+ self .datadog_errors = datadog_errors
121125 self .statsd = statsd
122126 self .sentry_client = sentry_client
123127 self .logger = logger
@@ -404,21 +408,29 @@ def _process(
404408 else :
405409 # Client error, request is not valid and server rejected it with
406410 # http 4xx, but not timeout, there is no point in retrying.
407- if report and self . sentry_client is not None :
411+ if report :
408412 response_text = self .get_response_text (response )
409413 extra_data = (
410414 {"response_text" : response_text }
411415 if response_text != ""
412416 else None
413417 )
414- if callable (
415- getattr (self .sentry_client , "capture_exception" , None )
416- ):
417- self .sentry_client .capture_exception (extras = extra_data )
418- elif callable (
419- getattr (self .sentry_client , "captureException" , None )
420- ):
421- self .sentry_client .captureException (extra = extra_data )
418+
419+ if self .sentry_client is not None :
420+ if callable (
421+ getattr (self .sentry_client , "capture_exception" , None )
422+ ):
423+ self .sentry_client .capture_exception (extras = extra_data )
424+ elif callable (
425+ getattr (self .sentry_client , "captureException" , None )
426+ ):
427+ self .sentry_client .captureException (extra = extra_data )
428+
429+ if self .datadog_errors and self .ddtrace is not None :
430+ span = self .ddtrace .tracer .current_span ()
431+ if span :
432+ span .record_exception (error , extra_data )
433+
422434
423435 if raise_for_status :
424436 raise RequestSessionException ( # pylint: disable=raise-missing-from
0 commit comments