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

adding additional event sources #926

Merged
merged 13 commits into from
Mar 11, 2022
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added


- `opentelemetry-instrumentation-aws-lambda` `SpanKind.SERVER` by default, add more cases for `SpanKind.CONSUMER` services. ([#926](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/926))

- `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability
([#908](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/908))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,19 @@ def _instrumented_lambda_handler_call(
lambda_event, event_context_extractor
)

# See more:
# https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
span_kind = None
try:
if lambda_event["Records"][0]["eventSource"] == "aws:sqs":
if lambda_event["Records"][0]["eventSource"] in set(
["aws:sqs", "aws:s3", "aws:sns", "aws:dynamodb"]
):
# See more:
# https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
# https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html
# https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
span_kind = SpanKind.CONSUMER
else:
span_kind = SpanKind.SERVER
except (IndexError, KeyError, TypeError):
span_kind = SpanKind.SERVER

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,29 @@ def test_lambda_no_error_with_invalid_flush_timeout(self):
self.assertEqual(len(spans), 1)

test_env_patch.stop()

def test_lambda_handles_multiple_consumers(self):
test_env_patch = mock.patch.dict(
"os.environ",
{
**os.environ,
# NOT Active Tracing
_X_AMZN_TRACE_ID: MOCK_XRAY_TRACE_CONTEXT_NOT_SAMPLED,
# NOT using the X-Ray Propagator
OTEL_PROPAGATORS: "tracecontext",
},
)
test_env_patch.start()

AwsLambdaInstrumentor().instrument()

mock_execute_lambda({"Records": [{"eventSource": "aws:sqs"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:s3"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:sns"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:dynamodb"}]})

spans = self.memory_exporter.get_finished_spans()

assert spans

test_env_patch.stop()