import re import uuid import contextlib import time
from datetime import datetime, timedelta
import sentry_sdk
from sentry_sdk.utils import capture_internal_exceptions, logger, to_string from sentry_sdk._compat import PY2 from sentry_sdk._types import MYPY
if PY2: from collections import Mapping else: from collections.abc import Mapping
if MYPY: import typing
from typing import Generator from typing import Optional from typing import Any from typing import Dict from typing import List from typing import Tuple
# This is just so that we don't run out of memory while recording a lot # of spans. At some point we just stop and flush out the start of the # trace tree (i.e. the first n spans with the smallest # start_timestamp).
self.open_span_count += 1 if self.open_span_count > self.maxlen:
span._span_recorder = None
if self.transaction isNone: # If this has no transaction set we assume there's a parent # transaction for this span that would be flushed out eventually. returnNone
client = hub.client
if client isNone: # We have no client and therefore nowhere to send this transaction # event. returnNone
ifnot self.sampled: # At this point a `sampled = None` should have already been # resolved to a concrete decision. If `sampled` is `None`, it's # likely that somebody used `with sentry_sdk.Hub.start_span(..)` on a # non-transaction span and later decided to make it a transaction. if self.sampled isNone:
logger.warning("Discarding transaction Span without sampling decision")
returnNone
return hub.capture_event(
{ "type": "transaction", "transaction": self.transaction, "contexts": {"trace": self.get_trace_context()}, "tags": self._tags, "timestamp": self.timestamp, "start_timestamp": self.start_timestamp, "spans": [
s.to_json(client) for s in self._span_recorder.finished_spans if s isnot self
],
}
)
# If we're using psycopg2, it could be that we're # looking at a query that uses Composed objects. Use psycopg2's mogrify # function to format the query. We lose per-parameter trimming but gain # accuracy in formatting. try: if hasattr(cursor, "mogrify"):
real_sql = cursor.mogrify(sql) if isinstance(real_sql, bytes):
real_sql = real_sql.decode(cursor.connection.encoding) except Exception:
real_sql = None
# TODO: Bring back capturing of params by default if hub.client and hub.client.options["_experiments"].get( "record_sql_params", False
): ifnot params_list or params_list == [None]:
params_list = None
data = {} if params_list isnotNone:
data["db.params"] = params_list if paramstyle isnotNone:
data["db.paramstyle"] = paramstyle if executemany:
data["db.executemany"] = True
with capture_internal_exceptions():
hub.add_breadcrumb(message=query, category="query", data=data)
with hub.start_span(op="db", description=query) as span: for k, v in data.items():
span.set_data(k, v) yield span
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.