예제 #1
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     transaction = execution_context.get_transaction()
     if transaction and transaction.is_sampled:
         try:
             transaction.end_span(self.skip_frames)
         except LookupError:
             logger.info("ended non-existing span %s of type %s", self.name,
                         self.type)
예제 #2
0
 def __enter__(self):
     transaction = execution_context.get_transaction()
     if transaction and transaction.is_sampled:
         return transaction.begin_span(self.name,
                                       self.type,
                                       context=self.extra,
                                       leaf=self.leaf,
                                       tags=self.tags)
예제 #3
0
def tag(**tags):
    """
    Tags current transaction. Both key and value of the tag should be strings.
    """
    transaction = execution_context.get_transaction()
    if not transaction:
        error_logger.warning(
            "Ignored tags %s. No transaction currently active.",
            ", ".join(tags.keys()))
    else:
        transaction.tag(**tags)
예제 #4
0
 def end_transaction(self, result=None, transaction_name=None):
     transaction = execution_context.get_transaction(clear=True)
     if transaction:
         transaction.end_transaction()
         if transaction.name is None:
             transaction.name = transaction_name if transaction_name is not None else ""
         if self._should_ignore(transaction.name):
             return
         if transaction.result is None:
             transaction.result = result
         self.queue_func(TRANSACTION, transaction.to_dict())
     return transaction
예제 #5
0
def set_context(data, key="custom"):
    transaction = execution_context.get_transaction()
    if not transaction:
        return
    if callable(data) and transaction.is_sampled:
        data = data()

    # remove invalid characters from key names
    if not callable(
            data
    ):  # if transaction wasn't sampled, data is still a callable here and can be ignored
        for k in list(data.keys()):
            if TAG_RE.search(k):
                data[TAG_RE.sub("_", k)] = data.pop(k)

    if key in transaction.context:
        transaction.context[key].update(data)
    else:
        transaction.context[key] = data
예제 #6
0
 def get_transaction(clear=False):
     try:
         return execution_context.get_transaction(clear=clear)
     except:
         return None
예제 #7
0
def set_transaction_result(result, override=True):
    transaction = execution_context.get_transaction()
    if not transaction:
        return
    if transaction.result is None or override:
        transaction.result = result
예제 #8
0
def set_transaction_name(name, override=True):
    transaction = execution_context.get_transaction()
    if not transaction:
        return
    if transaction.name is None or override:
        transaction.name = name