def test_tracer_instrument(elasticapm_client): with mock.patch("elasticapm.contrib.opentracing.tracer.instrument") as mock_instrument: elasticapm_client.config.instrument = False Tracer(client_instance=elasticapm_client) assert mock_instrument.call_count == 0 elasticapm_client.config.instrument = True Tracer(client_instance=elasticapm_client) assert mock_instrument.call_count == 1
def test_tracer_with_config(): config = { "METRICS_INTERVAL": "0s", "SERVER_URL": "https://example.com/test" } tracer = Tracer(config=config) assert tracer._agent.config.metrics_interval == 0 assert tracer._agent.config.server_url == "https://example.com/test"
def test_tracer_with_instantiated_client(elasticapm_client): tracer = Tracer(client_instance=elasticapm_client) assert tracer._agent is elasticapm_client
def tracer(elasticapm_client): yield Tracer(client_instance=elasticapm_client)
def tracer(elasticapm_client): yield Tracer(client_instance=elasticapm_client) elasticapm.uninstrument()
import os from bottle import route, run, template, view, static_file from elasticapm.contrib.opentracing import Tracer from opentracing.propagation import Format from elasticapm import Client ENVIRONMENT = os.getenv('ENVIRONMENT', 'local') DEBUG = True if os.getenv('DEBUG', 'False').lower() == 'true' else False RELOADER = True if os.getenv('RELOADER', 'False').lower() == 'true' else False TRACER = Tracer(Client({'SERVICE_NAME': os.environ.get('APM_NAME')})) @route('/hello/static/<filename:path>') @route('/static/<filename:path>') def send_static(filename): return static_file(filename, root='./static') @route('/') @view('home') def index(): with TRACER.start_active_span("index", finish_on_close=True): return dict(environment=ENVIRONMENT) @route('/hello') @route('/hello/<name>') @view('hello') def hello(name='World'): with self._tracer.start_active_span("hello", finish_on_close=True):
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', } }, 'handlers': { 'wsgi': { 'class': 'logging.StreamHandler', 'stream': 'ext://flask.logging.wsgi_errors_stream', 'formatter': 'default' } }, 'root': { 'level': 'INFO', 'handlers': ['wsgi'] } }) opentracing_tracer = Tracer(config={"SERVICE_NAME": "opbeans-flask-ot"}) app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', SQLITE_DB_PATH) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['ELASTIC_APM'] = { 'SERVICE_NAME': os.environ.get('ELASTIC_APM_SERVICE_NAME', 'opbeans-flask'), 'SERVER_URL': os.environ.get('ELASTIC_APM_SERVER_URL', 'http://localhost:8200'), 'DEBUG': True, } db = SQLAlchemy(app) apm = ElasticAPM(app, logging=True)