File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,10 @@ def __enter__(self):
268
268
def __exit__ (self , exc_type , exc_val , exc_tb ):
269
269
transaction = get_transaction ()
270
270
if transaction and transaction .is_sampled :
271
- transaction .end_span (self .skip_frames )
271
+ try :
272
+ transaction .end_span (self .skip_frames )
273
+ except IndexError :
274
+ error_logger .info ('ended non-existing span %s of type %s' , self .name , self .type )
272
275
273
276
274
277
def tag (** tags ):
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
+ import logging
2
3
import types
3
4
4
5
import mock
@@ -110,3 +111,16 @@ def test_skip_ignored_frames(elasticapm_client):
110
111
transaction = elasticapm_client .end_transaction ('test' , 'test' )
111
112
for frame in transaction .spans [0 ].frames :
112
113
assert not frame ['module' ].startswith ('elasticapm' )
114
+
115
+
116
+ def test_end_nonexisting_span (caplog , elasticapm_client ):
117
+ with caplog .at_level (logging .INFO ):
118
+ t = elasticapm_client .begin_transaction ('test' )
119
+ # we're purposefully creating a case where we don't begin a span
120
+ # and then try to end the non-existing span
121
+ t .is_sampled = False
122
+ with elasticapm .capture_span ('test_name' , 'test_type' ):
123
+ t .is_sampled = True
124
+ elasticapm_client .end_transaction ('test' , '' )
125
+ record = caplog .records [0 ]
126
+ assert record .args == ('test_name' , 'test_type' )
You can’t perform that action at this time.
0 commit comments