Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
saartochner-lumigo committed Oct 18, 2023
1 parent 97b2a3d commit 8fa7bd1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lumigo_opentelemetry/instrumentations/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from opentelemetry.trace import Span
from lumigo_opentelemetry.libs.general_utils import lumigo_safe_execute
from lumigo_opentelemetry.libs.json_utils import dump_with_context
from lumigo_opentelemetry.instrumentations.instrumentation_utils import add_body_attribute
from lumigo_opentelemetry.instrumentations.instrumentation_utils import (
add_body_attribute,
)


class RequestsInstrumentor(AbstractInstrumentor):
Expand All @@ -26,17 +28,23 @@ def request_hook(span: Span, request: PreparedRequest) -> None:
)
add_body_attribute(span, request.body, "http.request.body")

def response_hook(span: Span, request: PreparedRequest, response: Response) -> None:
def response_hook(
span: Span, request: PreparedRequest, response: Response
) -> None:
with lumigo_safe_execute("flask response_hook"):
span.set_attribute(
"http.response.headers",
dump_with_context("responseHeaders", response.headers),
)
add_body_attribute(span, response.content, "http.response.body")
if "x-amzn-requestid" in response.headers:
span.set_attribute("messageId", response.headers["x-amzn-requestid"])
span.set_attribute(
"messageId", response.headers["x-amzn-requestid"]
)

RequestsInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
RequestsInstrumentor().instrument(
request_hook=request_hook, response_hook=response_hook
)


instrumentor: AbstractInstrumentor = RequestsInstrumentor()

0 comments on commit 8fa7bd1

Please sign in to comment.