Esempio n. 1
0
    def _intercept_request_and_response(self, handler: RequestHandler) -> None:
        # Record the request and response
        record = TraceRecord(
            timestamp=datetime.now() -
            timedelta(seconds=handler.request.request_time()),
            principal=None,
            session=None,
            request=TraceRequest(
                method=handler.request.method or "",
                uri=handler.request.full_url(),
                headers={
                    k.lower(): v
                    for k, v in handler.request.headers.items()
                }),
            response=TraceResponse(
                status=handler.get_status(),
                headers={k.lower(): [v]
                         for k, v in handler._headers.items()}  # pylint: disable=protected-access
            ),
            timeTaken=int(handler.request.request_time() * 1000),
        )
        self.pyctuator_impl.http_tracer.add_record(record)

        if self.delegate_log_function:
            self.delegate_log_function(handler)
Esempio n. 2
0
 def _create_record(
     self,
     request: Request,
     response: Response,
     request_time: datetime,
     response_time: datetime,
 ) -> TraceRecord:
     new_record: TraceRecord = TraceRecord(
         request_time,
         None,
         None,
         TraceRequest(request.method, str(request.url),
                      self._create_headers_dictionary(request.headers)),
         TraceResponse(response.status_code,
                       self._create_headers_dictionary(response.headers)),
         int((response_time.timestamp() - request_time.timestamp()) * 1000),
     )
     return new_record
Esempio n. 3
0
 def record_request_and_response(
     self,
     response: Response,
     request_time: datetime,
     response_time: datetime,
 ) -> None:
     new_record = TraceRecord(
         request_time,
         None,
         None,
         TraceRequest(
             request.method, str(request.url),
             self._create_headers_dictionary_flask(request.headers)),
         TraceResponse(
             response.status_code,
             self._create_headers_dictionary_flask(response.headers)),
         int((response_time.timestamp() - request_time.timestamp()) * 1000),
     )
     self.pyctuator_impl.http_tracer.add_record(record=new_record)
Esempio n. 4
0
 def _create_record(
     self,
     request: Request,
     response: Response,
     request_time: datetime,
     response_time: datetime,
 ) -> TraceRecord:
     response_delta_time = response_time - request_time
     new_record: TraceRecord = TraceRecord(
         request_time,
         None,
         None,
         TraceRequest(request.method, str(request.url),
                      self._create_headers_dictionary(request.headers)),
         TraceResponse(response.status_code,
                       self._create_headers_dictionary(response.headers)),
         int(response_delta_time.microseconds / 1000),
     )
     return new_record