Skip to content

Commit 94a7676

Browse files
GSVarshapvital
authored andcommitted
fix(aio-pika): implement _bind_args method to fetch values from both args and kwargs
Signed-off-by: Varsha GS <[email protected]>
1 parent 72b7791 commit 94a7676

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/instana/instrumentation/aio_pika.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,26 @@ async def publish_with_instana(
4343
) -> Optional["ConfirmationFrameType"]:
4444
if tracing_is_off():
4545
return await wrapped(*args, **kwargs)
46-
46+
4747
tracer, parent_span, _ = get_tracer_tuple()
4848
parent_context = parent_span.get_span_context() if parent_span else None
4949

50+
def _bind_args(
51+
message: Type["AbstractMessage"],
52+
routing_key: str,
53+
*args: object,
54+
**kwargs: object,
55+
) -> Tuple[object, ...]:
56+
return (message, routing_key, args, kwargs)
57+
58+
(message, routing_key, args, kwargs) = _bind_args(
59+
*args, **kwargs
60+
)
61+
5062
with tracer.start_as_current_span(
5163
"rabbitmq", span_context=parent_context
5264
) as span:
5365
connection = instance.channel._connection
54-
message = kwargs["message"] if kwargs.get("message") else args[0]
55-
routing_key = (
56-
kwargs["routing_key"] if kwargs.get("routing_key") else args[1]
57-
)
5866

5967
_extract_span_attributes(
6068
span, connection, "publish", routing_key, instance.name
@@ -66,6 +74,9 @@ async def publish_with_instana(
6674
message.properties.headers,
6775
disable_w3c_trace_context=True,
6876
)
77+
78+
args = (message, routing_key) + args
79+
6980
try:
7081
response = await wrapped(*args, **kwargs)
7182
except Exception as exc:

0 commit comments

Comments
 (0)