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 Provenance Actions
apm-agent-utils-1.4.tar.gz 4.7 kB Without provenance Details for apm-agent-utils-1.4.tar.gz

Built distribution (wheel)

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

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

Security for apm-agent-utils 1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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