Created
February 5, 2018 12:55
-
-
Save ror6ax/69e1cf3fe5be130982f45db4dd5917ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
import time | |
from opentracing_instrumentation.request_context import get_current_span, span_in_context | |
from opentracing.ext import tags | |
from opentracing.propagation import Format | |
from opentracing_instrumentation.client_hooks import install_all_patches | |
from jaeger_client import Config | |
install_all_patches() | |
config = Config(config={'sampler':{'type': 'const','param': 1},'logging': True},service_name="jaeger_opentracing_example2") | |
tracer = config.initialize_tracer() | |
url = 'http://localhost:4999/log2' | |
span = tracer.start_span('TestSpan') | |
span.set_tag(tags.HTTP_METHOD, 'GET') | |
span.set_tag(tags.HTTP_URL, url) | |
span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT) | |
headers = {} | |
tracer.inject(span, Format.HTTP_HEADERS, headers) | |
r = requests.get(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import opentracing | |
import logging | |
import time | |
from jaeger_client import Config | |
from flask import Flask | |
from flask_opentracing import FlaskTracer | |
from opentracing_instrumentation.client_hooks import install_all_patches | |
import requests | |
from opentracing.propagation import Format | |
from flask import Flask, request | |
install_all_patches() | |
if __name__ == '__main__': | |
app = Flask(__name__) | |
#tracer = init_tracer('formatter') import from lib.tracer ??? | |
log_level = logging.DEBUG | |
logging.getLogger('').handlers = [] | |
logging.basicConfig(format='%(asctime)s %(message)s', level=log_level) | |
config = Config(config={'sampler':{'type': 'const','param': 1},'logging': True},service_name="jaeger_opentracing_example2") | |
ls_tracer = config.initialize_tracer() | |
tracer = FlaskTracer(ls_tracer) | |
@app.route('/log2') | |
@tracer.trace() | |
def log_something2(): | |
span_ctx = ls_tracer.extract(Format.HTTP_HEADERS, request.headers) | |
span_tags = {tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER} | |
child_span = tracer.start_span("python webserver internal span of log2", child_of=span_ctx, tags=span_tags) | |
child_span.finish() | |
return "log2" | |
app.run(debug=True, port=4999) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment