OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Manual exception logging in datadog

  • Thread starter Thread starter Luke
  • Start date Start date
L

Luke

Guest
Datadog appears to only log uncaught exceptions, but there are certain caught exceptions that I would like to log as exception as well. I've been trying to log them manually by adding them to a span, but they aren't showing up under datadog's error tracking tab. What am I doing incorrectly?

This is the function that I am using. I have stored the locals present at the time that the exception was raised within the exception itself.

Code:
def trace_exception(ex: BaseException, span):
    if span is None:
        return
    span.set_traceback()
    span.set_tag("error", True)
    span.set_tag("error.type", type(ex).__name__)
    span.set_tag("error.message", str(ex))
    span.set_tag("error.stack", "".join(traceback.format_tb(ex.__traceback__)))
    locals_dict = getattr(ex, "locals", {})
    for var_name, var_value in locals_dict.items():
        span.set_tag(f"local.{var_name}", str(var_value))
<p>Datadog appears to only log uncaught exceptions, but there are certain caught exceptions that I would like to log as exception as well. I've been trying to log them manually by adding them to a span, but they aren't showing up under datadog's error tracking tab. What am I doing incorrectly?</p>
<p>This is the function that I am using. I have stored the locals present at the time that the exception was raised within the exception itself.</p>
<pre class="lang-py prettyprint-override"><code>def trace_exception(ex: BaseException, span):
if span is None:
return
span.set_traceback()
span.set_tag("error", True)
span.set_tag("error.type", type(ex).__name__)
span.set_tag("error.message", str(ex))
span.set_tag("error.stack", "".join(traceback.format_tb(ex.__traceback__)))
locals_dict = getattr(ex, "locals", {})
for var_name, var_value in locals_dict.items():
span.set_tag(f"local.{var_name}", str(var_value))
</code></pre>
 

Latest posts

Top