Added extracting and injecting context
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
39d2f0300b
commit
b094ab43fa
@ -3,9 +3,10 @@ import time
|
||||
|
||||
import jaeger_client
|
||||
import opentracing
|
||||
from opentracing.ext import tags
|
||||
from opentracing.propagation import Format
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import pika
|
||||
import json
|
||||
@ -19,7 +20,6 @@ from magic_doer import MagicDoer
|
||||
|
||||
|
||||
def message_callback(channel, method, properties, body):
|
||||
with opentracing.tracer.start_active_span('main.handleMessage', finish_on_close=True) as scope:
|
||||
try:
|
||||
msg = json.loads(body.decode('utf-8'))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError) as e:
|
||||
@ -27,7 +27,14 @@ def message_callback(channel, method, properties, body):
|
||||
channel.basic_ack(delivery_tag=method.delivery_tag) # We don't want this to be requeue
|
||||
return
|
||||
|
||||
scope.span.log_kv({'event': 'messageParsed', 'sampleTag': msg['tag']})
|
||||
logging.debug(f"Handling message: {msg}")
|
||||
|
||||
span_ctx = opentracing.tracer.extract(Format.TEXT_MAP, msg)
|
||||
span_tags = {tags.SPAN_KIND: tags.SPAN_KIND_CONSUMER}
|
||||
|
||||
with opentracing.tracer.start_active_span(
|
||||
'main.handleMessage', finish_on_close=True, child_of=span_ctx, tags=span_tags
|
||||
) as scope:
|
||||
|
||||
with opentracing.tracer.start_active_span('magicDoer.runEverything'):
|
||||
try:
|
||||
@ -39,6 +46,8 @@ def message_callback(channel, method, properties, body):
|
||||
return
|
||||
|
||||
if results:
|
||||
opentracing.tracer.inject(scope.span.context, Format.TEXT_MAP, results)
|
||||
logging.debug(f"Publishing message: {results}")
|
||||
channel.basic_publish(
|
||||
exchange=Config.PIKA_OUTPUT_EXCHANGE,
|
||||
routing_key='classification-result',
|
||||
|
Loading…
Reference in New Issue
Block a user