File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -319,9 +319,10 @@ def set_context(data, key="custom"):
319319 data = data ()
320320
321321 # remove invalid characters from key names
322- for k in list (data .keys ()):
323- if TAG_RE .search (k ):
324- data [TAG_RE .sub ("_" , k )] = data .pop (k )
322+ if not callable (data ): # if transaction wasn't sampled, data is still a callable here and can be ignored
323+ for k in list (data .keys ()):
324+ if TAG_RE .search (k ):
325+ data [TAG_RE .sub ("_" , k )] = data .pop (k )
325326
326327 if key in transaction .context :
327328 transaction .context [key ].update (data )
Original file line number Diff line number Diff line change @@ -233,6 +233,17 @@ def test_tags_dedot(elasticapm_client):
233233 assert transactions [0 ]["context" ]["tags" ] == {"d_o_t" : "dot" , "s_t_a_r" : "star" , "q_u_o_t_e" : "quote" }
234234
235235
236+ def test_dedot_is_not_run_when_unsampled (elasticapm_client ):
237+ for sampled in (True , False ):
238+ t = elasticapm_client .begin_transaction ("test" )
239+ t .is_sampled = sampled
240+ elasticapm .set_context (lambda : {"a.b" : "b" })
241+ elasticapm_client .end_transaction ("x" , "OK" )
242+ sampled_transaction , unsampled_transaction = transactions = elasticapm_client .events [TRANSACTION ]
243+ assert "a_b" in sampled_transaction ["context" ]["custom" ]
244+ assert "context" not in unsampled_transaction
245+
246+
236247def test_set_transaction_name (elasticapm_client ):
237248 elasticapm_client .begin_transaction ("test" )
238249 elasticapm_client .end_transaction ("test_name" , 200 )
You can’t perform that action at this time.
0 commit comments