Skip to content

Commit e84faa4

Browse files
ocelotltoumorokoshic24t
authored
docs: Add more documentation for the instrumentor base class (#638)
Fixes #637 Co-authored-by: Yusuke Tsutsumi <tsutsumi.yusuke@gmail.com> Co-authored-by: Chris Kleinknecht <libc@google.com>
1 parent 82359d5 commit e84faa4

File tree

2 files changed

+45
-6
lines changed
  • opentelemetry-api/src/opentelemetry/configuration
  • opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation

2 files changed

+45
-6
lines changed

opentelemetry-api/src/opentelemetry/configuration/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@
7474
7575
To use the meter provider above, then the
7676
``OPENTELEMETRY_PYTHON_METER_PROVIDER`` should be set to
77-
"default_meter_provider" (this is not actually necessary since the
77+
``"default_meter_provider"`` (this is not actually necessary since the
7878
OpenTelemetry API provided providers are the default ones used if no
7979
configuration is found in the environment variables).
80+
81+
This object can be used by any OpenTelemetry component, native or external.
82+
For that reason, the ``Configuration`` object is designed to be immutable.
83+
If a component would change the value of one of the ``Configuration`` object
84+
attributes then another component that relied on that value may break, leading
85+
to bugs that are very hard to debug. To avoid this situation, the preferred
86+
approach for components that need a different value than the one provided by
87+
the ``Configuration`` object is to implement a mechanism that allows the user
88+
to override this value instead of changing it.
8089
"""
8190

8291
from os import environ

opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424

2525

2626
class BaseInstrumentor(ABC):
27-
"""An ABC for instrumentors"""
27+
"""An ABC for instrumentors
28+
29+
Child classes of this ABC should instrument specific third
30+
party libraries or frameworks either by using the
31+
``opentelemetry-auto-instrumentation`` command or by calling their methods
32+
directly.
33+
34+
Since every third party library or framework is different and has different
35+
instrumentation needs, more methods can be added to the child classes as
36+
needed to provide practical instrumentation to the end user.
37+
"""
2838

2939
_instance = None
3040
_is_instrumented = False
@@ -38,14 +48,30 @@ def __new__(cls):
3848

3949
@abstractmethod
4050
def _instrument(self, **kwargs):
41-
"""Instrument"""
51+
"""Instrument the library"""
4252

4353
@abstractmethod
4454
def _uninstrument(self, **kwargs):
45-
"""Uninstrument"""
55+
"""Uninstrument the library"""
4656

4757
def instrument(self, **kwargs):
48-
"""Instrument"""
58+
"""Instrument the library
59+
60+
This method will be called without any optional arguments by the
61+
``opentelemetry-auto-instrumentation`` command. The configuration of
62+
the instrumentation when done in this way should be done by previously
63+
setting the configuration (using environment variables or any other
64+
mechanism) that will be used later by the code in the ``instrument``
65+
implementation via the global ``Configuration`` object.
66+
67+
The ``instrument`` methods ``kwargs`` should default to values from the
68+
``Configuration`` object.
69+
70+
This means that calling this method directly without passing any
71+
optional values should do the very same thing that the
72+
``opentelemetry-auto-instrumentation`` command does. This approach is
73+
followed because the ``Configuration`` object is immutable.
74+
"""
4975

5076
if not self._is_instrumented:
5177
result = self._instrument(**kwargs)
@@ -57,7 +83,11 @@ def instrument(self, **kwargs):
5783
return None
5884

5985
def uninstrument(self, **kwargs):
60-
"""Uninstrument"""
86+
"""Uninstrument the library
87+
88+
See ``BaseInstrumentor.instrument`` for more information regarding the
89+
usage of ``kwargs``.
90+
"""
6191

6292
if self._is_instrumented:
6393
result = self._uninstrument(**kwargs)

0 commit comments

Comments
 (0)