OpenTelemetry Boto3 SQS Instrumentation

pypi

This library allows tracing requests made by the Boto3 library to the SQS service.

Installation

pip install opentelemetry-instrumentation-boto3sqs

References

Instrument boto3sqs to trace SQS applications.

Usage

import boto3
from opentelemetry.instrumentation.boto3sqs import Boto3SQSInstrumentor

Boto3SQSInstrumentor().instrument()

class opentelemetry.instrumentation.boto3sqs.Boto3SQSGetter(*args, **kwds)[source]

Bases: Getter[CarrierT]

get(carrier, key)[source]

Function that can retrieve zero or more values from the carrier. In the case that the value does not exist, returns None.

Parameters:
  • carrier (TypeVar(CarrierT)) – An object which contains values that are used to construct a Context.

  • key (str) – key of a field in carrier.

Return type:

Optional[List[str]]

Returns: first value of the propagation key or None if the key doesn’t

exist.

keys(carrier)[source]

Function that can retrieve all the keys in a carrier object.

Parameters:

carrier (TypeVar(CarrierT)) – An object which contains values that are used to construct a Context.

Return type:

List[str]

Returns:

list of keys from the carrier.

class opentelemetry.instrumentation.boto3sqs.Boto3SQSSetter(*args, **kwds)[source]

Bases: Setter[CarrierT]

set(carrier, key, value)[source]

Function that can set a value into a carrier””

Parameters:
  • carrier (TypeVar(CarrierT)) – An object which contains values that are used to construct a Context.

  • key (str) – key of a field in carrier.

  • value (str) – value for a field in carrier.

Return type:

None

class opentelemetry.instrumentation.boto3sqs.Boto3SQSInstrumentor(*args, **kwargs)[source]

Bases: BaseInstrumentor

received_messages_spans: Dict[str, Span] = {}
current_context_token = None
class ContextableList(iterable=(), /)[source]

Bases: list

Since the classic way to process SQS messages is using a for loop, without a well defined scope like a callback - we are doing something similar to the instrumentation of Kafka-python and instrumenting the __iter__ functions and the __getitem__ functions to set the span context of the addressed message. Since the return value from an SQS.ReceiveMessage returns a builtin list, we cannot wrap it and change all of the calls for list.__iter__ and list.__getitem__ - therefore we use ContextableList. It is bound to the received_messages_spans dict

instrumentation_dependencies()[source]

Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or pyproject.toml.

For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection[str]

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.