-
Notifications
You must be signed in to change notification settings - Fork 673
feat(boto3): Add ServiceExtension class
#7536
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
Open
pabloDeputter
wants to merge
11
commits into
pablo/add-boto3-response-retry-error-attributes
from
pablo/add-boto3-service-extension-class
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c72fe0
add base `ServiceExtension` class
pabloDeputter 2e5d377
feat(boto3): Add service registry
pabloDeputter d5bd6b1
add missing `__init__.py` file
pabloDeputter 1edba5a
simplify `_resolve_service()` logic
pabloDeputter 463e1b1
add service extension logic to `_instrumentation.py`
pabloDeputter ce34f60
combine span-config extraction and validation in `_start_client_span()`
pabloDeputter 26a2a08
add service extension logic to `_client.py`
pabloDeputter 6718be1
add tests
pabloDeputter 356a93f
fix(boto3): Remove "hardcoded" origin
pabloDeputter 405511f
feat(boto3): Add `sentry.kind` attribute to boto span
pabloDeputter d7727cd
ref(boto3): Add comment explaining
pabloDeputter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Any, Optional, Tuple | ||
|
|
||
| from sentry_sdk._types import Attributes | ||
| from sentry_sdk.integrations.boto3._context import AwsCallContext | ||
|
|
||
|
|
||
| class _ServiceExtension: | ||
| """ | ||
| Specialize generic botocore instrumentation for an AWS service. | ||
| """ | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def get_span_config( | ||
| self, ctx: "AwsCallContext" | ||
| ) -> "Optional[Tuple[Optional[str], Optional[str]]]": | ||
| """Return an optional `(op, origin)` override for the client span.""" | ||
| return None | ||
|
|
||
| def get_request_attributes(self, ctx: "AwsCallContext") -> "Attributes": | ||
| """Return service-specific attributes available before the call.""" | ||
| return {} | ||
|
|
||
| def get_response_attributes( | ||
| self, ctx: "AwsCallContext", response: "Any" | ||
| ) -> "Attributes": | ||
| """Return service-specific attributes derived from the response.""" | ||
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from functools import lru_cache | ||
| from importlib import import_module | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sentry_sdk.integrations.boto3._services.base import _ServiceExtension | ||
| from sentry_sdk.utils import capture_internal_exceptions | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Dict, Optional, Tuple | ||
|
|
||
|
|
||
| # service modules are imported lazily. | ||
| # e.g. `s3` -> (`sentry_sdk.integrations.boto3._services.s3`, `_S3Extension) | ||
| _SERVICE_EXTENSIONS: "Dict[str, Tuple[str, str]]" = {} | ||
|
|
||
|
|
||
| @lru_cache(maxsize=None) | ||
| def _resolve_service( | ||
| service: "str", | ||
| ) -> "Optional[_ServiceExtension]": | ||
| target = _SERVICE_EXTENSIONS.get(service) | ||
| if target is None: | ||
| return None | ||
|
|
||
| with capture_internal_exceptions(): | ||
| module_name, class_name = target | ||
| extension_class = getattr(import_module(module_name), class_name) | ||
| candidate = extension_class() | ||
| if isinstance(candidate, _ServiceExtension): | ||
| return candidate | ||
|
|
||
| # preserve generic instrumentation when lookup fails. | ||
| return None | ||
|
sentry-warden[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.