Skip to content

Commit 1ff200b

Browse files
committed
rename Client.instrumentation_store to Client.transaction_store (#253)
instrumentation_store was always a bit of a misnomer closes #253 Signed-off-by: Benjamin Wohlwend <[email protected]>
1 parent b5848aa commit 1ff200b

File tree

17 files changed

+106
-106
lines changed

17 files changed

+106
-106
lines changed

elasticapm/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, config=None, **defaults):
106106
self.error_logger = logging.getLogger('elasticapm.errors')
107107
self.state = ClientState()
108108

109-
self.instrumentation_store = None
109+
self.transaction_store = None
110110
self.processors = []
111111
self.filter_exception_types_dict = {}
112112
self._send_timer = None
@@ -148,7 +148,7 @@ def frames_collector_func():
148148
), local_var)
149149
)
150150

151-
self.instrumentation_store = TransactionsStore(
151+
self.transaction_store = TransactionsStore(
152152
frames_collector_func=frames_collector_func,
153153
collect_frequency=self.config.flush_interval,
154154
sample_rate=self.config.transaction_sample_rate,
@@ -247,11 +247,11 @@ def decode(self, data):
247247
def begin_transaction(self, transaction_type):
248248
"""Register the start of a transaction on the client
249249
"""
250-
return self.instrumentation_store.begin_transaction(transaction_type)
250+
return self.transaction_store.begin_transaction(transaction_type)
251251

252252
def end_transaction(self, name=None, result=''):
253-
transaction = self.instrumentation_store.end_transaction(result, name)
254-
if self.instrumentation_store.should_collect():
253+
transaction = self.transaction_store.end_transaction(result, name)
254+
if self.transaction_store.should_collect():
255255
self._collect_transactions()
256256
if not self._send_timer:
257257
# send first batch of data after config._wait_to_first_send
@@ -294,8 +294,8 @@ def handle_transport_fail(self, exception=None, **kwargs):
294294
def _collect_transactions(self):
295295
self._stop_send_timer()
296296
transactions = []
297-
if self.instrumentation_store:
298-
for transaction in self.instrumentation_store.get_all():
297+
if self.transaction_store:
298+
for transaction in self.transaction_store.get_all():
299299
for processor in self.processors:
300300
transaction = processor(self, transaction)
301301
transactions.append(transaction)

tests/client/client_tests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_metrics_collection(should_collect, sending_elasticapm_client):
397397
sending_elasticapm_client.begin_transaction("transaction.test")
398398
sending_elasticapm_client.end_transaction('test-transaction', 200)
399399

400-
assert len(sending_elasticapm_client.instrumentation_store) == 7
400+
assert len(sending_elasticapm_client.transaction_store) == 7
401401
assert len(sending_elasticapm_client.httpserver.requests) == 0
402402
should_collect.return_value = True
403403

@@ -449,7 +449,7 @@ def test_ignore_patterns(should_collect, elasticapm_client):
449449
elasticapm_client.begin_transaction("web")
450450
elasticapm_client.end_transaction('GET views.users', 200)
451451

452-
transactions = elasticapm_client.instrumentation_store.get_all()
452+
transactions = elasticapm_client.transaction_store.get_all()
453453

454454
assert len(transactions) == 1
455455
assert transactions[0]['name'] == 'GET views.users'
@@ -583,7 +583,7 @@ def test_collect_local_variables_transactions(should_collect, elasticapm_client)
583583
a_long_local_list = list(range(100))
584584
pass
585585
elasticapm_client.end_transaction('test', 'ok')
586-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
586+
transaction = elasticapm_client.transaction_store.get_all()[0]
587587
frame = transaction['spans'][0]['stacktrace'][0]
588588
if mode in ('transactions', 'all'):
589589
assert 'vars' in frame, mode
@@ -609,7 +609,7 @@ def test_collect_source_transactions(should_collect, elasticapm_client):
609609
with elasticapm.capture_span('foo'):
610610
pass
611611
elasticapm_client.end_transaction('test', 'ok')
612-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
612+
transaction = elasticapm_client.transaction_store.get_all()[0]
613613
in_app_frame = transaction['spans'][0]['stacktrace'][0]
614614
library_frame = transaction['spans'][0]['stacktrace'][1]
615615
assert not in_app_frame['library_frame']
@@ -659,7 +659,7 @@ def test_transaction_sampling(should_collect, elasticapm_client, not_so_random):
659659
pass
660660
elasticapm_client.end_transaction('test')
661661

662-
transactions = elasticapm_client.instrumentation_store.get_all()
662+
transactions = elasticapm_client.transaction_store.get_all()
663663

664664
# seed is fixed by not_so_random fixture
665665
assert len([t for t in transactions if t['sampled']]) == 5
@@ -681,7 +681,7 @@ def test_transaction_max_spans(should_collect, elasticapm_client):
681681
pass
682682
transaction_obj = elasticapm_client.end_transaction('test')
683683

684-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
684+
transaction = elasticapm_client.transaction_store.get_all()[0]
685685

686686
assert transaction_obj.max_spans == 5
687687
assert transaction_obj.dropped_spans == 10
@@ -702,7 +702,7 @@ def test_transaction_span_frames_min_duration(should_collect, elasticapm_client)
702702
time.sleep(0.040)
703703
elasticapm_client.end_transaction('test')
704704

705-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
705+
transaction = elasticapm_client.transaction_store.get_all()[0]
706706
spans = transaction['spans']
707707

708708
assert len(spans) == 2
@@ -724,7 +724,7 @@ def test_transaction_span_frames_min_duration_no_limit(should_collect, elasticap
724724
time.sleep(0.040)
725725
elasticapm_client.end_transaction('test')
726726

727-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
727+
transaction = elasticapm_client.transaction_store.get_all()[0]
728728
spans = transaction['spans']
729729

730730
assert len(spans) == 2
@@ -756,7 +756,7 @@ def test_transaction_max_span_nested(should_collect, elasticapm_client):
756756
pass
757757
transaction_obj = elasticapm_client.end_transaction('test')
758758

759-
transaction = elasticapm_client.instrumentation_store.get_all()[0]
759+
transaction = elasticapm_client.transaction_store.get_all()[0]
760760

761761
assert transaction_obj.dropped_spans == 6
762762
assert len(transaction['spans']) == 3

tests/contrib/django/django_tests.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,13 @@ def test_request_capture(django_elasticapm_client):
623623

624624
def test_transaction_request_response_data(django_elasticapm_client, client):
625625
client.cookies = SimpleCookie({'foo': 'bar'})
626-
django_elasticapm_client.instrumentation_store.get_all()
626+
django_elasticapm_client.transaction_store.get_all()
627627
with override_settings(**middleware_setting(
628628
django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware']
629629
)):
630630
client.get(reverse('elasticapm-no-error'))
631-
assert len(django_elasticapm_client.instrumentation_store) == 1
632-
transactions = django_elasticapm_client.instrumentation_store.get_all()
631+
assert len(django_elasticapm_client.transaction_store) == 1
632+
transactions = django_elasticapm_client.transaction_store.get_all()
633633
assert len(transactions) == 1
634634
transaction = transactions[0]
635635
assert transaction['result'] == 'HTTP 2xx'
@@ -652,15 +652,15 @@ def test_transaction_request_response_data(django_elasticapm_client, client):
652652

653653

654654
def test_transaction_metrics(django_elasticapm_client, client):
655-
django_elasticapm_client.instrumentation_store.get_all() # clear the store
655+
django_elasticapm_client.transaction_store.get_all() # clear the store
656656
with override_settings(**middleware_setting(
657657
django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware']
658658
)):
659-
assert len(django_elasticapm_client.instrumentation_store) == 0
659+
assert len(django_elasticapm_client.transaction_store) == 0
660660
client.get(reverse('elasticapm-no-error'))
661-
assert len(django_elasticapm_client.instrumentation_store) == 1
661+
assert len(django_elasticapm_client.transaction_store) == 1
662662

663-
transactions = django_elasticapm_client.instrumentation_store.get_all()
663+
transactions = django_elasticapm_client.transaction_store.get_all()
664664

665665
assert len(transactions) == 1
666666
transaction = transactions[0]
@@ -673,9 +673,9 @@ def test_transaction_metrics_debug(django_elasticapm_client, client):
673673
with override_settings(DEBUG=True, **middleware_setting(
674674
django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware']
675675
)):
676-
assert len(django_elasticapm_client.instrumentation_store) == 0
676+
assert len(django_elasticapm_client.transaction_store) == 0
677677
client.get(reverse('elasticapm-no-error'))
678-
assert len(django_elasticapm_client.instrumentation_store) == 0
678+
assert len(django_elasticapm_client.transaction_store) == 0
679679

680680

681681
@pytest.mark.parametrize('django_elasticapm_client', [
@@ -687,13 +687,13 @@ def test_transaction_metrics_debug_and_client_debug(django_elasticapm_client, cl
687687
with override_settings(DEBUG=True, **middleware_setting(
688688
django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware']
689689
)):
690-
assert len(django_elasticapm_client.instrumentation_store) == 0
690+
assert len(django_elasticapm_client.transaction_store) == 0
691691
client.get(reverse('elasticapm-no-error'))
692-
assert len(django_elasticapm_client.instrumentation_store) == 1
692+
assert len(django_elasticapm_client.transaction_store) == 1
693693

694694

695695
def test_request_metrics_301_append_slash(django_elasticapm_client, client):
696-
django_elasticapm_client.instrumentation_store.get_all() # clear the store
696+
django_elasticapm_client.transaction_store.get_all() # clear the store
697697

698698
# enable middleware wrapping
699699
django_elasticapm_client.config.instrument_django_middleware = True
@@ -709,7 +709,7 @@ def test_request_metrics_301_append_slash(django_elasticapm_client, client):
709709
])
710710
):
711711
client.get(reverse('elasticapm-no-error-slash')[:-1])
712-
transactions = django_elasticapm_client.instrumentation_store.get_all()
712+
transactions = django_elasticapm_client.transaction_store.get_all()
713713
assert transactions[0]['name'] in (
714714
# django <= 1.8
715715
'GET django.middleware.common.CommonMiddleware.process_request',
@@ -720,7 +720,7 @@ def test_request_metrics_301_append_slash(django_elasticapm_client, client):
720720

721721

722722
def test_request_metrics_301_prepend_www(django_elasticapm_client, client):
723-
django_elasticapm_client.instrumentation_store.get_all() # clear the store
723+
django_elasticapm_client.transaction_store.get_all() # clear the store
724724

725725
# enable middleware wrapping
726726
django_elasticapm_client.config.instrument_django_middleware = True
@@ -736,14 +736,14 @@ def test_request_metrics_301_prepend_www(django_elasticapm_client, client):
736736
])
737737
):
738738
client.get(reverse('elasticapm-no-error'))
739-
transactions = django_elasticapm_client.instrumentation_store.get_all()
739+
transactions = django_elasticapm_client.transaction_store.get_all()
740740
assert transactions[0]['name'] == 'GET django.middleware.common.CommonMiddleware.process_request'
741741
assert transactions[0]['result'] == 'HTTP 3xx'
742742

743743

744744
@pytest.mark.django_db
745745
def test_request_metrics_contrib_redirect(django_elasticapm_client, client):
746-
django_elasticapm_client.instrumentation_store.get_all() # clear the store
746+
django_elasticapm_client.transaction_store.get_all() # clear the store
747747

748748
# enable middleware wrapping
749749
django_elasticapm_client.config.instrument_django_middleware = True
@@ -761,18 +761,18 @@ def test_request_metrics_contrib_redirect(django_elasticapm_client, client):
761761
):
762762
response = client.get('/redirect/me/')
763763

764-
transactions = django_elasticapm_client.instrumentation_store.get_all()
764+
transactions = django_elasticapm_client.transaction_store.get_all()
765765
assert transactions[0]['name'] == 'GET django.contrib.redirects.middleware.RedirectFallbackMiddleware.process_response'
766766
assert transactions[0]['result'] == 'HTTP 3xx'
767767

768768

769769
def test_request_metrics_404_resolve_error(django_elasticapm_client, client):
770-
django_elasticapm_client.instrumentation_store.get_all() # clear the store
770+
django_elasticapm_client.transaction_store.get_all() # clear the store
771771
with override_settings(
772772
**middleware_setting(django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware'])
773773
):
774774
client.get('/i-dont-exist/')
775-
transactions = django_elasticapm_client.instrumentation_store.get_all()
775+
transactions = django_elasticapm_client.transaction_store.get_all()
776776
assert transactions[0]['name'] == ''
777777

778778

@@ -784,7 +784,7 @@ def test_request_metrics_streaming(django_elasticapm_client, client):
784784
resp = client.get(reverse('elasticapm-streaming-view'))
785785
assert list(resp.streaming_content) == [b'0', b'1', b'2', b'3', b'4']
786786
resp.close()
787-
transaction = django_elasticapm_client.instrumentation_store.get_all()[0]
787+
transaction = django_elasticapm_client.transaction_store.get_all()[0]
788788
assert transaction['result'] == 'HTTP 2xx'
789789
assert transaction['duration'] >= 50
790790
assert len(transaction['spans']) == 5
@@ -795,7 +795,7 @@ def test_request_metrics_name_override(django_elasticapm_client, client):
795795
**middleware_setting(django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware'])
796796
):
797797
client.get(reverse('elasticapm-name-override'))
798-
transaction = django_elasticapm_client.instrumentation_store.get_all()[0]
798+
transaction = django_elasticapm_client.transaction_store.get_all()[0]
799799
assert transaction['name'] == 'foo'
800800
assert transaction['result'] == 'okydoky'
801801

@@ -936,7 +936,7 @@ def test_stacktraces_have_templates(client, django_elasticapm_client):
936936
resp = client.get(reverse("render-heavy-template"))
937937
assert resp.status_code == 200
938938

939-
transactions = django_elasticapm_client.instrumentation_store.get_all()
939+
transactions = django_elasticapm_client.transaction_store.get_all()
940940
assert len(transactions) == 1
941941
transaction = transactions[0]
942942
assert transaction['result'] == 'HTTP 2xx'
@@ -968,7 +968,7 @@ def test_stacktrace_filtered_for_elasticapm(client, django_elasticapm_client):
968968
resp = client.get(reverse("render-heavy-template"))
969969
assert resp.status_code == 200
970970

971-
transactions = django_elasticapm_client.instrumentation_store.get_all()
971+
transactions = django_elasticapm_client.transaction_store.get_all()
972972
assert transactions[0]['result'] == 'HTTP 2xx'
973973
spans = transactions[0]['spans']
974974

@@ -994,7 +994,7 @@ def test_perf_template_render(benchmark, client, django_elasticapm_client):
994994
for resp in responses:
995995
assert resp.status_code == 200
996996

997-
transactions = django_elasticapm_client.instrumentation_store.get_all()
997+
transactions = django_elasticapm_client.transaction_store.get_all()
998998

999999
# If the test falls right at the change from one minute to another
10001000
# this will have two items.
@@ -1016,15 +1016,15 @@ def test_perf_template_render_no_middleware(benchmark, client, django_elasticapm
10161016
for resp in responses:
10171017
assert resp.status_code == 200
10181018

1019-
transactions = django_elasticapm_client.instrumentation_store.get_all()
1019+
transactions = django_elasticapm_client.transaction_store.get_all()
10201020
assert len(transactions) == 0
10211021

10221022

10231023
@pytest.mark.parametrize('django_elasticapm_client', [{'_wait_to_first_send': 100}], indirect=True)
10241024
@pytest.mark.django_db(transaction=True)
10251025
def test_perf_database_render(benchmark, client, django_elasticapm_client):
10261026
responses = []
1027-
django_elasticapm_client.instrumentation_store.get_all()
1027+
django_elasticapm_client.transaction_store.get_all()
10281028

10291029
with mock.patch("elasticapm.traces.TransactionsStore.should_collect") as should_collect:
10301030
should_collect.return_value = False
@@ -1037,7 +1037,7 @@ def test_perf_database_render(benchmark, client, django_elasticapm_client):
10371037
for resp in responses:
10381038
assert resp.status_code == 200
10391039

1040-
transactions = django_elasticapm_client.instrumentation_store.get_all()
1040+
transactions = django_elasticapm_client.transaction_store.get_all()
10411041

10421042
assert len(transactions) == len(responses)
10431043
for transaction in transactions:
@@ -1047,7 +1047,7 @@ def test_perf_database_render(benchmark, client, django_elasticapm_client):
10471047
@pytest.mark.django_db
10481048
@pytest.mark.parametrize('django_elasticapm_client', [{'_wait_to_first_send': 100}], indirect=True)
10491049
def test_perf_database_render_no_instrumentation(benchmark, django_elasticapm_client):
1050-
django_elasticapm_client.instrumentation_store.get_all()
1050+
django_elasticapm_client.transaction_store.get_all()
10511051
responses = []
10521052
with mock.patch("elasticapm.traces.TransactionsStore.should_collect") as should_collect:
10531053
should_collect.return_value = False
@@ -1060,7 +1060,7 @@ def test_perf_database_render_no_instrumentation(benchmark, django_elasticapm_cl
10601060
for resp in responses:
10611061
assert resp.status_code == 200
10621062

1063-
transactions = django_elasticapm_client.instrumentation_store.get_all()
1063+
transactions = django_elasticapm_client.transaction_store.get_all()
10641064
assert len(transactions) == 0
10651065

10661066

@@ -1070,7 +1070,7 @@ def test_perf_database_render_no_instrumentation(benchmark, django_elasticapm_cl
10701070
'flush_interval': 100
10711071
}], indirect=True)
10721072
def test_perf_transaction_with_collection(benchmark, django_elasticapm_client):
1073-
django_elasticapm_client.instrumentation_store.get_all()
1073+
django_elasticapm_client.transaction_store.get_all()
10741074
with mock.patch("elasticapm.traces.TransactionsStore.should_collect") as should_collect:
10751075
should_collect.return_value = False
10761076
django_elasticapm_client.events = []
@@ -1102,7 +1102,7 @@ def result():
11021102
@pytest.mark.django_db
11031103
@pytest.mark.parametrize('django_elasticapm_client', [{'_wait_to_first_send': 100}], indirect=True)
11041104
def test_perf_transaction_without_middleware(benchmark, django_elasticapm_client):
1105-
django_elasticapm_client.instrumentation_store.get_all()
1105+
django_elasticapm_client.transaction_store.get_all()
11061106
with mock.patch("elasticapm.traces.TransactionsStore.should_collect") as should_collect:
11071107
should_collect.return_value = False
11081108
client = _TestClient()
@@ -1281,7 +1281,7 @@ def test_tracing_middleware_uses_test_client(client, django_elasticapm_client):
12811281
'elasticapm.contrib.django.middleware.TracingMiddleware'
12821282
])):
12831283
client.get('/')
1284-
transactions = django_elasticapm_client.instrumentation_store.get_all()
1284+
transactions = django_elasticapm_client.transaction_store.get_all()
12851285
assert len(transactions) == 1
12861286
assert transactions[0]['context']['request']['url']['pathname'] == '/'
12871287

@@ -1387,5 +1387,5 @@ def test_options_request(client, django_elasticapm_client):
13871387
'elasticapm.contrib.django.middleware.TracingMiddleware'
13881388
])):
13891389
client.options('/')
1390-
transactions = django_elasticapm_client.instrumentation_store.get_all()
1390+
transactions = django_elasticapm_client.transaction_store.get_all()
13911391
assert transactions[0]['context']['request']['method'] == 'OPTIONS'

0 commit comments

Comments
 (0)