Hello all,
I'm a beginner with Elastic APM, currently trying to use Elastic APM to monitor a simple standalone python application using APM Server v8.1 to get an understanding for it. The application uses Flask framework and has one request that receives a number and computes its factorial.
import logging
from flask import Flask
from elasticapm.contrib.flask import ElasticAPM
from elasticapm.handlers.logging import LoggingHandler
import elasticapm
app = Flask(__name__)
server_url = 'http://localhost:8200'
service_name = 'DemoFlask'
environment = 'dev'
DEBUG = False
app.config["ELASTIC_APM"] = {
"DEBUG": DEBUG,
"LOG_FILE": "/Users/ahmed/Desktop/SPL/Elastic/Logs/flaskapm.log",
"LOG_LEVEL": "trace",
"SERVER_TIMEOUT": "20s",
"COLLECT_LOCAL_VARIABLES": "all",
"SOURCE_LINES_SPAN_APP_FRAMES": "5",
"SOURCE_LINES_SPAN_LIBRARY_FRAMES": "5",
"CAPTURE_BODY": "all",
"span_stack_trace_min_duration": "0ms",
"exit_span_min_duration": "0ms"
}
environment=environment, logging=logging.INFO)
apm = ElasticAPM(app, service_name=service_name)
elasticapm.label(platform='DemoPlatform')
@app.route('/hello/<name>')
def hello_name(name):
return 'Hello %s!' % name
@app.route('/fact/<num>')
def fact_helper(num):
num = int(num)
return 'The factorial of %d is %d!' % (num, fact(num))
def fact(n):
if n == 1 or n == 0:
return 1
else:
return n*fact(n-1)
if __name__ == '__main__':
handler = LoggingHandler(client=apm.client)
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)
app.run()
When observing the logs of APM Service, I can see that requests to '/fact/num' are being captured, however no spans are captured.
{"log.level":"debug","@timestamp":"2022-04-01T19:02:26.536+0400","log.logger":"spanmetrics","log.origin":{"file.name":"spanmetrics/aggregator.go","file.line":163},"message":"no span metrics to publish","service.name":"apm-server","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-04-01T19:02:26.536+0400","log.logger":"txmetrics","log.origin":{"file.name":"txmetrics/aggregator.go","file.line":230},"message":"publishing 1 metricsets","service.name":"apm-server","ecs.version":"1.6.0"}
Am I configuring anything incorrectly or is this due to the fact that spans with no service destinations are dropped as mentioned here.
Your help is greatly appreciated.