Skip to content

Commit dbea679

Browse files
authored
Add auto-discovery to working_set; add safeties (#97)
1 parent b1b47a6 commit dbea679

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

instana/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import absolute_import
22

33
import os
4-
from pkg_resources import get_distribution
4+
import pkg_resources
5+
56

67
"""
78
The Instana package has two core components: the agent and the tracer.
@@ -22,14 +23,20 @@
2223
Recorder
2324
"""
2425

26+
pkg_resources.working_set.add_entry("/tmp/instana/python")
27+
2528
__author__ = 'Instana Inc.'
2629
__copyright__ = 'Copyright 2017 Instana Inc.'
2730
__credits__ = ['Pavlo Baron', 'Peter Giacomo Lombardo']
2831
__license__ = 'MIT'
29-
__version__ = get_distribution('instana').version
3032
__maintainer__ = 'Peter Giacomo Lombardo'
3133
__email__ = '[email protected]'
3234

35+
try:
36+
__version__ = pkg_resources.get_distribution('instana').version
37+
except pkg_resources.DistributionNotFound:
38+
__version__ = 'unknown'
39+
3340

3441
def load(module):
3542
"""

instana/fsm.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import threading as t
99

1010
import fysom as f
11-
from pkg_resources import get_distribution
11+
import pkg_resources
1212

13-
from .agent_const import AGENT_HEADER, AGENT_DISCOVERY_URL, AGENT_DATA_URL, AGENT_DEFAULT_HOST, AGENT_DEFAULT_PORT
13+
from .agent_const import (AGENT_DATA_URL, AGENT_DEFAULT_HOST,
14+
AGENT_DEFAULT_PORT, AGENT_DISCOVERY_URL,
15+
AGENT_HEADER)
1416
from .log import logger
1517

1618

@@ -44,8 +46,13 @@ class Fsm(object):
4446
warnedPeriodic = False
4547

4648
def __init__(self, agent):
47-
logger.info("Stan is on the scene. Starting Instana instrumentation version: %s" %
48-
get_distribution('instana').version)
49+
package_version = 'unknown'
50+
try:
51+
package_version = pkg_resources.get_distribution('instana').version
52+
except pkg_resources.DistributionNotFound:
53+
pass
54+
55+
logger.info("Stan is on the scene. Starting Instana instrumentation version: %s" % package_version)
4956
logger.debug("initializing fsm")
5057

5158
self.agent = agent

0 commit comments

Comments
 (0)