Esempio n. 1
0
def report_app_metadata():
    CoreAgentSocketThread.send(
        ApplicationEvent(
            event_type="scout.metadata",
            event_value=get_metadata(),
            source="Pid: " + str(getpid()),
            timestamp=dt.datetime.utcnow(),
        ))
def test_wait_until_drained_one_slow(socket):
    class SlowCommand(object):
        def message(self):
            time.sleep(0.05)
            return {}

    for _ in range(10):
        CoreAgentSocketThread.send(SlowCommand())

    empty = CoreAgentSocketThread.wait_until_drained(timeout_seconds=0.05)
    assert not empty
    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)
Esempio n. 4
0
    def run(self):
        logger.debug("Starting Samplers.")
        instances = [Cpu(), Memory()]

        while True:
            for instance in instances:
                event_value = instance.run()
                if event_value is not None:
                    event_type = instance.metric_type + "/" + instance.metric_name
                    event = ApplicationEvent(
                        event_value=event_value,
                        event_type=event_type,
                        timestamp=dt.datetime.utcnow(),
                        source="Pid: " + str(os.getpid()),
                    )
                    CoreAgentSocketThread.send(event)

            should_stop = self._stop_event.wait(timeout=60)
            if should_stop:
                logger.debug("Stopping Samplers.")
                break
Esempio n. 5
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)
def test_send_network_error(sendall, socket):
    sendall.side_effect = OSError
    CoreAgentSocketThread.send(Command())
def test_send_serialization_error(socket):
    CoreAgentSocketThread.send(NonSerializableCommand())
def test_send(socket):
    CoreAgentSocketThread.send(Command())