-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botocore: Introduce instrumentation extensions (#718)
* botocore: Introduce instrumentation extensions * add extensions that are invoked before and after an AWS SDK service call to enrich the span with service specific request and response attirbutes * move SQS specific parts to a separate extension * changelog Co-authored-by: Owais Lone <[email protected]> Co-authored-by: Diego Hurtado <[email protected]>
- Loading branch information
1 parent
b41a917
commit c3df816
Showing
5 changed files
with
123 additions
and
3 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
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,35 @@ | ||
import importlib | ||
import logging | ||
|
||
from opentelemetry.instrumentation.botocore.extensions.types import ( | ||
_AwsSdkCallContext, | ||
_AwsSdkExtension, | ||
) | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _lazy_load(module, cls): | ||
def loader(): | ||
imported_mod = importlib.import_module(module, __name__) | ||
return getattr(imported_mod, cls, None) | ||
|
||
return loader | ||
|
||
|
||
_KNOWN_EXTENSIONS = { | ||
"sqs": _lazy_load(".sqs", "_SqsExtension"), | ||
} | ||
|
||
|
||
def _find_extension(call_context: _AwsSdkCallContext) -> _AwsSdkExtension: | ||
try: | ||
loader = _KNOWN_EXTENSIONS.get(call_context.service) | ||
if loader is None: | ||
return _AwsSdkExtension(call_context) | ||
|
||
extension_cls = loader() | ||
return extension_cls(call_context) | ||
except Exception as ex: # pylint: disable=broad-except | ||
_logger.error("Error when loading extension: %s", ex) | ||
return _AwsSdkExtension(call_context) |
12 changes: 12 additions & 0 deletions
12
...try-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sqs.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,12 @@ | ||
from opentelemetry.instrumentation.botocore.extensions.types import ( | ||
_AttributeMapT, | ||
_AwsSdkExtension, | ||
) | ||
|
||
|
||
class _SqsExtension(_AwsSdkExtension): | ||
def extract_attributes(self, attributes: _AttributeMapT): | ||
queue_url = self._call_context.params.get("QueueUrl") | ||
if queue_url: | ||
# TODO: update when semantic conventions exist | ||
attributes["aws.queue_url"] = queue_url |
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