Skip to content

Instantly share code, notes, and snippets.

@tedsuo
Created November 24, 2020 17:51
Show Gist options
  • Save tedsuo/d7f21918c29679c429c35e82f3354b37 to your computer and use it in GitHub Desktop.
Save tedsuo/d7f21918c29679c429c35e82f3354b37 to your computer and use it in GitHub Desktop.
Python recording errors
from opentelemetry.trace.status import StatusCode
@app.route("/hello")
def hello():
span = trace.propagation.get_current_span()
try:
1 / 0
except ZeroDivisionError as error:
# record an exception
span.record_exception(error)
# fail the operation
span.set_status(StatusCode.ERROR)
print("caught zero division error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment