-
Notifications
You must be signed in to change notification settings - Fork 890
botocore: Make common span attributes compliant with semconv in spec #674
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
Merged
lzchen
merged 8 commits into
open-telemetry:main
from
mariojonke:botocore-general-semconv
Oct 6, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d1c2bb
botocore: Make common span attributes compliant with semconv in spec
mariojonke 3068c77
changelog
mariojonke a164815
fix unit tests
mariojonke 6237b6d
make internally used classes private
mariojonke 06b995a
make extracting attributes from botocore more forgiving
mariojonke e8eaaae
Merge remote-tracking branch 'upstream/main' into botocore-general-se…
mariojonke 43415ac
lint and fix tests
mariojonke 2793665
Merge branch 'main' into botocore-general-semconv
lzchen 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
Empty file.
72 changes: 72 additions & 0 deletions
72
...y-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/types.py
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,72 @@ | ||
| import logging | ||
| from typing import Any, Dict, Optional, Tuple | ||
|
|
||
| from opentelemetry.trace import SpanKind | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| _BotoClientT = "botocore.client.BaseClient" | ||
|
|
||
| _OperationParamsT = Dict[str, Any] | ||
|
|
||
|
|
||
| class _AwsSdkCallContext: | ||
owais marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """An context object providing information about the invoked AWS service | ||
| call. | ||
|
|
||
| Args: | ||
| service: the AWS service (e.g. s3, lambda, ...) which is called | ||
| service_id: the name of the service in propper casing | ||
| operation: the called operation (e.g. ListBuckets, Invoke, ...) of the | ||
| AWS service. | ||
| params: a dict of input parameters passed to the service operation. | ||
| region: the AWS region in which the service call is made | ||
| endpoint_url: the endpoint which the service operation is calling | ||
| api_version: the API version of the called AWS service. | ||
| span_name: the name used to create the span. | ||
| span_kind: the kind used to create the span. | ||
| """ | ||
|
|
||
| def __init__(self, client: _BotoClientT, args: Tuple[str, Dict[str, Any]]): | ||
| operation = args[0] | ||
| try: | ||
| params = args[1] | ||
| except (IndexError, TypeError): | ||
| _logger.warning("Could not get request params.") | ||
| params = {} | ||
|
|
||
| boto_meta = client.meta | ||
| service_model = boto_meta.service_model | ||
|
|
||
| self.service = service_model.service_name.lower() # type: str | ||
| self.operation = operation # type: str | ||
| self.params = params # type: Dict[str, Any] | ||
|
|
||
| # 'operation' and 'service' are essential for instrumentation. | ||
| # for all other attributes we extract them defensively. All of them should | ||
| # usually exist unless some future botocore version moved things. | ||
| self.region = self._get_attr( | ||
| boto_meta, "region_name" | ||
| ) # type: Optional[str] | ||
| self.endpoint_url = self._get_attr( | ||
| boto_meta, "endpoint_url" | ||
| ) # type: Optional[str] | ||
|
|
||
| self.api_version = self._get_attr( | ||
| service_model, "api_version" | ||
| ) # type: Optional[str] | ||
| # name of the service in proper casing | ||
| self.service_id = str( | ||
| self._get_attr(service_model, "service_id", self.service) | ||
| ) | ||
|
|
||
| self.span_name = f"{self.service_id}.{self.operation}" | ||
| self.span_kind = SpanKind.CLIENT | ||
|
|
||
| @staticmethod | ||
| def _get_attr(obj, name: str, default=None): | ||
| try: | ||
| return getattr(obj, name) | ||
| except AttributeError: | ||
| _logger.warning("Could not get attribute '%s'", name) | ||
| return default | ||
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.