open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
647 stars 535 forks source link

bugfix: AWS Lambda event source key incorrect for SNS in instrumenta… #2612

Closed Charlie-lizhihan closed 1 week ago

Charlie-lizhihan commented 2 weeks ago

…tion library.

Description

Fixes #2511

In AWS doc: https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html, The SNS message event looks like:

{
  "Records": [
    {
      "EventVersion": "1.0",
      "EventSubscriptionArn": "arn:aws:sns:us-east-1:123456789012:sns-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
      "EventSource": "aws:sns",
      "Sns": {
......

but the code will just check eventSource(which applicable in sqs, s3 and dynamodb) but not EventSource. So I add code to check the EventSource, make sure the SNS's span id will be SpanKind.CONSUMER but not SpanKind.SERVER

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

tox -e py39-test-instrumentation-aws-lambda

Does This PR Require a Core Repo Change?

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

xrmx commented 2 weeks ago

Please setup pre-commit as written in CONTRIBUTING.md to avoid basic lint issues