Skip to content

Commit

Permalink
fix: python sqs link
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Apr 15, 2024
1 parent 9202c85 commit 00e605a
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def custom_event_context_extractor(lambda_event):
)
from opentelemetry.trace.propagation import get_current_span
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.trace.span import INVALID_SPAN_ID
import json
import typing
#import traceback
Expand Down Expand Up @@ -434,7 +435,9 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
attributes = record.get("messageAttributes")
if attributes is not None:
ctx = get_global_textmap().extract(carrier=attributes, getter=SQSGetter())
links.append(Link(get_current_span(ctx).get_span_context()))
span_ctx = get_current_span(ctx).get_span_context()
if span_ctx.span_id != INVALID_SPAN_ID:
links.append(Link(span_ctx))

span_name = orig_handler_name
sqsTriggerSpan = tracer.start_span(span_name, context=parent_context, kind=SpanKind.PRODUCER, links=links)
Expand Down Expand Up @@ -523,7 +526,9 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
links = []
if lambda_event.get("detail") is not None and lambda_event["detail"].get("_context") is not None:
ctx = get_global_textmap().extract(carrier=lambda_event["detail"].get("_context"))
links.append(Link(get_current_span(ctx).get_span_context()))
span_ctx = get_current_span(ctx).get_span_context()
if span_ctx.span_id != INVALID_SPAN_ID:
links.append(Link(span_ctx))

eventBridgeTriggerSpan = tracer.start_span(span_name, context=parent_context, kind=SpanKind.CONSUMER, links=links)
eventBridgeTriggerSpan.set_attribute(SpanAttributes.FAAS_TRIGGER, "pubsub")
Expand Down Expand Up @@ -616,7 +621,7 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
if lambda_event["Records"][0]["eventSource"] == "aws:sqs":
span.set_attribute(SpanAttributes.FAAS_TRIGGER, "pubsub")
span.set_attribute("messaging.message",
limit_string_size(lambda_event["Records"]))
limit_string_size(lambda_event["Records"][0].get("body")))
except Exception as ex:
#print(traceback.format_exc())
#print("exception")
Expand Down Expand Up @@ -894,4 +899,4 @@ def keys(
self, carrier: typing.Mapping[str, textmap.CarrierValT]
) -> typing.List[str]:
"""Keys implementation that returns all keys from a dictionary."""
return list(carrier.keys())
return list(carrier.keys())

0 comments on commit 00e605a

Please sign in to comment.