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

[boto3sqs] Instrument Session and resource #2161

Merged
merged 11 commits into from
Apr 22, 2024

Conversation

mattoberle
Copy link
Contributor

@mattoberle mattoberle commented Feb 9, 2024

Description

There are six ways to access the SQS API via boto3:

  • client = boto3.client("sqs")
  • client = boto3.Session().client("sqs")
  • sqs = boto3.resource("sqs")
  • sqs = boto3.Session().resource("sqs")
  • sqs = boto3.session.Session().client("sqs")
  • sqs = boto3.session.Session().resource("sqs")

The existing wrapper tied into boto3.client to wrap a generated botocore.client.SQS class.
The change here targets the deeper session.Session.client method, extending instrumentation to the remaining 5 initialization strategies.

Fixes #1699
Fixes #1996

Type of change

Note: I'm not sure whether to consider this a bug fix or new feature.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit Tests
  • Installed patch and sent/received 4 SQS messages (using the 4 methods). Verified message attributes on send, verified span context on receive.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

This commit addresses the following open issues:

- open-telemetry#1699
- open-telemetry#1996

There are four ways to access the SQS API via `boto3`:

- `client = boto3.client("sqs")`
- `client = boto3.Session().client("sqs")`
- `sqs = boto3.resource("sqs")`
- `sqs = boto3.Session().resource("sqs")`

The existing wrapper tied into `boto3.client` to wrap a generated `botocore.client.SQS` class.
The change here covers the three missing initialization methods.
mattoberle and others added 3 commits February 19, 2024 23:07
There are actually 6 ways to initialize a boto3 API object.

```py
boto3.client()              # Using default global session
boto3.resource()            # Using default global session
boto3.Session().client()    # Using "re-exported" session.Session
boto3.Session().resource()  # Using "re-exported" session.Session

boto3.session.Session().client()    # Using session.Session directly
boto3.session.Session().resource()  # Using session.Session directly
```

We only have to patch `session.Session.client` to catch all the cases.

- https://github.com/boto/boto3/blob/b3c158c62aa2a1314dc0ec78caea1ea976abd1a0/boto3/session.py#L217-L229
- https://github.com/boto/boto3/blob/b3c158c62aa2a1314dc0ec78caea1ea976abd1a0/boto3/session.py#L446-L457
@mattoberle
Copy link
Contributor Author

Just a note: Read through the relevant boto3 source and optimized this a bit from the initial commit.

@ocelotl ocelotl enabled auto-merge (squash) April 22, 2024 22:43
@ocelotl ocelotl merged commit c644f0d into open-telemetry:main Apr 22, 2024
258 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants