ObserveNow
...
Cloud Providers
Microsoft Azure

Azure Functions

overview this document outlines the steps to integrate azure functions with a centralized monitoring solution using opentelemetry it covers the setup for a central opentelemetry collector, configuring azure event hub for log streaming, and monitoring system metrics for azure functions following this guide will help establish an observability pipeline for capturing and visualizing metrics, logs, and traces, thereby enabling comprehensive monitoring of your azure based applications prerequisites before proceeding with the setup, ensure the following prerequisites are met azure subscription an active azure subscription with appropriate permissions virtual machine (vm) a vm instance provisioned in your cloud environment with the following specifications minimum 2 cpus and 4 gb ram ports 4317 (grpc) and 4318 (http) open for inbound traffic azure cli installed on your local machine for managing azure resources and configurations azure monitor receiver configuration steps to configure azure monitor receiver create a service principal follow the instructions in the https //learn microsoft com/en us/azure/active directory/develop/howto create service principal portal documentation to create a service principal name it opsverse collector sp and leave the redirect uri empty assign read permissions to azure monitor follow the https //learn microsoft com/en us/azure/role based access control/role assignments portal documentation to assign read access to azure monitor you can assign permissions at the subscription level for broader access configure authentication for the service principal follow the https //learn microsoft com/en us/entra/identity platform/howto create service principal portal#option 3 create a new client secret documentation to create a client secret be sure to copy the client secret, as it will be needed in the configuration file as client secret retrieve client id and tenant id go to the azure portal and search for the application you created you will find the application (client) id and directory (tenant) id in the overview section these values will be used in your opentelemetry collector configuration otel collector setup azure vm installation steps to install the opsverse agent on your azure vm, execute the following command make sure to replace the placeholders with your specific values curl https //raw\ githubusercontent com/opsverseio/installers/main/prometheus exporters/install exporter amd64 sh | sudo bash s e opsverse otelcontribcol t \<collector traces endpoint> m \<collector metrics endpoint> p \<password> u \<username> the traces collector url,metrics url, user, and password can be found in the admin console under "urls and integrations" after the installation, navigate to the configuration file directory cd /etc/opsverse/exporters/opsverse otelcontribcol open the config yaml file in your preferred editor sudo nano config yaml add the azuremonitor receiver block and a new metrics pipeline to the existing configuration receivers otlp protocols grpc endpoint 0 0 0 0 4317 http endpoint 0 0 0 0 4318 azuremonitor subscription id "\<your subscription id>" tenant id "\<your tenant id>" client id "\<your client id>" client secret "\<your client secret>" resource groups \["\<your resource group>"] collection interval 60s service pipelines metrics/am receivers \[azuremonitor] exporters \[prometheusremotewrite] after modifying the configuration, restart the opentelemetry collector to apply the changes sudo systemctl restart opsverse otelcontribcol add a dns label to the public ip address of the collector vm for easier reference in azure portal like this opsverse central collector centralindia cloudapp azure com use existing opsverse agent if your setup already includes a kubernetes cluster running the opsverse agent, as per the opsverse agent setup guide https //docs opsverse io/install the opsverse agent#e7l6c , you can reuse the same collector to send telemetry data from your azure function app expose an ingress endpoint for the collector service add an ingress endpoint for the opentelemetry collector service in your kubernetes cluster this endpoint will be used in the azure function app code instrumentation to define the otlp export endpoint update the opentelemetry collector configuration modify the existing configmap for the opentelemetry collector in your cluster add the following block under the receivers and service pipelines section receivers otlp protocols grpc endpoint 0 0 0 0 4317 http endpoint 0 0 0 0 4318 azuremonitor subscription id "\<your subscription id>" tenant id "\<your tenant id>" client id "\<your client id>" client secret "\<your client secret>" resource groups \["\<your resource group>"] collection interval 60s service pipelines metrics/am receivers \[azuremonitor] exporters \[prometheusremotewrite] restart the opentelemetry collector deployment kubectl rollout restart deployment \<otel collector deployment name> azure event hub setup setup steps create an event hubs namespace navigate to the azure portal and select create a resource search for event hubs and select create fill in the required details, including resource group choose an existing group or create a new one namespace name enter a unique name for your namespace region choose the appropriate region click review + create to provision the namespace create an event hub inside your event hubs namespace, go to event hubs and select + event hub enter a name for your event hub ( logs) and click create create a shared access policy in your event hub, go to shared access policies click add , name the policy (e g , opsverselisten), and select listen permission save and copy the connection string–primary key for later use view the metrics in observenow ensure the following are met you have an azure subscription and an azure function instance running the central collector is set up with the azure monitor exporter metrics collected from azure function can be viewed under the explore section of observenow grafana view the traces in observenow to monitor your azure function app, use opentelemetry (otel) sdks to instrument your application for collecting and forwarding metrics and traces to a central collector installing the opentelemetry sdk install necessary packages in this example we are using node js npm install @opentelemetry/api npm install @opentelemetry/auto instrumentations node npm install @opentelemetry/exporter trace otlp http set environment variables or configure a config file export otel exporter otlp endpoint="http //\<your central collector dns> 4318/v1/traces traces collected from azure function can be viewed under the explore section of observenow grafana logs integration configure diagnostic settings navigate to the diagnostic settings of the azure function you want to log click "add diagnostic setting" and select the log categories for export choose "stream to an event hub" and input the event hub details created earlier integrate with opsverse console log into the opsverse console and navigate to your observenow stack go to integrations → azure integration → logs, and enable the feature input the event hub connection string created earlier and save after completing the integration, logs should appear in grafana labeled as {job="loki source azure event hubs"}