1212import pytest
1313import urllib3
1414import requests
15+ from urllib3 import HTTPConnectionPool
1516
1617import lumigo_tracer
1718from lumigo_tracer import lumigo_utils
@@ -43,6 +44,7 @@ def lambda_test_function(event, context):
4344 assert http_spans [0 ]["started" ] > SpansContainer .get_span ().function_span ["started" ]
4445 assert "ended" in http_spans [0 ]
4546 assert "content-length" in http_spans [0 ]["info" ]["httpInfo" ]["request" ]["headers" ]
47+ assert http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
4648
4749
4850def test_lambda_wrapper_query_with_http_params (context ):
@@ -55,6 +57,7 @@ def lambda_test_function(event, context):
5557
5658 assert http_spans
5759 assert http_spans [0 ]["info" ]["httpInfo" ]["request" ]["uri" ] == "www.google.com/?q=123"
60+ assert http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
5861
5962
6063def test_uri_requests (context ):
@@ -69,6 +72,7 @@ def lambda_test_function(event, context):
6972
7073 assert http_spans
7174 assert http_spans [0 ]["info" ]["httpInfo" ]["request" ]["uri" ] == "www.google.com/?q=123"
75+ assert http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
7276
7377
7478def test_lambda_wrapper_get_response (context ):
@@ -83,6 +87,7 @@ def lambda_test_function(event, context):
8387
8488 assert http_spans
8589 assert http_spans [0 ]["info" ]["httpInfo" ]["response" ]["statusCode" ] == 200
90+ assert http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
8691
8792
8893def test_lambda_wrapper_http_splitted_send (context ):
@@ -102,6 +107,7 @@ def lambda_test_function(event, context):
102107 assert http_spans
103108 assert http_spans [0 ]["info" ]["httpInfo" ]["request" ]["body" ] == '"123456"'
104109 assert "content-length" in http_spans [0 ]["info" ]["httpInfo" ]["request" ]["headers" ]
110+ assert http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
105111
106112
107113def test_lambda_wrapper_no_headers (context ):
@@ -152,6 +158,7 @@ def lambda_test_function(event, context):
152158 assert len (http_events ) == 1
153159 span = SpansContainer .get_span ().spans [0 ]
154160 assert span ["info" ]["httpInfo" ]["request" ]["body" ] == '"body"'
161+ assert span ["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
155162
156163
157164def test_bad_domains_scrubber (monkeypatch , context ):
@@ -176,6 +183,7 @@ def lambda_test_function(event, context):
176183 assert http_events [0 ].get ("info" , {}).get ("httpInfo" , {}).get ("host" ) == "www.google.com"
177184 assert "headers" not in http_events [0 ]["info" ]["httpInfo" ]["request" ]
178185 assert http_events [0 ]["info" ]["httpInfo" ]["request" ]["body" ] == "The data is not available"
186+ assert http_events [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
179187
180188
181189def test_domains_scrubber_override_allows_default_domains (monkeypatch , context ):
@@ -193,6 +201,7 @@ def lambda_test_function(event, context):
193201 assert len (http_events ) == 1
194202 assert http_events [0 ].get ("info" , {}).get ("httpInfo" , {}).get ("host" ) == ssm_url
195203 assert http_events [0 ]["info" ]["httpInfo" ]["request" ]["headers" ]
204+ assert http_events [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
196205
197206
198207def test_wrapping_json_request (context ):
@@ -241,6 +250,7 @@ def lambda_test_function(event, context):
241250 assert event ["info" ]["httpInfo" ]["response" ]["body" ]
242251 assert event ["info" ]["httpInfo" ]["response" ]["statusCode" ] == 200
243252 assert event ["info" ]["httpInfo" ]["host" ] == "www.google.com"
253+ assert event ["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
244254
245255
246256def test_wrapping_requests_times (monkeypatch , context ):
@@ -292,6 +302,7 @@ def lambda_test_function(event, context):
292302 assert span ["info" ]["httpInfo" ]["request" ]["method" ] == "POST"
293303 assert span ["info" ]["httpInfo" ]["request" ]["body" ] == '"123"'
294304 assert span ["info" ]["httpInfo" ]["request" ]["headers" ]
305+ assert span ["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
295306
296307
297308def test_requests_failure_with_kwargs (monkeypatch , context ):
@@ -342,6 +353,8 @@ def lambda_test_function(event, context):
342353 spans = SpansContainer .get_span ().spans
343354 assert spans [0 ]["info" ]["httpInfo" ]["request" ]["headers" ] == json .dumps ({"a" : "b" })
344355 assert spans [1 ]["info" ]["httpInfo" ]["request" ]["headers" ] == json .dumps ({"c" : "d" })
356+ assert spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
357+ assert spans [1 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" ) is not None
345358
346359
347360def api_gw_event () -> Dict :
@@ -558,3 +571,18 @@ def lambda_test_function(event, context):
558571def test_is_lumigo_edge (host , is_lumigo , monkeypatch ):
559572 monkeypatch .setattr (Configuration , "host" , "lumigo.io" )
560573 assert is_lumigo_edge (host ) == is_lumigo
574+
575+
576+ def test_same_connection_id_for_same_connection (context ):
577+ @lumigo_tracer .lumigo_tracer (token = TOKEN )
578+ def lambda_test_function (event , context ):
579+ pool = HTTPConnectionPool ("www.google.com" , maxsize = 1 )
580+ pool .request ("GET" , "/?q=123" )
581+ pool .request ("GET" , "/?q=1234" )
582+
583+ lambda_test_function ({}, context )
584+ http_spans = SpansContainer .get_span ().spans
585+
586+ instance_id_1 = http_spans [0 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" )
587+ instance_id_2 = http_spans [1 ]["info" ]["httpInfo" ]["request" ].get ("instance_id" )
588+ assert instance_id_1 == instance_id_2
0 commit comments