@@ -25,7 +25,7 @@ def __init__(self, service_name: str):
2525 self ._initiate_tracers (service_name )
2626
2727 def _initiate_tracers (self , service_name ):
28- """Initiates everything needed for tracing"""
28+ """Initiates everything needed for tracing. """
2929 # Label this resource as its service:
3030 resource = Resource (attributes = {
3131 SERVICE_NAME : service_name
@@ -41,7 +41,7 @@ def _initiate_tracers(self, service_name):
4141 self .tracer = trace .get_tracer (__name__ )
4242
4343 def _extract_trace_context (self , message ):
44- """Retrieves Context object from message"""
44+ """Retrieves Context object from message. """
4545 carrier = message .get ('trace_context' )
4646 if carrier :
4747 # Deserialise serialised context into a Context object:
@@ -51,7 +51,10 @@ def _extract_trace_context(self, message):
5151 return {}
5252
5353 def _inject_trace_context (self , message ):
54- """Inserts serialized trace context into message"""
54+ """Inserts serialized trace context into message."""
55+ if type (message ) == str :
56+ print ("Warning: string message received" )
57+ return
5558 carrier = {}
5659 # If called outside of a span context, just leave carrier empty
5760 # (very safe!)
@@ -60,9 +63,9 @@ def _inject_trace_context(self, message):
6063
6164 def subscribe (self , call_next : Callable , channel , callback , ** kwargs ) -> int :
6265 """The callback includes 'everything' that happens in a service that
63- we care about, so we wrap it in a span context.
64- To link the current span context with others from the same request
65- we inject/extract the serialized trace context in the recipe message"""
66+ we care about, so we wrap it in a span context.
67+ To link the current span context with others from the same request
68+ we inject/extract the serialized trace context in the recipe message. """
6669 @functools .wraps (callback )
6770 def wrapped_callback (header , message ):
6871 ctx = self ._extract_trace_context (message )
@@ -74,7 +77,7 @@ def wrapped_callback(header, message):
7477 return call_next (channel , wrapped_callback , ** kwargs )
7578
7679 def send (self , call_next : Callable , destination , message , ** kwargs ):
77- # Because send is usually called within a callback, it is inside a span
78- # context, so we can inject its trace context into the message:
80+ """ Because send is usually called within a callback, it is inside a span
81+ context, so we can inject its trace context into the message."""
7982 self ._inject_trace_context (message )
8083 call_next (destination , message , ** kwargs )
0 commit comments