Skip to main content

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

Metadata

Release files for apm-agent-utils 1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apm-agent-utils 1.4
File Size Uploaded
apm-agent-utils-1.4.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apm-agent-utils 1.4
File Interpreter ABI Platform
apm_agent_utils-1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 10.0 kB

Release files / apm-agent-utils-1.4.tar.gz

Download URL apm-agent-utils-1.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fee78b6b293d1169649a3809526880c288bd6d80b360dddfcf757a509916051b
BLAKE2b-256 checksum
How to use checksums
6254c32e7723b97cfb765595fdd3900759f95fe7b29267ca1e03229374d9ec78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.8.5 Linux/5.4.0-72-generic

Release files / apm_agent_utils-1.4-py2.py3-none-any.whl

Download URL apm_agent_utils-1.4-py2.py3-none-any.whl
Size 5.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
54e33c33c0e073e2e5cbb5c688d35d623317873222f0c76bc5ac4e66f2cd7454
BLAKE2b-256 checksum
How to use checksums
3dd325f34d252fbbb422936e14ebc59164506bba0bfd109894af1576e66c0501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.8.5 Linux/5.4.0-72-generic

Release history Release notifications | RSS feed

This release

1.4 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page