from celery.signals import worker_process_init

    @worker_process_init.connect(weak=False)
    def create_global_tracer(*args, **kwargs):
        tracer = create_tracer(access_token=access_token, set_global=False)
        tracer_proxy.set_tracer(tracer)


if hasattr(sys, 'argv') and sys.argv[0].split(
        os.path.sep)[-1] == 'celery' and 'worker' in sys.argv:
    create_celery_tracer()
else:
    try:
        auto_instrument(
            create_tracer(access_token=access_token, set_global=True))
    except Exception:
        print(traceback.format_exc())

# Do not prevent existing sitecustomize module import. Done by
# removing this module's package and attempting to import
# sitecustomize module.

# Removing references to this sitecustomize module
# can trigger garbage collection and cause lookup failures in other modules.
sys.modules['sfx_sitecustomize'] = sys.modules.pop('sitecustomize', None)
sys.path.remove(os.path.abspath(os.path.dirname(__file__)))

# Attempt to load any existing sitecustomize
module = get_module('sitecustomize')
if module is None:  # reset to our own if no preexisting
 def create_global_tracer(*args, **kwargs):
     tracer = create_tracer(access_token=access_token, set_global=False)
     tracer_proxy.set_tracer(tracer)
Exemple #3
0
# Copyright (C) 2019 SignalFx, Inc. All rights reserved.
from __future__ import print_function

import traceback
import os.path
import sys

from signalfx_tracing import auto_instrument, create_tracer
from signalfx_tracing.utils import get_module


access_token = os.environ.get('SIGNALFX_ACCESS_TOKEN')

try:
    auto_instrument(create_tracer(access_token=access_token, set_global=True))
except Exception:
    print(traceback.format_exc())

# Do not prevent existing sitecustomize module import. Done by
# removing this module's package and attempting to import
# sitecustomize module.

# Removing references to this sitecustomize module
# can trigger garbage collection and cause lookup failures in other modules.
sys.modules['sfx_sitecustomize'] = sys.modules.pop('sitecustomize', None)
sys.path.remove(os.path.abspath(os.path.dirname(__file__)))

# Attempt to load any existing sitecustomize
module = get_module('sitecustomize')
if module is None:  # reset to our own if no preexisting
    sys.modules['sitecustomize'] = sys.modules['sfx_sitecustomize']
import time
import requests
from signalfx_tracing import auto_instrument, create_tracer, trace
import opentracing
from opentracing.ext import tags

tracer = create_tracer()
auto_instrument(tracer)

@trace
def pythonrequests():
    try:
        print(opentracing.tracer.active_span)
        with opentracing.tracer.active_span as span:
            span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        requests.get('http://httpbin.org/get')
    except requests.exceptions.RequestException as err:
        print(err)
for x in range (1,1000):
    pythonrequests()
    time.sleep(1)
Exemple #5
0
def post_fork(server, worker):
    auto_instrument(create_tracer())
from flask import Flask, make_response, request
from signalfx_tracing import auto_instrument, create_tracer, trace
import opentracing

tracer = create_tracer(service_name='FlaskServer')
auto_instrument(tracer)

app = Flask(__name__)


@trace
def convert_response(message):
    print(opentracing.tracer.active_span)
    return 'Hello From Flask Server- You Sent: {}\n'.format(message)


@app.route('/echo', methods=['POST'])
def echo():
    message = request.data.decode('utf-8')
    return make_response(convert_response(message))


if __name__ == '__main__':
    app.run()
Exemple #7
0
 def setup_tracing(self, caplog):
     self.tracer = create_tracer()
     instrument(self.tracer)
     opentracing.tracer = self.tracer
     caplog.set_level(logging.INFO)
            jaeger_password = f.read()
    if jaeger_password:
        tracer_config["jaeger_password"] = jaeger_password

    user_path = "/opentracing/user"
    jaeger_user = None
    if os.path.exists(user_path):
        with open(user_path, 'r') as f:
            jaeger_user = f.read()
    if jaeger_user:
        tracer_config["jaeger_user"] = jaeger_user

    logging.info("tracer_config: %s" % tracer_config)
    tracer = create_tracer(
        config=tracer_config,
        service_name="dltk-dask-client",
        validate=True,
    )

    concurrent_algo_executions = int(
        os.environ.get("CONCURRENT_ALGO_EXECUTIONS"))
    logging.info("starting server on %s threads..." %
                 concurrent_algo_executions)
    serve(
        app,
        host="0.0.0.0",
        port=5002,
        channel_timeout=100000,
        threads=concurrent_algo_executions,
    )
            "param": 1,
        },
        "logging": False,
    }

    jaeger_endpoint = None
    signalfx_agent_host = os.getenv('SIGNALFX_AGENT_HOST')
    if signalfx_agent_host:
        jaeger_endpoint = 'http://' + signalfx_agent_host + ':9080/v1/trace'
        tracer_config["jaeger_endpoint"] = jaeger_endpoint
        logging.info("jaeger_endpoint: %s" % jaeger_endpoint)

    logging.info("tracer_config: %s" % tracer_config)
    tracer = create_tracer(
        config=tracer_config,
        service_name="dltk-spark-driver",
        #validate=True,
    )

    search_id = os.getenv("DLTK_SEARCH_ID", "")
    logging.info("DLTK_SEARCH_ID=%s" % search_id)

    algo_name = os.getenv("DLTK_ALGO", "DLTK")
    logging.info("DLTK_ALGO=%s" % algo_name)
    spark_context = SparkContext(appName=algo_name)
    spark_context.addPyFile(os.path.abspath(output_relay.__file__))

    fields = None
    fields_string = os.getenv("DLTK_FIELDS", "")
    logging.info("fields_string=%s" % fields_string)
    if fields_string:
import logging
import requests
from argparse import ArgumentParser
from requests.auth import HTTPBasicAuth
from signalfx_tracing import auto_instrument, create_tracer, trace
# Important: Needed to propagate traces
from signalfx_tracing.libraries import requests_config

# Create and configure logger
logging.basicConfig(
    level='DEBUG',
    format='%(asctime)s %(message)s',
)

# create an instance of the SignalFx tracer
tracer = create_tracer(service_name='BlogClient')

# Setting requests_config.propagate to 'True'  ensures
# that the relational information between spans is maintained
# and forwarded.
requests_config.propagate = True

# Configure auto-instrumentation of the tracing instance
auto_instrument(tracer)


class BlogClient:
    def __init__(self, url, username, password):
        self.url = url
        self.session = requests.Session()
        self.session.auth = HTTPBasicAuth(username, password)
Exemple #11
0
            "param": 1,
        },
        "logging": False,
    }

    jaeger_endpoint = None
    signalfx_agent_host = os.getenv('SIGNALFX_AGENT_HOST')
    if signalfx_agent_host:
        jaeger_endpoint = 'http://' + signalfx_agent_host + ':9080/v1/trace'
        tracer_config["jaeger_endpoint"] = jaeger_endpoint
        logging.info("jaeger_endpoint: %s" % jaeger_endpoint)

    logging.info("tracer_config: %s" % tracer_config)
    tracer = create_tracer(
        config=tracer_config,
        service_name="spark-inbound-relay",
        #validate=True,
    )

    hdfs_path = os.environ.get("HDFS_PATH", "")
    logging.info("hdfs_path: %s" % hdfs_path)

    hdfs_base_url = os.environ.get("HDFS_SINK_URL", "")
    logging.info("hdfs_base_url: %s" % hdfs_base_url)

    hdfs_client = hdfs.InsecureClient(hdfs_base_url)
    hdfs_client.delete(hdfs_path, recursive=True)
    hdfs_client.makedirs(hdfs_path)

    app = Flask(__name__)