Type to search.

Monitoring Azure Functions

Serverless Observability

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

APM Agent Python

The Elastic APM Python agent enables you to trace the execution of operations in your Python applications, sending performance metrics and errors to the Elastic APM Server.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

You need an APM Server to which you can send APM data. Follow the APM Quick start if you have not set one up yet. For the best-possible performance, we recommend setting up APM on Elastic Cloud in the same Azure region as your Azure Functions app.

Note

Currently, only HTTP and timer triggers are supported. Other trigger types may be captured as well, but the amount of captured contextual data may differ.

Elastic APM uses Worker Extensions to instrument Azure Functions. This feature is not enabled by default, and must be enabled in your Azure Functions App. Please follow the instructions in the Azure docs.

Once you have enabled Worker Extensions, these two lines of code will enable Elastic APM’s extension:

Python
from elasticapm.contrib.serverless.azure import ElasticAPMExtension

ElasticAPMExtension.configure()

Put them somewhere at the top of your Python file, before the function definitions.

You need to add elastic-apm as a dependency for your Functions app. Simply add elastic-apm to your requirements.txt file. We recommend pinning the version to the current newest version of the agent, and periodically updating the version.

The APM Python agent is configured through App Settings. These are then picked up by the agent as environment variables.

For the minimal configuration, you will need the ELASTIC_APM_SERVER_URL to set the destination for APM data and a ELASTIC_APM_SECRET_TOKEN. If you prefer to use an APM API key instead of the APM secret token, use the ELASTIC_APM_API_KEY environment variable instead of ELASTIC_APM_SECRET_TOKEN in the following example configuration.

Shell
$ az functionapp config appsettings set --settings ELASTIC_APM_SERVER_URL=https://example.apm.northeurope.azure.elastic-cloud.com:443
$ az functionapp config appsettings set --settings ELASTIC_APM_SECRET_TOKEN=verysecurerandomstring

You can optionally fine-tune the Python agent.

That’s it; Once the agent is installed and working, spans will be captured for supported technologies. You can also use capture_span to capture custom spans, and you can retrieve the Client object for capturing exceptions/messages using get_client.