def ensure_stopped_before_and_after():
    SamplersThread.ensure_stopped()
    try:
        yield
    finally:
        assert not SamplersThread._stop_event.is_set()
        SamplersThread.ensure_stopped()
Exemplo n.º 2
0
def test_ensure_started(caplog):
    SamplersThread.ensure_started()
    time.sleep(0.001)

    assert caplog.record_tuples[0] == (
        "scout_apm.core.samplers.thread",
        10,
        "Starting Samplers.",
    )
def test_ensure_stopped(caplog):
    SamplersThread.ensure_started()
    time.sleep(0.001)
    SamplersThread.ensure_stopped()

    assert SamplersThread._instance is None
    assert caplog.record_tuples[-1] == (
        "scout_apm.core.samplers.thread",
        10,
        "Stopping Samplers.",
    )
    def finish(self):
        logger.debug("Stopping request: %s", self.request_id)
        if self.end_time is None:
            self.end_time = dt.datetime.utcnow()
        if self.is_real_request:
            self.tag("mem_delta", self._get_mem_delta())
            if not self.is_ignored():
                batch_command = BatchCommand.from_tracked_request(self)
                CoreAgentSocketThread.send(batch_command)
            SamplersThread.ensure_started()

        from scout_apm.core.context import context

        context.clear_tracked_request(self)
Exemplo n.º 5
0
def test_ensure_stopped(caplog):
    SamplersThread.ensure_started()
    time.sleep(0.001)
    SamplersThread.ensure_stopped()

    # Ignore logs from the core agent thread.
    records = [
        record
        for record in caplog.record_tuples
        if record[0] == "scout_apm.core.samplers.thread"
    ]
    assert records[-1] == (
        "scout_apm.core.samplers.thread",
        10,
        "Stopping Samplers.",
    )
Exemplo n.º 6
0
    def finish(self):
        from scout_apm.core.context import context

        logger.debug("Stopping request: %s", self.request_id)
        if self.end_time is None:
            self.end_time = dt.datetime.utcnow()

        if self.is_real_request:
            self.tag("mem_delta", self._get_mem_delta())
            if not self.is_ignored() and not self.sent:
                self.sent = True
                batch_command = BatchCommand.from_tracked_request(self)
                if scout_config.value("log_payload_content"):
                    logger.debug(
                        "Sending request: %s. Payload: %s",
                        self.request_id,
                        batch_command.message(),
                    )
                else:
                    logger.debug("Sending request: %s.", self.request_id)
                CoreAgentSocketThread.send(batch_command)
            SamplersThread.ensure_started()

        details = " ".join(
            "{}={}".format(key, value)
            for key, value in [
                ("start_time", self.start_time),
                ("end_time", self.end_time),
                ("duration", (self.end_time - self.start_time).total_seconds()),
                ("active_spans", len(self.active_spans)),
                ("complete_spans", len(self.complete_spans)),
                ("tags", len(self.tags)),
                ("hit_max", self.hit_max),
                ("is_real_request", self.is_real_request),
                ("sent", self.sent),
            ]
        )
        logger.debug("Request %s %s", self.request_id, details)
        context.clear_tracked_request(self)