Merge pull request #14 from Microsoft/develop

Fixed issue #12
This commit is contained in:
Bogdan Berce 2015-02-18 20:41:11 -08:00
Родитель c5a85bd8a2 88da9b5e76
Коммит 7000e7abe0
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -200,7 +200,18 @@ class TelemetryClient(object):
data.id = str(uuid.uuid4())
data.name = name
data.start_time = start_time or datetime.datetime.utcnow().isoformat() + 'Z'
data.duration = duration or 0
local_duration = duration or 0
duration_parts = []
for multiplier in [1000, 60, 60, 24]:
duration_parts.append(local_duration % multiplier)
local_duration //= multiplier
duration_parts.reverse()
data.duration = '%02d:%02d:%02d.%03d' % tuple(duration_parts)
if local_duration:
data.duration = '%d.%s' % (local_duration, data.duration)
data.response_code = response_code or '200'
data.success = success
data.http_method = http_method or 'GET'

Просмотреть файл

@ -132,7 +132,7 @@ class TestTelemetryClient(unittest.TestCase):
client.context.device = None
client.track_request('test', 'http://tempuri.org', True, 'START_TIME', 13, '42', 'OPTIONS', { 'foo': 'bar' }, { 'x': 42 })
client.flush()
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Request", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "RequestData", "baseData": {"ver": 2, "id": "ID_PLACEHOLDER", "name": "test", "startTime": "START_TIME", "duration": 13, "responseCode": "42", "success": true, "httpMethod": "OPTIONS", "url": "http://tempuri.org", "properties": {"foo": "bar"}, "measurements": {"x": 42}}}}'
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Request", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "RequestData", "baseData": {"ver": 2, "id": "ID_PLACEHOLDER", "name": "test", "startTime": "START_TIME", "duration": "00:00:00.013", "responseCode": "42", "success": true, "httpMethod": "OPTIONS", "url": "http://tempuri.org", "properties": {"foo": "bar"}, "measurements": {"x": 42}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
sender.data.data.base_data.id = 'ID_PLACEHOLDER'