Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django: Fix carrier usage on ASGI requests #767

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#766](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/766))
- `opentelemetry-instrumentation-falcon` Dropped broken support for Python 3.4.
([#774](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/774))
- `opentelemetry-instrumentation-django` Fixed carrier usage on ASGI requests.
([#767](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/767))

## [1.6.2-0.25b2](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.6.2-0.25b2) - 2021-10-19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def process_request(self, request):
carrier_getter = wsgi_getter
collect_request_attributes = wsgi_collect_request_attributes

token = attach(extract(request_meta, getter=carrier_getter))
token = attach(extract(carrier, getter=carrier_getter))

span = self._tracer.start_span(
self._get_span_name(request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@
)
from opentelemetry.sdk import resources
from opentelemetry.sdk.trace import Span
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.test.wsgitestutil import WsgiTestBase
from opentelemetry.trace import SpanKind, StatusCode
from opentelemetry.trace import (
SpanKind,
StatusCode,
format_span_id,
format_trace_id,
)
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs

# pylint: disable=import-error
Expand Down Expand Up @@ -331,6 +337,29 @@ def response_hook(span, request, response):
self.assertIsInstance(response_hook_args[2], HttpResponse)
self.assertEqual(response_hook_args[2], response)

async 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),
)
self.assertIsNotNone(span.parent)
self.assertEqual(
trace_id, format_trace_id(span.parent.trace_id),
)
self.assertEqual(
span_id, format_span_id(span.parent.span_id),
)
self.memory_exporter.clear()

def test_trace_response_headers(self):
response = Client().get("/span_name/1234/")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
from opentelemetry.sdk import resources
from opentelemetry.sdk.trace import Span
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import (
Expand Down Expand Up @@ -317,6 +318,29 @@ def response_hook(span, request, response):
self.assertIsInstance(response_hook_args[2], HttpResponse)
self.assertEqual(response_hook_args[2], response)

async 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"

await self.async_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),
)
self.assertIsNotNone(span.parent)
self.assertEqual(
trace_id, format_trace_id(span.parent.trace_id),
)
self.assertEqual(
span_id, format_span_id(span.parent.span_id),
)
self.memory_exporter.clear()

async def test_trace_response_headers(self):
response = await self.async_client.get("/span_name/1234/")

Expand Down