adding additional event sources (#926)

This commit is contained in:
brett-bim
2022-03-11 12:39:01 -06:00
committed by GitHub
parent 7a0caed36f
commit 5539d1f35a
3 changed files with 38 additions and 3 deletions

View File

@ -19,6 +19,7 @@ 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-sqlalchemy` added experimental sql commenter capability
([#924](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/924))
- `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability

View File

@ -187,11 +187,19 @@ def _instrument(
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

View File

@ -274,3 +274,29 @@ class TestAwsLambdaInstrumentor(TestBase):
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()