Skip to content

Instantly share code, notes, and snippets.

@graphaelli
Created February 27, 2018 20:45
Show Gist options
  • Save graphaelli/d9cb1c59bc1a78459650c9882382c2fb to your computer and use it in GitHub Desktop.
Save graphaelli/d9cb1c59bc1a78459650c9882382c2fb to your computer and use it in GitHub Desktop.
sample elastic apm flask app
#!/usr/bin/env python
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
from flask import Flask
# initialize using environment variables from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
# configure to use ELASTIC_APM in your application's settings from elasticapm.contrib.flask import ElasticAPM
app.config['ELASTIC_APM'] = {
# allowed app_name chars: a-z, A-Z, 0-9, -, _, and space from elasticapm.contrib.flask
'APP_NAME': 'flask-apm-client',
'DEBUG': True,
'SERVER_URL': 'http://localhost:8200',
'TRACES_SEND_FREQ': 5,
'SERVICE_NAME': 'flaskapp',
'FLUSH_INTERVAL': 1, # 2.x
'MAX_QUEUE_SIZE': 1, # 2.x
'TRANSACTIONS_IGNORE_PATTERNS': ['.*healthcheck']
}
apm = ElasticAPM(app, logging=True)
@app.route('/foo')
def foo_route():
return foo()
@elasticapm.capture_span()
def foo():
return "foo"
if __name__ == '__main__':
app.run()
@BenSchZA
Copy link

BenSchZA commented Jul 16, 2018

Is it possible to use the decorator @elasticapm.capture_span() within another class/module after ElasticAPM has been initialized? I have quickly given it a try and it doesn't seem like it, but perhaps you'd be able to tell me otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment