|
4 | 4 | import spyne
|
5 | 5 | import wrapt
|
6 | 6 | from typing import TYPE_CHECKING, Dict, Any, Callable, Tuple, Iterable
|
| 7 | + from types import SimpleNamespace |
7 | 8 |
|
8 | 9 | from opentelemetry.semconv.trace import SpanAttributes
|
9 | 10 |
|
@@ -49,10 +50,9 @@ def handle_error_with_instana(
|
49 | 50 | kwargs: Dict[str, Any],
|
50 | 51 | ) -> Iterable[object]:
|
51 | 52 | ctx = args[0]
|
52 |
| - span = ctx.udc |
53 | 53 |
|
54 | 54 | # span created inside process_request() will be handled by finalize() method
|
55 |
| - if span: |
| 55 | + if ctx.udc and ctx.udc.span: |
56 | 56 | return wrapped(*args, **kwargs)
|
57 | 57 |
|
58 | 58 | headers = ctx.in_document
|
@@ -83,15 +83,15 @@ def finalize_with_instana(
|
83 | 83 | kwargs: Dict[str, Any],
|
84 | 84 | ) -> Tuple[()]:
|
85 | 85 | ctx = args[0]
|
86 |
| - span = ctx.udc |
87 | 86 | response_string = ctx.transport.resp_code
|
88 | 87 |
|
89 |
| - if span and response_string: |
| 88 | + if ctx.udc and ctx.udc.span and response_string: |
| 89 | + span = ctx.udc.span |
90 | 90 | set_response_status_code(span, response_string)
|
91 | 91 | if span.is_recording():
|
92 | 92 | span.end()
|
93 | 93 |
|
94 |
| - ctx.udc = None |
| 94 | + ctx.udc.span = None |
95 | 95 | return wrapped(*args, **kwargs)
|
96 | 96 |
|
97 | 97 | @wrapt.patch_function_wrapper("spyne.application", "Application.process_request")
|
@@ -121,7 +121,11 @@ def process_request_with_instana(
|
121 | 121 | tracer.inject(span.context, Format.HTTP_HEADERS, response_headers)
|
122 | 122 |
|
123 | 123 | ## Store the span in the user defined context object offered by Spyne
|
124 |
| - ctx.udc = span |
| 124 | + if ctx.udc: |
| 125 | + ctx.udc.span = span |
| 126 | + else: |
| 127 | + ctx.udc = SimpleNamespace() |
| 128 | + ctx.udc.span = span |
125 | 129 | return response
|
126 | 130 |
|
127 | 131 | logger.debug("Instrumenting Spyne")
|
|
0 commit comments