Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Trying to use same span through inject/extract across scripts to update additional details using jaeger-client #144

Closed
dhineshmm opened this issue Mar 19, 2018 · 4 comments

Comments

@dhineshmm
Copy link

Having two separate scripts...
First one to create span before execute/process something and
Second one to update some more details on the same span at end

In first script, Created root span and child span. Update some portion details in child span and injected
root and child spans were flushed with currently updated details in my execution

I have tried zipkin, as well as OPEN_TEXT format to inject and extract the same to use and treat single span.

import opentracing
from lib.tracing import init_tracer
from opentracing_instrumentation.request_context import get_current_span, span_in_context
from opentracing.ext import tags
from opentracing.propagation import Format
import json
import time
from datetime import datetime

global tracer

def get_current_time():
get_current_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
return get_current_time;

def create_root_span(process_name):
global tracer
tracer = init_tracer(process_name)
tracer.one_span_per_rpc = 1
tracer.one_span_per_rpc = 1
span_name = process_name
with tracer.start_span(span_name) as root_span:
with span_in_context(root_span):
root_span.set_tag('start_time', get_current_time() );
root_span.set_tag('test', 'data' );
time.sleep(2)
root_span.set_tag('span', span_name)
root_span.info('Root span created...');
with tracer.start_span( 'rpc_span', child_of=root_span.context) as child_span:
with span_in_context(child_span):
child_span.set_tag('span', span_name)
child_span.set_tag('start-time', get_current_time());
time.sleep(2)
child_span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
text_carrier = {}
tracer.inject(child_span.context, 'zipkin-span-format', text_carrier)
update_header_as_json( text_carrier );
#child_span.finish()

def update_header_as_json( text_carrier ):
filename='./rpc_tracing.txt'
with open(filename, 'w') as f:
json.dump(text_carrier, f)
f.close();

process_name = 'master-app'
create_root_span(process_name)

yield to IOLoop to flush the spans

time.sleep(5)
#tracer.close()

In second independent script, extracted the span, trying to update some portion in the span.
When it flush, it has created as child for same span-id and has details updated only in the script

from lib.tracing import init_tracer
from opentracing.ext import tags
from opentracing_instrumentation.request_context import get_current_span, span_in_context
from opentracing.propagation import Format
import time
from datetime import datetime
import json
import collections

def get_current_time():
get_current_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
return get_current_time;

filename='./rpc_tracing.txt'
with open(filename, 'r') as f:
text_carrier = json.load(f)
f.close()

def get_reference_object(referenced_context):

Reference(ctx=spanCtxForSpanA, refType="decorates")

Reference= collections.namedtuple('Reference', ['type', 'referenced_context'])
#return Reference('decorates',referenced_context);
return Reference('',referenced_context);

tracer = init_tracer('master-app')
tracer.one_span_per_rpc = 1

extracted_context = tracer.extract(
#Format.TEXT_MAP,
'zipkin-span-format',
text_carrier
)

span_tags = {tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER}
span_name = 'rpc-span'
with tracer.start_span(span_name,tags=span_tags, references=get_reference_object(extracted_context)) as span:
with span_in_context(span):
span.set_tag('span', span_name)
time.sleep(5)
span.set_tag('end-time', get_current_time());
time.sleep(2)
tracer.close()

@black-adder
Copy link
Contributor

I'm not sure I follow, what is the problem you are trying to solve? From my understanding, you have one script that creates a root and child span and it finishes them. Then you are sending context via inject to a second script which extracts the 2 spans. I don't follow the next steps.

@dhineshmm
Copy link
Author

In the first script
I create root span and child span. In child span i update some tag and log. Inject the child span to be used by other process/script

In the second script,
I extract the span (child span, which was injected by first script), Try to update the some more tags and logs and exit smooth.

Both the span use same span-id/context

Here i expect collector/GUI will list only two spans (root and child ), Child span contain all the tags and logs updated by both the script.

But result is
-- root span
----child span, logs and span created by first script
------ child span, logs and span created by second script
## both the child span uses same trace-id and span-id

opentracing-tutorial/python /usr/bin/python master_app.py
Initializing Jaeger Tracer with UDP reporter
Using sampler ConstSampler(True)
opentracing.tracer initialized to <jaeger_client.tracer.Tracer object at 0x191bed0>[app_name=master-app]
Reporting span 3ba4b9f91c828815:e6558cf0e7174264:3ba4b9f91c828815:1 master-app.rpc_span
Reporting span 3ba4b9f91c828815:3ba4b9f91c828815:0:1 master-app.master-app
[dhineshm@devws274 solution]$

[dhineshm@devws274 solution]$ PYTHONPATH=/repo/dhineshm/python-libraries/env/lib/python2.7/site-packages/:/repo/dhineshm/sample_programs/opentracing-tutorial/python /usr/bin/python receiver.py
Initializing Jaeger Tracer with UDP reporter
Using sampler ConstSampler(True)
opentracing.tracer initialized to <jaeger_client.tracer.Tracer object at 0x2015e90>[app_name=master-app]
Reporting span 3ba4b9f91c828815:e6558cf0e7174264:3ba4b9f91c828815:1 master-app.rpc-span
[dhineshm@devws274 solution]$

@black-adder
Copy link
Contributor

Understood. At the moment, if you emit the same traceid-spanid span, they aren't combined into one span. This ticket might be of interest to you: jaegertracing/jaeger#729.

@mkiran18
Copy link

mkiran18 commented Feb 26, 2019

Hi @black-adder ,

I see lot of commentary on the upserting span entries it in ES storage in jaegertracing/jaeger#729 , is this features already released ?

thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants