OpenTelemetry Pyramid Instrumentation

Pyramid instrumentation supporting pyramid, it can be enabled by using PyramidInstrumentor.

Usage

There are two methods to instrument Pyramid:

Method 1 (Instrument all Configurators):

from pyramid.config import Configurator
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor

PyramidInstrumentor().instrument()

config = Configurator()

# use your config as normal
config.add_route('index', '/')

Method 2 (Instrument one Configurator):

from pyramid.config import Configurator
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor

config = Configurator()
PyramidInstrumentor().instrument_config(config)

# use your config as normal
config.add_route('index', '/')

Using pyramid.tweens setting:

If you use Method 2 and then set tweens for your application with the pyramid.tweens setting, you need to add opentelemetry.instrumentation.pyramid.trace_tween_factory explicity to the list, as well as instrumenting the config as shown above.

For example:

from pyramid.config import Configurator
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor

settings = {
    'pyramid.tweens', 'opentelemetry.instrumentation.pyramid.trace_tween_factory\nyour_tween_no_1\nyour_tween_no_2',
}
config = Configurator(settings=settings)
PyramidInstrumentor().instrument_config(config)

# use your config as normal.
config.add_route('index', '/')

API

class opentelemetry.instrumentation.pyramid.PyramidInstrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

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 setup.py.

For example, if an instrumentation instruments requests 1.x, this method should look like:

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.

Return type

Collection[str]

static instrument_config(config)[source]

Enable instrumentation in a Pyramid configurator.

Parameters

config – The Configurator to instrument.

static uninstrument_config(config)[source]