apm-agent-python icon indicating copy to clipboard operation
apm-agent-python copied to clipboard

How to integrate into Frappeframework

Open saranRe opened this issue 2 years ago • 3 comments

We are running Frappe in our Python Project

https://frappeframework.com/ https://github.com/frappe/frappe

Any tips on how to integrate elastic python apm agent into this?

saranRe avatar May 24 '23 06:05 saranRe

To integrate Elastic APM (Application Performance Monitoring) agent into your Python project running Frappe, you can follow these general steps:

Install the Elastic APM agent:

You can install the Elastic APM agent using pip:

-----pip install elastic-apm----- Import and initialize the Elastic APM agent in your Frappe application's main entry point or initialization file. This could be the file where you define your Flask or Django application object. For example, in a Flask application, you might have a file called app.py:

-----------------from elasticapm.contrib.flask import ElasticAPM -----------------from frappe import Frappe

app = Frappe()

Initialize the Elastic APM agent

apm = ElasticAPM(app) Note: Make sure you import the appropriate module based on your web framework. In the example above, ElasticAPM from elasticapm.contrib.flask is used for Flask. If you're using a different framework, refer to the Elastic APM documentation for the relevant module.

Configure the Elastic APM agent by adding the necessary configuration parameters. You can specify these configurations either through environment variables or by passing them directly to the ElasticAPM constructor. Here's an example configuration using environment variables:

bash

export ELASTIC_APM_SERVICE_NAME="your_service_name" export ELASTIC_APM_SERVER_URL="http://your-apm-server:8200" Alternatively, you can provide the configuration directly:

python apm = ElasticAPM(app, service_name="your_service_name", server_url="http://your-apm-server:8200") Make sure to replace your_service_name with a meaningful name for your application and http://your-apm-server:8200 with the URL of your APM server.

Instrument your code: By default, the Elastic APM agent will automatically capture traces for HTTP requests and certain database operations. However, you can also instrument additional code blocks to gain more insights. You can use decorators or context managers to manually instrument specific functions or code blocks. Refer to the Elastic APM documentation for instructions on instrumenting specific parts of your Frappe application.

Start your Frappe application: Start your Frappe application as you normally would, and the Elastic APM agent will now monitor and report performance metrics and errors to your APM server.

Remember to consult the official Elastic APM documentation for more detailed information and instructions specific to your web framework and use case.

Raaja0007 avatar May 24 '23 06:05 Raaja0007

The above doesn't work. It seems to be the auto-generated response. Is it?

saranRe avatar Jun 03 '23 05:06 saranRe

No, it was not an auto-generated response, at least not by our team. I assumed it was a developer or user of Frappe who had it working themselves. I don't have any experience with Frappe and was hoping our Flask instrumentation would work as @Raaja0007 suggested.

We'll add this to our backlog, thanks for the request!

basepi avatar Jun 03 '23 14:06 basepi