Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: python sqs link #8

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def custom_event_context_extractor(lambda_event):
set_span_in_context
)
from opentelemetry.trace.propagation import get_current_span
from opentelemetry.trace.span import INVALID_SPAN_ID
import json
import typing
#import traceback
Expand Down Expand Up @@ -430,7 +431,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 @@ -519,7 +522,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 @@ -595,7 +600,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")))
povilasv marked this conversation as resolved.
Show resolved Hide resolved
except Exception as ex:
#print(traceback.format_exc())
#print("exception")
Expand Down Expand Up @@ -870,4 +875,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())
Loading