def create_http_event(self, request): # if beeline has not been initialised, just execute request if not beeline.get_beeline(): return self.get_response(request) # Code to be executed for each request before # the view (and later middleware) are called. dr = DjangoRequest(request) request_context = self.get_context_from_request(request) root_span = beeline.propagate_and_start_trace(request_context, dr) response = self.get_response(request) # Code to be executed for each request/response after # the view is called. response_context = self.get_context_from_response(request, response) beeline.add_context(response_context) # Streaming responses return immediately, but iterate over # their `streaming_content` until it's empty; only close the # trace then, not now. def wrap_streaming_content(content): for chunk in content: yield chunk beeline.finish_trace(root_span) if response.streaming: response.streaming_content = wrap_streaming_content( response.streaming_content) else: beeline.finish_trace(root_span) return response
def _beeline_wrapper(event, context): global COLD_START # don't blow up the world if the beeline has not been initialized if not beeline.get_beeline(): return handler(event, context) root_span = None try: # Create request context request_context = { "app.function_name": getattr(context, 'function_name', ""), "app.function_version": getattr(context, 'function_version', ""), "app.request_id": getattr(context, 'aws_request_id', ""), "app.event": event, "meta.cold_start": COLD_START, "name": handler.__name__ } lr = LambdaRequest(event) root_span = beeline.propagate_and_start_trace(request_context, lr) # Actually run the handler resp = handler(event, context) if resp is not None: beeline.add_context_field('app.response', resp) return resp finally: # This remains false for the lifetime of the module COLD_START = False beeline.finish_trace(root_span) # we have to flush events before the lambda returns beeline.get_beeline().client.flush()
def __call__(self, environ, start_response): wr = WSGIRequest("bottle", environ) root_span = beeline.propagate_and_start_trace(wr.request_context(), wr) def _start_response(status, headers, *args): beeline.add_context_field("response.status_code", status) beeline.finish_trace(root_span) return start_response(status, headers, *args) return self.app(environ, _start_response)
def __call__(self, environ, start_response): req = Request(environ, shallow=True) wr = WSGIRequest("flask", environ) root_span = beeline.propagate_and_start_trace(wr.request_context(), wr) def _start_response(status, headers, *args): status_code = int(status[0:4]) beeline.add_context_field("response.status_code", status_code) if not signals.signals_available: beeline.finish_trace(root_span) return start_response(status, headers, *args) return self.app(environ, _start_response)
def _beeline_wrapper(event, context): global COLD_START # don't blow up the world if the beeline has not been initialized if not beeline.get_beeline(): return handler(event, context) root_span = None try: # Create request context request_context = { "app.function_name": getattr(context, 'function_name', ""), "app.function_version": getattr(context, 'function_version', ""), "app.request_id": getattr(context, 'aws_request_id', ""), "meta.cold_start": COLD_START, "name": handler.__name__ } if record_input: request_context["app.event"] = event lr = LambdaRequest(event) root_span = beeline.propagate_and_start_trace(request_context, lr) # Actually run the handler resp = handler(event, context) if resp is not None and record_output: beeline.add_context_field('app.response', resp) return resp except Exception as e: beeline.add_context({ "app.exception_type": str(type(e)), "app.exception_string": beeline.internal.stringify_exception(e), "app.exception_stacktrace": traceback.format_exc(), }) raise e finally: # This remains false for the lifetime of the module COLD_START = False beeline.finish_trace(root_span) # we have to flush events before the lambda returns beeline.get_beeline().client.flush()
def create_http_event(self, request): # if beeline has not been initialised, just execute request if not beeline.get_beeline(): return self.get_response(request) # Code to be executed for each request before # the view (and later middleware) are called. dr = DjangoRequest(request) request_context = self.get_context_from_request(request) root_span = beeline.propagate_and_start_trace(request_context, dr) response = self.get_response(request) # Code to be executed for each request/response after # the view is called. response_context = self.get_context_from_response(request, response) beeline.add_context(response_context) beeline.finish_trace(root_span) return response