File tree 2 files changed +42
-0
lines changed
opentelemetry-instrumentation/src/opentelemetry/instrumentation
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
import sys
16
+ import logging
16
17
from logging import getLogger
17
18
from os import environ , path
18
19
from os .path import abspath , dirname , pathsep
23
24
from opentelemetry .environment_variables import (
24
25
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS ,
25
26
)
27
+ from opentelemetry .instrumentation .resources import get_target_dependency_conflict
26
28
29
+ logging .basicConfig (level = logging .DEBUG )
27
30
logger = getLogger (__file__ )
28
31
29
32
@@ -53,6 +56,13 @@ def _load_instrumentors():
53
56
"Instrumentation skipped for library %s" , entry_point .name
54
57
)
55
58
continue
59
+
60
+ # check if instrumentor has any missing or conflicting dependencies
61
+ conflict = get_target_dependency_conflict (entry_point .dist )
62
+ if conflict :
63
+ logger .debug (conflict )
64
+ continue
65
+
56
66
entry_point .load ()().instrument () # type: ignore
57
67
logger .debug ("Instrumented %s" , entry_point .name )
58
68
except Exception as exc : # pylint: disable=broad-except
Original file line number Diff line number Diff line change
1
+ from typing import Optional
2
+ from pkg_resources import get_distribution , VersionConflict , DistributionNotFound
3
+
4
+
5
+ class DependencyConflict :
6
+ required : str = None
7
+ found : Optional [str ] = None
8
+
9
+ def __init__ (self , required , found = None ):
10
+ self .required = required
11
+ self .found = found
12
+
13
+ def __str__ (self ):
14
+ return 'DependencyConflict: requested: "{0}" but found: "{1}"' .format (self .required , self .found )
15
+
16
+
17
+ def get_target_dependency_conflict (dist ) -> Optional [DependencyConflict ]:
18
+
19
+ # skip the check if the distribution has not specified any target dependencies
20
+ if 'target' not in dist .extras :
21
+ return
22
+
23
+ # figure out target dependencies
24
+ target_dependencies = [dep for dep in dist .requires (('target' ,)) if dep not in dist .requires ()]
25
+ for dep in target_dependencies :
26
+ try :
27
+ get_distribution (str (dep ))
28
+ except VersionConflict as exc :
29
+ return DependencyConflict (dep , exc .dist )
30
+ except DistributionNotFound as exc :
31
+ return DependencyConflict (dep )
32
+ return
You can’t perform that action at this time.
0 commit comments