Skip to content

Commit 4ac0b94

Browse files
committed
remove old defaults.py and move still-used variables to constants.py (#110)
closes #110
1 parent 9bad675 commit 4ac0b94

File tree

7 files changed

+16
-98
lines changed

7 files changed

+16
-98
lines changed

elasticapm/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import zlib
2323

2424
import elasticapm
25-
from elasticapm.conf import Config, defaults
25+
from elasticapm.conf import Config, constants
2626
from elasticapm.traces import TransactionsStore, get_transaction
2727
from elasticapm.transport.base import TransportException
2828
from elasticapm.utils import json_encoder as json
@@ -226,7 +226,7 @@ def build_msg_for_logging(self, event_type, data=None, date=None,
226226
data = transform(data)
227227

228228
data.update({
229-
'timestamp': date.strftime(defaults.TIMESTAMP_FORMAT),
229+
'timestamp': date.strftime(constants.TIMESTAMP_FORMAT),
230230
})
231231

232232
return self.build_msg({'errors': [data]})
@@ -285,7 +285,7 @@ def capture(self, event_type, data=None, date=None,
285285
data = self.build_msg_for_logging(event_type, data, date, extra, stack, **kwargs)
286286

287287
if data:
288-
url = self.config.server_url + defaults.ERROR_API_PATH
288+
url = self.config.server_url + constants.ERROR_API_PATH
289289
self.send(url, **data)
290290
return data['errors'][0]['id']
291291

@@ -493,7 +493,7 @@ def _collect_transactions(self):
493493
'transactions': transactions,
494494
})
495495

496-
api_path = defaults.TRANSACTIONS_API_PATH
496+
api_path = constants.TRANSACTIONS_API_PATH
497497

498498
self.send(self.config.server_url + api_path, **data)
499499
self._start_send_timer()

elasticapm/conf/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Error API path
2+
ERROR_API_PATH = '/v1/errors'
3+
4+
# Transactions API path
5+
TRANSACTIONS_API_PATH = '/v1/transactions'
6+
7+
TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'

elasticapm/conf/defaults.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

elasticapm/traces.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import uuid
88

9-
from elasticapm.conf import defaults
9+
from elasticapm.conf import constants
1010
from elasticapm.utils import compat, get_name_from_func
1111
from elasticapm.utils.lru import LRUCache
1212

@@ -101,7 +101,7 @@ def to_dict(self):
101101
'type': self.kind,
102102
'duration': self.duration * 1000, # milliseconds
103103
'result': str(self.result),
104-
'timestamp': self.timestamp.strftime(defaults.TIMESTAMP_FORMAT),
104+
'timestamp': self.timestamp.strftime(constants.TIMESTAMP_FORMAT),
105105
'context': self._context,
106106
'traces': [
107107
trace_obj.to_dict() for trace_obj in self.traces

elasticapm/transport/asyncio.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import aiohttp
44

5-
from elasticapm.conf import defaults
6-
75
from .base import TransportException
86
from .http_base import HTTPTransportBase
97

@@ -21,8 +19,6 @@ def __init__(self, parsed_url):
2119
async def send(self, data, headers, timeout=None):
2220
"""Use synchronous interface, because this is a coroutine."""
2321

24-
if timeout is None:
25-
timeout = defaults.TIMEOUT
2622
try:
2723
with aiohttp.Timeout(timeout):
2824
async with self.client.post(self._url,
@@ -32,7 +28,7 @@ async def send(self, data, headers, timeout=None):
3228
except asyncio.TimeoutError as e:
3329
print_trace = True
3430
message = ("Connection to APM Server timed out "
35-
"(url: %s, timeout: %d seconds)" % (self._url, timeout))
31+
"(url: %s, timeout: %s seconds)" % (self._url, timeout))
3632
raise TransportException(message, data,
3733
print_trace=print_trace) from e
3834
except AssertionError as e:

elasticapm/transport/http.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import urllib3
77
from urllib3.exceptions import MaxRetryError, TimeoutError
88

9-
from elasticapm.conf import defaults
109
from elasticapm.transport.base import TransportException
1110
from elasticapm.transport.http_base import (AsyncHTTPTransportBase,
1211
HTTPTransportBase)
@@ -33,8 +32,6 @@ def __init__(self, parsed_url):
3332
super(Transport, self).__init__(parsed_url)
3433

3534
def send(self, data, headers, timeout=None):
36-
if timeout is None:
37-
timeout = defaults.TIMEOUT
3835
response = None
3936

4037
# ensure headers are byte strings
@@ -56,7 +53,7 @@ def send(self, data, headers, timeout=None):
5653
if isinstance(e, MaxRetryError) and isinstance(e.reason, TimeoutError):
5754
message = (
5855
"Connection to APM Server timed out "
59-
"(url: %s, timeout: %d seconds)" % (self._url, timeout)
56+
"(url: %s, timeout: %s seconds)" % (self._url, timeout)
6057
)
6158
print_trace = False
6259
else:

tests/transports/test_urllib3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_timeout():
3030
responses.add('POST', '/', status=202,
3131
body=MaxRetryError(None, None, reason=TimeoutError()))
3232
with pytest.raises(TransportException) as exc_info:
33-
transport.send('x', {})
33+
transport.send('x', {}, timeout=5)
3434
assert 'timeout' in str(exc_info.value)
3535

3636

0 commit comments

Comments
 (0)