pip install elastic-apm
export ELASTIC_APM_APP_NAME="example"
export ELASTIC_APM_SERVER_URL="http://apm-server.kube-system:8200"
ELASTIC_APM_SECRET_TOKEN=
import os
os.environ
import logging
from elasticapm.conf.constants import ERROR, KEYWORD_MAX_LENGTH, SPAN, TRANSACTION
import elasticapm
from elasticapm import Client
#####
client = Client()
handler = client.get_handler()
handler.setLevel(logging.DEBUG)
# https://www.elastic.co/guide/en/apm/agent/python/current/configuration.html
client = Client({'SERVICE_NAME': 'example', 'ELASTIC_APM_SERVER_URL':'http://apm-server.kube-system:8200'})#, **defaults)
client = Client(service_name="example", environment="production", server_url='http://apm-server.kube-system:8200', hostname = "host-10-1-2-70", version = "1.2.3", transport_class="elasticapm.transport.http.Transport", debug=True)
#, transport_class": "elasticapm.transport.http.AsyncTransport", "async_mode": True)
try:
x = int("five")
except ValueError:
client.capture_exception()
try:
1 / 0
except Exception:
client.capture_exception()
client.capture_message('Billing process succeeded.')
client.capture_message("foo", handled=False)
client.begin_transaction('myapp.zxcv')
client.begin_transaction('myapp.asdf')
client.begin_transaction('myapp.qwer')
client.end_transaction('myapp.qwer',"failed") # /*processor.status*/
client.end_transaction('myapp.asdf',"ok") # /*processor.status*/
client.end_transaction('myapp.zxcv',404) # /*processor.status*/
elasticapm.set_transaction_name('myapp.billing_process')
client.set_transaction_result('SUCCESS')
end_transaction('asdf')