Skip to content

Commit e28499a

Browse files
committed
spyne: Add support for UDC
Signed-off-by: Varsha GS <[email protected]>
1 parent 6347275 commit e28499a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/instana/instrumentation/spyne.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import spyne
55
import wrapt
66
from typing import TYPE_CHECKING, Dict, Any, Callable, Tuple, Iterable
7+
from types import SimpleNamespace
78

89
from opentelemetry.semconv.trace import SpanAttributes
910

@@ -49,10 +50,9 @@ def handle_error_with_instana(
4950
kwargs: Dict[str, Any],
5051
) -> Iterable[object]:
5152
ctx = args[0]
52-
span = ctx.udc
5353

5454
# span created inside process_request() will be handled by finalize() method
55-
if span:
55+
if ctx.udc and ctx.udc.span:
5656
return wrapped(*args, **kwargs)
5757

5858
headers = ctx.in_document
@@ -83,15 +83,15 @@ def finalize_with_instana(
8383
kwargs: Dict[str, Any],
8484
) -> Tuple[()]:
8585
ctx = args[0]
86-
span = ctx.udc
8786
response_string = ctx.transport.resp_code
8887

89-
if span and response_string:
88+
if ctx.udc and ctx.udc.span and response_string:
89+
span = ctx.udc.span
9090
set_response_status_code(span, response_string)
9191
if span.is_recording():
9292
span.end()
9393

94-
ctx.udc = None
94+
ctx.udc.span = None
9595
return wrapped(*args, **kwargs)
9696

9797
@wrapt.patch_function_wrapper("spyne.application", "Application.process_request")
@@ -121,7 +121,11 @@ def process_request_with_instana(
121121
tracer.inject(span.context, Format.HTTP_HEADERS, response_headers)
122122

123123
## 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
125129
return response
126130

127131
logger.debug("Instrumenting Spyne")

tests/apps/spyne_app/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def exception(ctx):
5555
raise Exception('fake error')
5656

5757

58-
application = Application([HelloWorldService], 'spyne.examples.hello.http',
58+
application = Application([HelloWorldService], 'instana.spyne.service.helloworld',
5959
in_protocol=HttpRpc(validator='soft'),
6060
out_protocol=JsonDocument(ignore_wrappers=True),
6161
)

0 commit comments

Comments
 (0)