From a182761e6b7197fb851b02e646e13b6638092911 Mon Sep 17 00:00:00 2001 From: "(Eliseo) Nathaniel Ruiz Nowell" Date: Wed, 27 Oct 2021 11:01:01 -0400 Subject: [PATCH] Lambda is CONSUMER SQS trace if 'Records' key in Lambda event --- .../instrumentation/aws_lambda/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py index 8d9f96d6e3..aa42fd86ba 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py @@ -183,12 +183,17 @@ def _instrumented_lambda_handler_call( lambda_event, event_context_extractor ) + # See more: + # https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html + if "Records" in lambda_event: + span_kind = SpanKind.CONSUMER + else: + span_kind = SpanKind.SERVER + tracer = get_tracer(__name__, __version__, tracer_provider) with tracer.start_as_current_span( - name=orig_handler_name, - context=parent_context, - kind=SpanKind.SERVER, + name=orig_handler_name, context=parent_context, kind=span_kind, ) as span: if span.is_recording(): lambda_context = args[1]