@@ -133,7 +133,7 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
133133 for span , expected in zip (span_list , expected ):
134134 self .assertEqual (span .name , expected ["name" ])
135135 self .assertEqual (span .kind , expected ["kind" ])
136- self .assertEqual ( span .attributes , expected ["attributes" ])
136+ self .assertDictEqual ( dict ( span .attributes ) , expected ["attributes" ])
137137
138138 def test_basic_asgi_call (self ):
139139 """Test that spans are emitted as expected."""
@@ -170,6 +170,24 @@ def update_expected_span_name(expected):
170170 outputs = self .get_all_output ()
171171 self .validate_outputs (outputs , modifiers = [update_expected_span_name ])
172172
173+ def test_behavior_with_scope_server_as_none (self ):
174+ """Test that middleware is ok when server is none in scope."""
175+ def update_expected_server (expected ):
176+ expected [3 ]['attributes' ].update ({
177+ 'http.server_name' : '0.0.0.0' ,
178+ 'http.host' : '0.0.0.0' ,
179+ 'host.port' : 80 ,
180+ 'http.url' : 'http://0.0.0.0/'
181+ })
182+ return expected
183+ self .scope ["server" ] = None
184+ app = otel_asgi .OpenTelemetryMiddleware (simple_asgi )
185+ self .seed_app (app )
186+ self .send_default_request ()
187+ outputs = self .get_all_output ()
188+ self .validate_outputs (outputs , modifiers = [update_expected_server ])
189+
190+
173191
174192class TestAsgiAttributes (unittest .TestCase ):
175193 def setUp (self ):
0 commit comments