Skip to main content

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

  1. python2.7+ || python3.6+
  2. 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:
structure
Run app

python3 main.py

Get your endpoint

curl --location --request GET 'http://localhost:5000'

Goto your APM dashboard, result look like this: successful dashboard

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

apm-agent-utils-1.4.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

apm_agent_utils-1.4-py2.py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page