opentelemetry-instrumentation 0.39b0__tar.gz → 0.41b0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/PKG-INFO +7 -2
  2. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/README.rst +6 -1
  3. opentelemetry_instrumentation-0.39b0/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py → opentelemetry_instrumentation-0.41b0/src/opentelemetry/instrumentation/auto_instrumentation/_load.py +38 -41
  4. opentelemetry_instrumentation-0.41b0/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py +44 -0
  5. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/bootstrap_gen.py +58 -46
  6. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/environment_variables.py +10 -0
  7. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/utils.py +1 -1
  8. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/version.py +1 -1
  9. opentelemetry_instrumentation-0.41b0/tests/auto_instrumentation/test_load.py +312 -0
  10. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/.gitignore +0 -0
  11. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/LICENSE +0 -0
  12. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/pyproject.toml +0 -0
  13. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +0 -0
  14. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/bootstrap.py +0 -0
  15. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/dependencies.py +0 -0
  16. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/distro.py +0 -0
  17. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/instrumentor.py +0 -0
  18. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/propagators.py +0 -0
  19. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/py.typed +0 -0
  20. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/src/opentelemetry/instrumentation/sqlcommenter_utils.py +0 -0
  21. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/__init__.py +0 -0
  22. {opentelemetry_instrumentation-0.39b0/tests → opentelemetry_instrumentation-0.41b0/tests/auto_instrumentation}/test_run.py +0 -0
  23. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_bootstrap.py +0 -0
  24. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_dependencies.py +0 -0
  25. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_distro.py +0 -0
  26. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_instrumentor.py +0 -0
  27. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_propagators.py +0 -0
  28. {opentelemetry_instrumentation-0.39b0 → opentelemetry_instrumentation-0.41b0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentelemetry-instrumentation
3
- Version: 0.39b0
3
+ Version: 0.41b0
4
4
  Summary: Instrumentation Tools & Auto Instrumentation for OpenTelemetry Python
5
5
  Project-URL: Homepage, https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/opentelemetry-instrumentation
6
6
  Author-email: OpenTelemetry Authors <cncf-opentelemetry-contributors@lists.cncf.io>
@@ -43,12 +43,15 @@ This package provides a couple of commands that help automatically instruments a
43
43
 
44
44
  .. note::
45
45
  You need to install a distro package to get auto instrumentation working. The ``opentelemetry-distro``
46
- package contains the default distro and automatically configures some of the common options for users.
46
+ package contains the default distro and configurator and automatically configures some of the common options for users.
47
47
  For more info about ``opentelemetry-distro`` check `here <https://opentelemetry-python.readthedocs.io/en/latest/examples/distro/README.html>`__
48
48
  ::
49
49
 
50
50
  pip install opentelemetry-distro[otlp]
51
51
 
52
+ When creating a custom distro and/or configurator, be sure to add entry points for each under `opentelemetry_distro` and `opentelemetry_configurator` respectfully.
53
+ If you have entry points for multiple distros or configurators present in your environment, you should specify the entry point name of the distro and configurator you want to be used via the `OTEL_PYTHON_DISTRO` and `OTEL_PYTHON_CONFIGURATOR` environment variables.
54
+
52
55
 
53
56
  opentelemetry-bootstrap
54
57
  -----------------------
@@ -83,6 +86,8 @@ The command supports the following configuration options as CLI arguments and en
83
86
 
84
87
  * ``--traces_exporter`` or ``OTEL_TRACES_EXPORTER``
85
88
  * ``--metrics_exporter`` or ``OTEL_METRICS_EXPORTER``
89
+ * ``--distro`` or ``OTEL_PYTHON_DISTRO``
90
+ * ``--configurator`` or ``OTEL_PYTHON_CONFIGURATOR``
86
91
 
87
92
  Used to specify which trace exporter to use. Can be set to one or more of the well-known exporter
88
93
  names (see below).
@@ -18,12 +18,15 @@ This package provides a couple of commands that help automatically instruments a
18
18
 
19
19
  .. note::
20
20
  You need to install a distro package to get auto instrumentation working. The ``opentelemetry-distro``
21
- package contains the default distro and automatically configures some of the common options for users.
21
+ package contains the default distro and configurator and automatically configures some of the common options for users.
22
22
  For more info about ``opentelemetry-distro`` check `here <https://opentelemetry-python.readthedocs.io/en/latest/examples/distro/README.html>`__
23
23
  ::
24
24
 
25
25
  pip install opentelemetry-distro[otlp]
26
26
 
27
+ When creating a custom distro and/or configurator, be sure to add entry points for each under `opentelemetry_distro` and `opentelemetry_configurator` respectfully.
28
+ If you have entry points for multiple distros or configurators present in your environment, you should specify the entry point name of the distro and configurator you want to be used via the `OTEL_PYTHON_DISTRO` and `OTEL_PYTHON_CONFIGURATOR` environment variables.
29
+
27
30
 
28
31
  opentelemetry-bootstrap
29
32
  -----------------------
@@ -58,6 +61,8 @@ The command supports the following configuration options as CLI arguments and en
58
61
 
59
62
  * ``--traces_exporter`` or ``OTEL_TRACES_EXPORTER``
60
63
  * ``--metrics_exporter`` or ``OTEL_METRICS_EXPORTER``
64
+ * ``--distro`` or ``OTEL_PYTHON_DISTRO``
65
+ * ``--configurator`` or ``OTEL_PYTHON_CONFIGURATOR``
61
66
 
62
67
  Used to specify which trace exporter to use. Can be set to one or more of the well-known exporter
63
68
  names (see below).
@@ -14,7 +14,6 @@
14
14
 
15
15
  from logging import getLogger
16
16
  from os import environ
17
- from os.path import abspath, dirname, pathsep
18
17
 
19
18
  from pkg_resources import iter_entry_points
20
19
 
@@ -23,30 +22,34 @@ from opentelemetry.instrumentation.dependencies import (
23
22
  )
24
23
  from opentelemetry.instrumentation.distro import BaseDistro, DefaultDistro
25
24
  from opentelemetry.instrumentation.environment_variables import (
25
+ OTEL_PYTHON_CONFIGURATOR,
26
26
  OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
27
+ OTEL_PYTHON_DISTRO,
27
28
  )
28
- from opentelemetry.instrumentation.utils import _python_path_without_directory
29
29
  from opentelemetry.instrumentation.version import __version__
30
30
 
31
- logger = getLogger(__name__)
31
+ _logger = getLogger(__name__)
32
32
 
33
33
 
34
- def _load_distros() -> BaseDistro:
34
+ def _load_distro() -> BaseDistro:
35
+ distro_name = environ.get(OTEL_PYTHON_DISTRO, None)
35
36
  for entry_point in iter_entry_points("opentelemetry_distro"):
36
37
  try:
37
- distro = entry_point.load()()
38
- if not isinstance(distro, BaseDistro):
39
- logger.debug(
40
- "%s is not an OpenTelemetry Distro. Skipping",
41
- entry_point.name,
38
+ # If no distro is specified, use first to come up.
39
+ if distro_name is None or distro_name == entry_point.name:
40
+ distro = entry_point.load()()
41
+ if not isinstance(distro, BaseDistro):
42
+ _logger.debug(
43
+ "%s is not an OpenTelemetry Distro. Skipping",
44
+ entry_point.name,
45
+ )
46
+ continue
47
+ _logger.debug(
48
+ "Distribution %s will be configured", entry_point.name
42
49
  )
43
- continue
44
- logger.debug(
45
- "Distribution %s will be configured", entry_point.name
46
- )
47
- return distro
50
+ return distro
48
51
  except Exception as exc: # pylint: disable=broad-except
49
- logger.exception(
52
+ _logger.exception(
50
53
  "Distribution %s configuration failed", entry_point.name
51
54
  )
52
55
  raise exc
@@ -65,7 +68,7 @@ def _load_instrumentors(distro):
65
68
 
66
69
  for entry_point in iter_entry_points("opentelemetry_instrumentor"):
67
70
  if entry_point.name in package_to_exclude:
68
- logger.debug(
71
+ _logger.debug(
69
72
  "Instrumentation skipped for library %s", entry_point.name
70
73
  )
71
74
  continue
@@ -73,7 +76,7 @@ def _load_instrumentors(distro):
73
76
  try:
74
77
  conflict = get_dist_dependency_conflicts(entry_point.dist)
75
78
  if conflict:
76
- logger.debug(
79
+ _logger.debug(
77
80
  "Skipping instrumentation %s: %s",
78
81
  entry_point.name,
79
82
  conflict,
@@ -82,9 +85,9 @@ def _load_instrumentors(distro):
82
85
 
83
86
  # tell instrumentation to not run dep checks again as we already did it above
84
87
  distro.load_instrumentor(entry_point, skip_dep_check=True)
85
- logger.debug("Instrumented %s", entry_point.name)
88
+ _logger.debug("Instrumented %s", entry_point.name)
86
89
  except Exception as exc: # pylint: disable=broad-except
87
- logger.exception("Instrumenting of %s failed", entry_point.name)
90
+ _logger.exception("Instrumenting of %s failed", entry_point.name)
88
91
  raise exc
89
92
 
90
93
  for entry_point in iter_entry_points("opentelemetry_post_instrument"):
@@ -92,36 +95,30 @@ def _load_instrumentors(distro):
92
95
 
93
96
 
94
97
  def _load_configurators():
98
+ configurator_name = environ.get(OTEL_PYTHON_CONFIGURATOR, None)
95
99
  configured = None
96
100
  for entry_point in iter_entry_points("opentelemetry_configurator"):
97
101
  if configured is not None:
98
- logger.warning(
102
+ _logger.warning(
99
103
  "Configuration of %s not loaded, %s already loaded",
100
104
  entry_point.name,
101
105
  configured,
102
106
  )
103
107
  continue
104
108
  try:
105
- entry_point.load()().configure(auto_instrumentation_version=__version__) # type: ignore
106
- configured = entry_point.name
109
+ if (
110
+ configurator_name is None
111
+ or configurator_name == entry_point.name
112
+ ):
113
+ entry_point.load()().configure(auto_instrumentation_version=__version__) # type: ignore
114
+ configured = entry_point.name
115
+ else:
116
+ _logger.warning(
117
+ "Configuration of %s not loaded because %s is set by %s",
118
+ entry_point.name,
119
+ configurator_name,
120
+ OTEL_PYTHON_CONFIGURATOR,
121
+ )
107
122
  except Exception as exc: # pylint: disable=broad-except
108
- logger.exception("Configuration of %s failed", entry_point.name)
123
+ _logger.exception("Configuration of %s failed", entry_point.name)
109
124
  raise exc
110
-
111
-
112
- def initialize():
113
- # prevents auto-instrumentation of subprocesses if code execs another python process
114
- environ["PYTHONPATH"] = _python_path_without_directory(
115
- environ["PYTHONPATH"], dirname(abspath(__file__)), pathsep
116
- )
117
-
118
- try:
119
- distro = _load_distros()
120
- distro.configure()
121
- _load_configurators()
122
- _load_instrumentors(distro)
123
- except Exception: # pylint: disable=broad-except
124
- logger.exception("Failed to auto initialize opentelemetry")
125
-
126
-
127
- initialize()
@@ -0,0 +1,44 @@
1
+ # Copyright The OpenTelemetry Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from logging import getLogger
16
+ from os import environ
17
+ from os.path import abspath, dirname, pathsep
18
+
19
+ from opentelemetry.instrumentation.auto_instrumentation._load import (
20
+ _load_configurators,
21
+ _load_distro,
22
+ _load_instrumentors,
23
+ )
24
+ from opentelemetry.instrumentation.utils import _python_path_without_directory
25
+
26
+ logger = getLogger(__name__)
27
+
28
+
29
+ def initialize():
30
+ # prevents auto-instrumentation of subprocesses if code execs another python process
31
+ environ["PYTHONPATH"] = _python_path_without_directory(
32
+ environ["PYTHONPATH"], dirname(abspath(__file__)), pathsep
33
+ )
34
+
35
+ try:
36
+ distro = _load_distro()
37
+ distro.configure()
38
+ _load_configurators()
39
+ _load_instrumentors(distro)
40
+ except Exception: # pylint: disable=broad-except
41
+ logger.exception("Failed to auto initialize opentelemetry")
42
+
43
+
44
+ initialize()
@@ -18,158 +18,170 @@
18
18
  libraries = {
19
19
  "aio_pika": {
20
20
  "library": "aio_pika >= 7.2.0, < 10.0.0",
21
- "instrumentation": "opentelemetry-instrumentation-aio-pika==0.39b0",
21
+ "instrumentation": "opentelemetry-instrumentation-aio-pika==0.41b0",
22
22
  },
23
23
  "aiohttp": {
24
24
  "library": "aiohttp ~= 3.0",
25
- "instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.39b0",
25
+ "instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.41b0",
26
26
  },
27
27
  "aiopg": {
28
28
  "library": "aiopg >= 0.13.0, < 2.0.0",
29
- "instrumentation": "opentelemetry-instrumentation-aiopg==0.39b0",
29
+ "instrumentation": "opentelemetry-instrumentation-aiopg==0.41b0",
30
30
  },
31
31
  "asgiref": {
32
32
  "library": "asgiref ~= 3.0",
33
- "instrumentation": "opentelemetry-instrumentation-asgi==0.39b0",
33
+ "instrumentation": "opentelemetry-instrumentation-asgi==0.41b0",
34
34
  },
35
35
  "asyncpg": {
36
36
  "library": "asyncpg >= 0.12.0",
37
- "instrumentation": "opentelemetry-instrumentation-asyncpg==0.39b0",
37
+ "instrumentation": "opentelemetry-instrumentation-asyncpg==0.41b0",
38
38
  },
39
39
  "boto": {
40
40
  "library": "boto~=2.0",
41
- "instrumentation": "opentelemetry-instrumentation-boto==0.39b0",
41
+ "instrumentation": "opentelemetry-instrumentation-boto==0.41b0",
42
42
  },
43
43
  "boto3": {
44
44
  "library": "boto3 ~= 1.0",
45
- "instrumentation": "opentelemetry-instrumentation-boto3sqs==0.39b0",
45
+ "instrumentation": "opentelemetry-instrumentation-boto3sqs==0.41b0",
46
46
  },
47
47
  "botocore": {
48
48
  "library": "botocore ~= 1.0",
49
- "instrumentation": "opentelemetry-instrumentation-botocore==0.39b0",
49
+ "instrumentation": "opentelemetry-instrumentation-botocore==0.41b0",
50
+ },
51
+ "cassandra-driver": {
52
+ "library": "cassandra-driver ~= 3.25",
53
+ "instrumentation": "opentelemetry-instrumentation-cassandra==0.41b0",
54
+ },
55
+ "scylla-driver": {
56
+ "library": "scylla-driver ~= 3.25",
57
+ "instrumentation": "opentelemetry-instrumentation-cassandra==0.41b0",
50
58
  },
51
59
  "celery": {
52
60
  "library": "celery >= 4.0, < 6.0",
53
- "instrumentation": "opentelemetry-instrumentation-celery==0.39b0",
61
+ "instrumentation": "opentelemetry-instrumentation-celery==0.41b0",
54
62
  },
55
63
  "confluent-kafka": {
56
- "library": "confluent-kafka >= 1.8.2, < 2.0.0",
57
- "instrumentation": "opentelemetry-instrumentation-confluent-kafka==0.39b0",
64
+ "library": "confluent-kafka >= 1.8.2, <= 2.2.0",
65
+ "instrumentation": "opentelemetry-instrumentation-confluent-kafka==0.41b0",
58
66
  },
59
67
  "django": {
60
68
  "library": "django >= 1.10",
61
- "instrumentation": "opentelemetry-instrumentation-django==0.39b0",
69
+ "instrumentation": "opentelemetry-instrumentation-django==0.41b0",
62
70
  },
63
71
  "elasticsearch": {
64
72
  "library": "elasticsearch >= 2.0",
65
- "instrumentation": "opentelemetry-instrumentation-elasticsearch==0.39b0",
73
+ "instrumentation": "opentelemetry-instrumentation-elasticsearch==0.41b0",
66
74
  },
67
75
  "falcon": {
68
76
  "library": "falcon >= 1.4.1, < 4.0.0",
69
- "instrumentation": "opentelemetry-instrumentation-falcon==0.39b0",
77
+ "instrumentation": "opentelemetry-instrumentation-falcon==0.41b0",
70
78
  },
71
79
  "fastapi": {
72
80
  "library": "fastapi ~= 0.58",
73
- "instrumentation": "opentelemetry-instrumentation-fastapi==0.39b0",
81
+ "instrumentation": "opentelemetry-instrumentation-fastapi==0.41b0",
74
82
  },
75
83
  "flask": {
76
84
  "library": "flask >= 1.0, < 3.0",
77
- "instrumentation": "opentelemetry-instrumentation-flask==0.39b0",
85
+ "instrumentation": "opentelemetry-instrumentation-flask==0.41b0",
78
86
  },
79
87
  "grpcio": {
80
88
  "library": "grpcio ~= 1.27",
81
- "instrumentation": "opentelemetry-instrumentation-grpc==0.39b0",
89
+ "instrumentation": "opentelemetry-instrumentation-grpc==0.41b0",
82
90
  },
83
91
  "httpx": {
84
- "library": "httpx >= 0.18.0, <= 0.23.0",
85
- "instrumentation": "opentelemetry-instrumentation-httpx==0.39b0",
92
+ "library": "httpx >= 0.18.0",
93
+ "instrumentation": "opentelemetry-instrumentation-httpx==0.41b0",
86
94
  },
87
95
  "jinja2": {
88
96
  "library": "jinja2 >= 2.7, < 4.0",
89
- "instrumentation": "opentelemetry-instrumentation-jinja2==0.39b0",
97
+ "instrumentation": "opentelemetry-instrumentation-jinja2==0.41b0",
90
98
  },
91
99
  "kafka-python": {
92
100
  "library": "kafka-python >= 2.0",
93
- "instrumentation": "opentelemetry-instrumentation-kafka-python==0.39b0",
101
+ "instrumentation": "opentelemetry-instrumentation-kafka-python==0.41b0",
94
102
  },
95
103
  "mysql-connector-python": {
96
104
  "library": "mysql-connector-python ~= 8.0",
97
- "instrumentation": "opentelemetry-instrumentation-mysql==0.39b0",
105
+ "instrumentation": "opentelemetry-instrumentation-mysql==0.41b0",
106
+ },
107
+ "mysqlclient": {
108
+ "library": "mysqlclient < 3",
109
+ "instrumentation": "opentelemetry-instrumentation-mysqlclient==0.41b0",
98
110
  },
99
111
  "pika": {
100
112
  "library": "pika >= 0.12.0",
101
- "instrumentation": "opentelemetry-instrumentation-pika==0.39b0",
113
+ "instrumentation": "opentelemetry-instrumentation-pika==0.41b0",
102
114
  },
103
115
  "psycopg2": {
104
116
  "library": "psycopg2 >= 2.7.3.1",
105
- "instrumentation": "opentelemetry-instrumentation-psycopg2==0.39b0",
117
+ "instrumentation": "opentelemetry-instrumentation-psycopg2==0.41b0",
106
118
  },
107
119
  "pymemcache": {
108
120
  "library": "pymemcache >= 1.3.5, < 5",
109
- "instrumentation": "opentelemetry-instrumentation-pymemcache==0.39b0",
121
+ "instrumentation": "opentelemetry-instrumentation-pymemcache==0.41b0",
110
122
  },
111
123
  "pymongo": {
112
124
  "library": "pymongo >= 3.1, < 5.0",
113
- "instrumentation": "opentelemetry-instrumentation-pymongo==0.39b0",
125
+ "instrumentation": "opentelemetry-instrumentation-pymongo==0.41b0",
114
126
  },
115
127
  "PyMySQL": {
116
128
  "library": "PyMySQL < 2",
117
- "instrumentation": "opentelemetry-instrumentation-pymysql==0.39b0",
129
+ "instrumentation": "opentelemetry-instrumentation-pymysql==0.41b0",
118
130
  },
119
131
  "pyramid": {
120
132
  "library": "pyramid >= 1.7",
121
- "instrumentation": "opentelemetry-instrumentation-pyramid==0.39b0",
133
+ "instrumentation": "opentelemetry-instrumentation-pyramid==0.41b0",
122
134
  },
123
135
  "redis": {
124
136
  "library": "redis >= 2.6",
125
- "instrumentation": "opentelemetry-instrumentation-redis==0.39b0",
137
+ "instrumentation": "opentelemetry-instrumentation-redis==0.41b0",
126
138
  },
127
139
  "remoulade": {
128
140
  "library": "remoulade >= 0.50",
129
- "instrumentation": "opentelemetry-instrumentation-remoulade==0.39b0",
141
+ "instrumentation": "opentelemetry-instrumentation-remoulade==0.41b0",
130
142
  },
131
143
  "requests": {
132
144
  "library": "requests ~= 2.0",
133
- "instrumentation": "opentelemetry-instrumentation-requests==0.39b0",
145
+ "instrumentation": "opentelemetry-instrumentation-requests==0.41b0",
134
146
  },
135
147
  "scikit-learn": {
136
148
  "library": "scikit-learn ~= 0.24.0",
137
- "instrumentation": "opentelemetry-instrumentation-sklearn==0.39b0",
149
+ "instrumentation": "opentelemetry-instrumentation-sklearn==0.41b0",
138
150
  },
139
151
  "sqlalchemy": {
140
152
  "library": "sqlalchemy",
141
- "instrumentation": "opentelemetry-instrumentation-sqlalchemy==0.39b0",
153
+ "instrumentation": "opentelemetry-instrumentation-sqlalchemy==0.41b0",
142
154
  },
143
155
  "starlette": {
144
156
  "library": "starlette ~= 0.13.0",
145
- "instrumentation": "opentelemetry-instrumentation-starlette==0.39b0",
157
+ "instrumentation": "opentelemetry-instrumentation-starlette==0.41b0",
146
158
  },
147
159
  "psutil": {
148
160
  "library": "psutil >= 5",
149
- "instrumentation": "opentelemetry-instrumentation-system-metrics==0.39b0",
161
+ "instrumentation": "opentelemetry-instrumentation-system-metrics==0.41b0",
150
162
  },
151
163
  "tornado": {
152
164
  "library": "tornado >= 5.1.1",
153
- "instrumentation": "opentelemetry-instrumentation-tornado==0.39b0",
165
+ "instrumentation": "opentelemetry-instrumentation-tornado==0.41b0",
154
166
  },
155
167
  "tortoise-orm": {
156
168
  "library": "tortoise-orm >= 0.17.0",
157
- "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.39b0",
169
+ "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.41b0",
158
170
  },
159
171
  "pydantic": {
160
172
  "library": "pydantic >= 1.10.2",
161
- "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.39b0",
173
+ "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.41b0",
162
174
  },
163
175
  "urllib3": {
164
- "library": "urllib3 >= 1.0.0, < 2.0.0",
165
- "instrumentation": "opentelemetry-instrumentation-urllib3==0.39b0",
176
+ "library": "urllib3 >= 1.0.0, < 3.0.0",
177
+ "instrumentation": "opentelemetry-instrumentation-urllib3==0.41b0",
166
178
  },
167
179
  }
168
180
  default_instrumentations = [
169
- "opentelemetry-instrumentation-aws-lambda==0.39b0",
170
- "opentelemetry-instrumentation-dbapi==0.39b0",
171
- "opentelemetry-instrumentation-logging==0.39b0",
172
- "opentelemetry-instrumentation-sqlite3==0.39b0",
173
- "opentelemetry-instrumentation-urllib==0.39b0",
174
- "opentelemetry-instrumentation-wsgi==0.39b0",
181
+ "opentelemetry-instrumentation-aws-lambda==0.41b0",
182
+ "opentelemetry-instrumentation-dbapi==0.41b0",
183
+ "opentelemetry-instrumentation-logging==0.41b0",
184
+ "opentelemetry-instrumentation-sqlite3==0.41b0",
185
+ "opentelemetry-instrumentation-urllib==0.41b0",
186
+ "opentelemetry-instrumentation-wsgi==0.41b0",
175
187
  ]
@@ -16,3 +16,13 @@ OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"
16
16
  """
17
17
  .. envvar:: OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
18
18
  """
19
+
20
+ OTEL_PYTHON_DISTRO = "OTEL_PYTHON_DISTRO"
21
+ """
22
+ .. envvar:: OTEL_PYTHON_DISTRO
23
+ """
24
+
25
+ OTEL_PYTHON_CONFIGURATOR = "OTEL_PYTHON_CONFIGURATOR"
26
+ """
27
+ .. envvar:: OTEL_PYTHON_CONFIGURATOR
28
+ """
@@ -95,7 +95,7 @@ def _start_internal_or_server_span(
95
95
 
96
96
  Args:
97
97
  tracer : tracer in use by given instrumentation library
98
- name (string): name of the span
98
+ span_name (string): name of the span
99
99
  start_time : start time of the span
100
100
  context_carrier : object which contains values that are
101
101
  used to construct a Context. This object
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "0.39b0"
15
+ __version__ = "0.41b0"
@@ -0,0 +1,312 @@
1
+ # Copyright The OpenTelemetry Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # type: ignore
15
+
16
+ from unittest import TestCase
17
+ from unittest.mock import Mock, call, patch
18
+
19
+ from opentelemetry.instrumentation.auto_instrumentation import _load
20
+ from opentelemetry.instrumentation.environment_variables import (
21
+ OTEL_PYTHON_CONFIGURATOR,
22
+ OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
23
+ OTEL_PYTHON_DISTRO,
24
+ )
25
+ from opentelemetry.instrumentation.version import __version__
26
+
27
+
28
+ class TestLoad(TestCase):
29
+ @patch.dict(
30
+ "os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
31
+ )
32
+ @patch(
33
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
34
+ )
35
+ def test_load_configurators(self, iter_mock):
36
+ # Add multiple entry points but only specify the 2nd in the environment variable.
37
+ ep_mock1 = Mock()
38
+ ep_mock1.name = "custom_configurator1"
39
+ configurator_mock1 = Mock()
40
+ ep_mock1.load.return_value = configurator_mock1
41
+ ep_mock2 = Mock()
42
+ ep_mock2.name = "custom_configurator2"
43
+ configurator_mock2 = Mock()
44
+ ep_mock2.load.return_value = configurator_mock2
45
+ ep_mock3 = Mock()
46
+ ep_mock3.name = "custom_configurator3"
47
+ configurator_mock3 = Mock()
48
+ ep_mock3.load.return_value = configurator_mock3
49
+
50
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3)
51
+ _load._load_configurators()
52
+ configurator_mock1.assert_not_called()
53
+ configurator_mock2().configure.assert_called_once_with(
54
+ auto_instrumentation_version=__version__
55
+ )
56
+ configurator_mock3.assert_not_called()
57
+
58
+ @patch.dict(
59
+ "os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
60
+ )
61
+ @patch(
62
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
63
+ )
64
+ def test_load_configurators_no_ep(
65
+ self,
66
+ iter_mock,
67
+ ):
68
+ iter_mock.return_value = ()
69
+ # Confirm method does not crash if not entry points exist.
70
+ _load._load_configurators()
71
+
72
+ @patch.dict(
73
+ "os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
74
+ )
75
+ @patch(
76
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
77
+ )
78
+ def test_load_configurators_error(self, iter_mock):
79
+ # Add multiple entry points but only specify the 2nd in the environment variable.
80
+ ep_mock1 = Mock()
81
+ ep_mock1.name = "custom_configurator1"
82
+ configurator_mock1 = Mock()
83
+ ep_mock1.load.return_value = configurator_mock1
84
+ ep_mock2 = Mock()
85
+ ep_mock2.name = "custom_configurator2"
86
+ configurator_mock2 = Mock()
87
+ configurator_mock2().configure.side_effect = Exception()
88
+ ep_mock2.load.return_value = configurator_mock2
89
+ ep_mock3 = Mock()
90
+ ep_mock3.name = "custom_configurator3"
91
+ configurator_mock3 = Mock()
92
+ ep_mock3.load.return_value = configurator_mock3
93
+
94
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3)
95
+ # Confirm failed configuration raises exception.
96
+ self.assertRaises(Exception, _load._load_configurators)
97
+
98
+ @patch.dict("os.environ", {OTEL_PYTHON_DISTRO: "custom_distro2"})
99
+ @patch(
100
+ "opentelemetry.instrumentation.auto_instrumentation._load.isinstance"
101
+ )
102
+ @patch(
103
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
104
+ )
105
+ def test_load_distro(self, iter_mock, isinstance_mock):
106
+ # Add multiple entry points but only specify the 2nd in the environment variable.
107
+ ep_mock1 = Mock()
108
+ ep_mock1.name = "custom_distro1"
109
+ distro_mock1 = Mock()
110
+ ep_mock1.load.return_value = distro_mock1
111
+ ep_mock2 = Mock()
112
+ ep_mock2.name = "custom_distro2"
113
+ distro_mock2 = Mock()
114
+ ep_mock2.load.return_value = distro_mock2
115
+ ep_mock3 = Mock()
116
+ ep_mock3.name = "custom_distro3"
117
+ distro_mock3 = Mock()
118
+ ep_mock3.load.return_value = distro_mock3
119
+
120
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3)
121
+ # Mock entry points to be instances of BaseDistro.
122
+ isinstance_mock.return_value = True
123
+ self.assertEqual(
124
+ _load._load_distro(),
125
+ distro_mock2(),
126
+ )
127
+
128
+ @patch.dict("os.environ", {OTEL_PYTHON_DISTRO: "custom_distro2"})
129
+ @patch(
130
+ "opentelemetry.instrumentation.auto_instrumentation._load.isinstance"
131
+ )
132
+ @patch(
133
+ "opentelemetry.instrumentation.auto_instrumentation._load.DefaultDistro"
134
+ )
135
+ @patch(
136
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
137
+ )
138
+ def test_load_distro_not_distro(
139
+ self, iter_mock, default_distro_mock, isinstance_mock
140
+ ):
141
+ # Add multiple entry points but only specify the 2nd in the environment variable.
142
+ ep_mock1 = Mock()
143
+ ep_mock1.name = "custom_distro1"
144
+ distro_mock1 = Mock()
145
+ ep_mock1.load.return_value = distro_mock1
146
+ ep_mock2 = Mock()
147
+ ep_mock2.name = "custom_distro2"
148
+ distro_mock2 = Mock()
149
+ ep_mock2.load.return_value = distro_mock2
150
+ ep_mock3 = Mock()
151
+ ep_mock3.name = "custom_distro3"
152
+ distro_mock3 = Mock()
153
+ ep_mock3.load.return_value = distro_mock3
154
+
155
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3)
156
+ # Confirm default distro is used if specified entry point is not a BaseDistro
157
+ isinstance_mock.return_value = False
158
+ self.assertEqual(
159
+ _load._load_distro(),
160
+ default_distro_mock(),
161
+ )
162
+
163
+ @patch.dict("os.environ", {OTEL_PYTHON_DISTRO: "custom_distro2"})
164
+ @patch(
165
+ "opentelemetry.instrumentation.auto_instrumentation._load.DefaultDistro"
166
+ )
167
+ @patch(
168
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
169
+ )
170
+ def test_load_distro_no_ep(self, iter_mock, default_distro_mock):
171
+ iter_mock.return_value = ()
172
+ # Confirm default distro is used if there are no entry points.
173
+ self.assertEqual(
174
+ _load._load_distro(),
175
+ default_distro_mock(),
176
+ )
177
+
178
+ @patch.dict("os.environ", {OTEL_PYTHON_DISTRO: "custom_distro2"})
179
+ @patch(
180
+ "opentelemetry.instrumentation.auto_instrumentation._load.isinstance"
181
+ )
182
+ @patch(
183
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
184
+ )
185
+ def test_load_distro_error(self, iter_mock, isinstance_mock):
186
+ ep_mock1 = Mock()
187
+ ep_mock1.name = "custom_distro1"
188
+ distro_mock1 = Mock()
189
+ ep_mock1.load.return_value = distro_mock1
190
+ ep_mock2 = Mock()
191
+ ep_mock2.name = "custom_distro2"
192
+ distro_mock2 = Mock()
193
+ distro_mock2.side_effect = Exception()
194
+ ep_mock2.load.return_value = distro_mock2
195
+ ep_mock3 = Mock()
196
+ ep_mock3.name = "custom_distro3"
197
+ distro_mock3 = Mock()
198
+ ep_mock3.load.return_value = distro_mock3
199
+
200
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3)
201
+ isinstance_mock.return_value = True
202
+ # Confirm method raises exception if it fails to load a distro.
203
+ self.assertRaises(Exception, _load._load_distro)
204
+
205
+ @patch.dict(
206
+ "os.environ",
207
+ {OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: " instr1 , instr3 "},
208
+ )
209
+ @patch(
210
+ "opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
211
+ )
212
+ @patch(
213
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
214
+ )
215
+ def test_load_instrumentors(self, iter_mock, dep_mock):
216
+ # Mock opentelemetry_pre_instrument entry points
217
+ pre_ep_mock1 = Mock()
218
+ pre_ep_mock1.name = "pre1"
219
+ pre_mock1 = Mock()
220
+ pre_ep_mock1.load.return_value = pre_mock1
221
+
222
+ pre_ep_mock2 = Mock()
223
+ pre_ep_mock2.name = "pre2"
224
+ pre_mock2 = Mock()
225
+ pre_ep_mock2.load.return_value = pre_mock2
226
+
227
+ # Mock opentelemetry_instrumentor entry points
228
+ ep_mock1 = Mock()
229
+ ep_mock1.name = "instr1"
230
+
231
+ ep_mock2 = Mock()
232
+ ep_mock2.name = "instr2"
233
+
234
+ ep_mock3 = Mock()
235
+ ep_mock3.name = "instr3"
236
+
237
+ ep_mock4 = Mock()
238
+ ep_mock4.name = "instr4"
239
+
240
+ # Mock opentelemetry_instrumentor entry points
241
+ post_ep_mock1 = Mock()
242
+ post_ep_mock1.name = "post1"
243
+ post_mock1 = Mock()
244
+ post_ep_mock1.load.return_value = post_mock1
245
+
246
+ post_ep_mock2 = Mock()
247
+ post_ep_mock2.name = "post2"
248
+ post_mock2 = Mock()
249
+ post_ep_mock2.load.return_value = post_mock2
250
+
251
+ distro_mock = Mock()
252
+
253
+ # Mock entry points in order
254
+ iter_mock.side_effect = [
255
+ (pre_ep_mock1, pre_ep_mock2),
256
+ (ep_mock1, ep_mock2, ep_mock3, ep_mock4),
257
+ (post_ep_mock1, post_ep_mock2),
258
+ ]
259
+ # No dependency conflict
260
+ dep_mock.return_value = None
261
+ _load._load_instrumentors(distro_mock)
262
+ # All opentelemetry_pre_instrument entry points should be loaded
263
+ pre_mock1.assert_called_once()
264
+ pre_mock2.assert_called_once()
265
+ self.assertEqual(iter_mock.call_count, 3)
266
+ # Only non-disabled instrumentations should be loaded
267
+ distro_mock.load_instrumentor.assert_has_calls(
268
+ [
269
+ call(ep_mock2, skip_dep_check=True),
270
+ call(ep_mock4, skip_dep_check=True),
271
+ ]
272
+ )
273
+ self.assertEqual(distro_mock.load_instrumentor.call_count, 2)
274
+ # All opentelemetry_post_instrument entry points should be loaded
275
+ post_mock1.assert_called_once()
276
+ post_mock2.assert_called_once()
277
+
278
+ @patch.dict(
279
+ "os.environ",
280
+ {OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: " instr1 , instr3 "},
281
+ )
282
+ @patch(
283
+ "opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
284
+ )
285
+ @patch(
286
+ "opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
287
+ )
288
+ def test_load_instrumentors_dep_conflict(self, iter_mock, dep_mock):
289
+ ep_mock1 = Mock()
290
+ ep_mock1.name = "instr1"
291
+
292
+ ep_mock2 = Mock()
293
+ ep_mock2.name = "instr2"
294
+
295
+ ep_mock3 = Mock()
296
+ ep_mock3.name = "instr3"
297
+
298
+ ep_mock4 = Mock()
299
+ ep_mock4.name = "instr4"
300
+
301
+ distro_mock = Mock()
302
+
303
+ iter_mock.return_value = (ep_mock1, ep_mock2, ep_mock3, ep_mock4)
304
+ # If a dependency conflict is raised, that instrumentation should not be loaded, but others still should.
305
+ dep_mock.side_effect = [None, "DependencyConflict"]
306
+ _load._load_instrumentors(distro_mock)
307
+ distro_mock.load_instrumentor.assert_has_calls(
308
+ [
309
+ call(ep_mock2, skip_dep_check=True),
310
+ ]
311
+ )
312
+ distro_mock.load_instrumentor.assert_called_once()