Skip to content

Docs for Pyramid and SQLite3 #806

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
merged 4 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ opentracing~=2.2.0
prometheus_client>=0.5.0,<1.0.0
psycopg2-binary>=2.7.3.1
pymongo~=3.1
pyramid>=1.7
redis>=2.6
sqlalchemy>=1.0
thrift>=0.10.0
Expand Down
7 changes: 7 additions & 0 deletions docs/ext/pyramid/pyramid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry Pyramid Integration
=================================

.. automodule:: opentelemetry.ext.pyramid
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/ext/sqlite3/sqlite3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry SQLite3 Integration
=================================

.. automodule:: opentelemetry.ext.sqlite3
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@

Usage
-----
There are two methods to instrument Pyramid:
There are two methods to instrument Pyramid:

Method 1 (Instrument all Configurators):
----------------------------------------

.. code:: python

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

PyramidInstrumentor.instrument()
PyramidInstrumentor().instrument()

config = Configurator()

Expand All @@ -38,6 +39,7 @@

Method 2 (Instrument one Configurator):
---------------------------------------

.. code:: python

from pyramid.config import Configurator
Expand All @@ -49,22 +51,30 @@
# use your config as normal
config.add_route('index', '/')

Using ``pyramid.tweens`` settings:
----------------------------------
If you use Method 2 and then set tweens for your application with the ``pyramid.tweens`` setting,
you need to add ``opentelemetry.ext.pyramid.trace_tween_factory`` explicity to the list,
*as well as* instrumenting the config with `PyramidInstrumentor().instrument_config(config)`.
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.ext.pyramid.trace_tween_factory`` explicity to the list,
*as well as* instrumenting the config as shown above.

For example:

For example:
.. code:: python

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

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

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

API
---
"""

Expand All @@ -87,7 +97,7 @@
from opentelemetry.trace import TracerProvider, get_tracer


def traced_init(wrapped, instance, args, kwargs):
def _traced_init(wrapped, instance, args, kwargs):
settings = kwargs.get("settings", {})
tweens = aslist(settings.get("pyramid.tweens", []))

Expand Down Expand Up @@ -119,7 +129,7 @@ def _instrument(self, **kwargs):
"""Integrate with Pyramid Python library.
https://docs.pylonsproject.org/projects/pyramid/en/latest/
"""
_wrap("pyramid.config", "Configurator.__init__", traced_init)
_wrap("pyramid.config", "Configurator.__init__", _traced_init)

def _uninstrument(self, **kwargs):
""""Disable Pyramid instrumentation"""
Expand All @@ -131,9 +141,6 @@ def instrument_config(self, config):

Args:
config: The Configurator to instrument.

Returns:
An instrumented Configurator.
"""
config.include("opentelemetry.ext.pyramid.callbacks")

Expand Down