Skip to content

Django sync middleware test broken #2336

@xrmx

Description

@xrmx

Describe your environment

broken test for Django middleware

Steps to reproduce

first you have to remove a spurious async before the test to have run it :)

diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py
index d7bb1e54..44273113 100644
--- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py
+++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py
@@ -390,7 +390,7 @@ class TestMiddleware(WsgiTestBase):
         self.assertIsInstance(response_hook_args[2], HttpResponse)
         self.assertEqual(response_hook_args[2], response)
 
-    async def test_trace_parent(self):
+    def test_trace_parent(self):
         id_generator = RandomIdGenerator()
         trace_id = format_trace_id(id_generator.generate_trace_id())
         span_id = format_span_id(id_generator.generate_span_id())

And then:

tox -e py311-test-instrumentation-django-4

What is the expected behavior?

test pass

What is the actual behavior?

test fails

________________________________________ TestMiddleware.test_trace_parent _________________________________________

self = <tests.test_middleware.TestMiddleware testMethod=test_trace_parent>

    def test_trace_parent(self):
        id_generator = RandomIdGenerator()
        trace_id = format_trace_id(id_generator.generate_trace_id())
        span_id = format_span_id(id_generator.generate_span_id())
        traceparent_value = f"00-{trace_id}-{span_id}-01"
    
        Client().get(
            "/span_name/1234/",
            traceparent=traceparent_value,
        )
        span = self.memory_exporter.get_finished_spans()[0]
    
>       self.assertEqual(
            trace_id,
            format_trace_id(span.get_span_context().trace_id),
        )
E       AssertionError: 'f46f1247628f554b587aadce9790c731' != 'ab9bda20154106be406c2314bed448f7'
E       - f46f1247628f554b587aadce9790c731
E       + ab9bda20154106be406c2314bed448f7

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py:405: AssertionError

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions