mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 09:13:23 +08:00
adding additional event sources (#926)
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user