-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botocore: Make common span attributes compliant with semconv in spec (#…
…674)
- Loading branch information
1 parent
3b5071b
commit 1960371
Showing
5 changed files
with
377 additions
and
504 deletions.
There are no files selected for viewing
This file contains 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 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 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: | ||
"""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.