This package can help you create Elastic APM instrumentations using regex
Project description
Elastic APM Agent Utils
This package can help you create Elastic APM instrumentations using regex.
Dependencies
python2.7+ || python3.6+elastic-apm 5.4.0+
Installation
pip install apm-agent-utils
Usage
Create a file named instrumentations.py
# instrumentations.py
from apm_agent_utils.instrumentation import InstrumentationBuilder
builder = InstrumentationBuilder("Test")
builder.add_instrument("logic.logic1", r"^hello.*") # finding and wrapping your funtions by regex
builder.add_instrument("logic.logic2", r".*")
Test = builder.create_instrument()
In your app.py, adding the following lines at top of the file.
import elasticapm
from apm_agent_utils.utils import add_instrumentation
add_instrumentation("instrumentations.Test")
elasticapm.instrument()
==> app.py
# app.py
import elasticapm
from apm_agent_utils.utils import add_instrumentation
from elasticapm.contrib.flask import ElasticAPM
from flask import Flask
add_instrumentation("instrumentations.Instrument")
elasticapm.instrument()
app = Flask(__name__)
app.config['ELASTIC_APM'] = {
'SERVICE_NAME': 'vuonglv_test',
'SECRET_TOKEN': '#####',
'SERVER_URL': 'http://##.##.##.##:8200/',
'DEBUG': True
}
apm = ElasticAPM(app)
main.py - your controllers
# main.py
from app import app
from logic.logic1 import hello
from logic.logic2 import foo, bar
@app.route("/")
def run():
print(hello())
print(foo())
print(bar())
return {"ok": True}
if __name__ == "__main__":
app.run(debug=True)
Project structure look like this:
Run app
python3 main.py
Get your endpoint
curl --location --request GET 'http://localhost:5000'
Goto your APM dashboard, result look like this:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apm-agent-utils-1.4.tar.gz.
File metadata
- Download URL: apm-agent-utils-1.4.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.5 Linux/5.4.0-72-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fee78b6b293d1169649a3809526880c288bd6d80b360dddfcf757a509916051b
|
|
| MD5 |
2cefd823ce425f7ec78bec79756106ba
|
|
| BLAKE2b-256 |
6254c32e7723b97cfb765595fdd3900759f95fe7b29267ca1e03229374d9ec78
|
File details
Details for the file apm_agent_utils-1.4-py2.py3-none-any.whl.
File metadata
- Download URL: apm_agent_utils-1.4-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.5 Linux/5.4.0-72-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54e33c33c0e073e2e5cbb5c688d35d623317873222f0c76bc5ac4e66f2cd7454
|
|
| MD5 |
99bfbb61d3a271df7044cc58a720c8fe
|
|
| BLAKE2b-256 |
3dd325f34d252fbbb422936e14ebc59164506bba0bfd109894af1576e66c0501
|