Skip to content

Commit ab860d2

Browse files
bripkenspglombardo
authored andcommitted
API improvements (#122)
* Set specific User-Agent in API client The API client should transmit a meaningful `User-Agent` header that will allow us clearly identify users of this API client. * Do not report now timestamps Instana's API optimizes the `now` case. This optimization works best when the `time` parameter isn't defined (this means `now`). We should therefore let the API identify what `now` means and because of that let all the optimizations kick in.
1 parent 35e7753 commit ab860d2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

instana/api.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import certifi
1919
import urllib3
2020
from .log import logger as log
21+
from .util import package_version
2122

2223

2324
PY2 = sys.version_info[0] == 2
@@ -138,7 +139,7 @@ def __init__(self, **kwds):
138139
log.warn("APIClient: API token or Base URL not set. No-op mode")
139140
else:
140141
self.api_key = "apiToken %s" % self.api_token
141-
self.headers = {'Authorization': self.api_key}
142+
self.headers = {'Authorization': self.api_key, 'User-Agent': 'instana-python-sensor v' + package_version()}
142143
self.http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',
143144
ca_certs=certifi.where())
144145

@@ -271,18 +272,18 @@ def upsert_service_extraction_configs(self, service_extraction_config):
271272
return self.put(path, service_extraction_config)
272273

273274
def snapshot(self, id, timestamp=None):
274-
if timestamp is None:
275-
timestamp = self.ts_now()
275+
params = {}
276+
if timestamp is not None:
277+
params['time'] = timestamp
276278

277-
params = {'time': timestamp}
278279
path = "/api/snapshots/%s" % id
279280
return self.get(path, query_args=params)
280281

281282
def snapshots(self, query, timestamp=None, size=5):
282-
if timestamp is None:
283-
timestamp = self.ts_now()
283+
params = {'q': query, 'size': size}
284+
if timestamp is not None:
285+
params['time'] = timestamp
284286

285-
params = {'time': timestamp, 'q': query, 'size': size}
286287
path = "/api/snapshots"
287288
return self.get(path, query_args=params)
288289

0 commit comments

Comments
 (0)