5050
5151
5252@pytest .fixture ()
53- def grpc_server (validating_httpserver ):
53+ def grpc_server (validating_httpserver , request ):
54+ config = getattr (request , "param" , {})
55+ env = {f"ELASTIC_APM_{ k .upper ()} " : str (v ) for k , v in config .items ()}
56+ env .setdefault ("ELASTIC_APM_SERVER_URL" , validating_httpserver .url )
5457 free_port = get_free_port ()
5558 server_proc = subprocess .Popen (
5659 [os .path .join (sys .prefix , "bin" , "python" ), "-m" , "tests.contrib.grpc.grpc_app.server" , str (free_port )],
5760 stdout = sys .stdout ,
5861 stderr = sys .stdout ,
59- env = { "ELASTIC_APM_SERVER_URL" : validating_httpserver . url } ,
62+ env = env ,
6063 )
6164 wait_for_open_port (free_port )
6265 yield f"localhost:{ free_port } "
@@ -178,7 +181,7 @@ def test_grpc_client_server_exception(instrument, sending_elasticapm_client, grp
178181 assert error ["transaction_id" ] == server_transactions [0 ]["id" ]
179182
180183
181- def test_grpc_client_unsampled_transaction (instrument , sending_elasticapm_client , grpc_client_and_server_url ):
184+ def test_grpc_client_unsampled_span (instrument , sending_elasticapm_client , grpc_client_and_server_url ):
182185 grpc_client , grpc_server_url = grpc_client_and_server_url
183186 grpc_server_host , grpc_server_port = grpc_server_url .split (":" )
184187 transaction = sending_elasticapm_client .begin_transaction ("request" )
@@ -196,6 +199,26 @@ def test_grpc_client_unsampled_transaction(instrument, sending_elasticapm_client
196199 assert transaction_data ["span_count" ]["started" ] == 0
197200
198201
202+ @pytest .mark .parametrize (
203+ "grpc_server" ,
204+ [
205+ {
206+ "recording" : "False" ,
207+ }
208+ ],
209+ indirect = True ,
210+ )
211+ def test_grpc_client_unsampled_transaction (instrument , sending_elasticapm_client , grpc_client_and_server_url ):
212+ grpc_client , grpc_server_url = grpc_client_and_server_url
213+ grpc_client .GetServerResponse (Message (message = "foo" ))
214+ payloads = sending_elasticapm_client .httpserver .payloads
215+ for i in range (100 ):
216+ if len (sending_elasticapm_client .httpserver .payloads ) > 1 :
217+ break
218+ time .sleep (0.01 )
219+ assert len (payloads ) == 1 # only the server_version request
220+
221+
199222def extract_events_from_payload (service_name , payloads ):
200223 payloads = [
201224 payload for payload in payloads if payload and payload [0 ]["metadata" ]["service" ]["name" ] == service_name
0 commit comments