Skip to content

Commit 236fba7

Browse files
authored
fix: python sqs link (#8)
1 parent 3a20793 commit 236fba7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def custom_event_context_extractor(lambda_event):
102102
set_span_in_context
103103
)
104104
from opentelemetry.trace.propagation import get_current_span
105+
from opentelemetry.trace.span import INVALID_SPAN_ID
105106
import json
106107
import typing
107108
#import traceback
@@ -430,7 +431,9 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
430431
attributes = record.get("messageAttributes")
431432
if attributes is not None:
432433
ctx = get_global_textmap().extract(carrier=attributes, getter=SQSGetter())
433-
links.append(Link(get_current_span(ctx).get_span_context()))
434+
span_ctx = get_current_span(ctx).get_span_context()
435+
if span_ctx.span_id != INVALID_SPAN_ID:
436+
links.append(Link(span_ctx))
434437

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

524529
eventBridgeTriggerSpan = tracer.start_span(span_name, context=parent_context, kind=SpanKind.CONSUMER, links=links)
525530
eventBridgeTriggerSpan.set_attribute(SpanAttributes.FAAS_TRIGGER, "pubsub")
@@ -595,7 +600,7 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
595600
if lambda_event["Records"][0]["eventSource"] == "aws:sqs":
596601
span.set_attribute(SpanAttributes.FAAS_TRIGGER, "pubsub")
597602
span.set_attribute("messaging.message",
598-
limit_string_size(lambda_event["Records"]))
603+
limit_string_size(lambda_event["Records"][0].get("body")))
599604
except Exception as ex:
600605
#print(traceback.format_exc())
601606
#print("exception")
@@ -870,4 +875,4 @@ def keys(
870875
self, carrier: typing.Mapping[str, textmap.CarrierValT]
871876
) -> typing.List[str]:
872877
"""Keys implementation that returns all keys from a dictionary."""
873-
return list(carrier.keys())
878+
return list(carrier.keys())

0 commit comments

Comments
 (0)