This guide explains how to set up Azure Function Instrumentation to instrument request and response flows with Typescript as the language.
Access to Azure Functions in Azure cloud
The Azure Functions extension part of Visual Studio Code editor installed
You can configure the Astra Traffic Collector to receive data over HTTP or HTTPS. For production environments, HTTPS is recommended for secure data transmission.
Open config_custom.yaml
in your traffic collector's instance and update the receivers section:
receivers:
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318" # HTTP receiver on port 4318
processors:
#...
Save the file once edited and restart the collector using:
systemctl restart astra-traffic-collector.service
Update the same config_custom.yaml
to use HTTPS with your cert and key files from the trusted authority:
receivers:
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318" # HTTP receiver on port 4318
tls:
cert_file: "/etc/otelcol-contrib/<cert-file>"
key_file: "/etc/otelcol-contrib/<privkey-file>"
The third field is ca_file
, which is used when the certificate is self-signed or from an untrusted CA.
If your certificate is issued by a trusted CA (e.g., Let's Encrypt), you don’t need to specify ca_file
.
Ensure the certificate files are correctly placed in /etc/otelcol-contrib/
and have proper permissions. The private key should be readable only by the owner for security reasons, whereas the certificate can be readable by others but should not be writable.
Next, modify your volume section in the docker-compose.yaml by adding the following lines in your Astra Traffic Collector to include volume mounts for the certificates:
volumes:
- <path_to_certificates>/<cert-file>:/etc/otelcol-contrib/<cert-file>:ro
- <path_to_certificates>/<privkey-file>:/etc/otelcol-contrib/<privkey-file>:ro
Save the file once edited and restart the collector using:
systemctl restart astra-traffic-collector.service
The following code reference and package names are for Typescript:
Navigate to your local directory where your function is initialized using the Azure Functions extension.
Run the below commands on your terminal in your Azure Functions project directory to install the dependencies of OpenTelemetry SDK and Azure Functions:
npm install @azure/functions
npm install @opentelemetry/exporter-trace-otlp-http
npm install @opentelemetry/sdk-trace-node
npm install @opentelemetry/resources
npm install @opentelemetry/api
Navigate to <path-to-function>/src/functions/function.ts
.
Copy and paste the code from the provided OpenTelemetry boilerplate into your local code editor.
Update the following values in the script given:
Sensor ID: Set <sensorId>
using the value provided at the time of creating the Azure Functions Integration. Keep the value within double quotes.
Astra Traffic Collector Endpoint: Set <collectorUrl>
to the appropriate Astra OpenTelemetry collector URL. Keep the value within double quotes.
Write your code logic before the telemetry related setup (e.g., withTelemetry()
function) and the final return
statement, as it automatically sends your response back to anyone calling your API.
The provided boilerplate is carefully configured for monitoring API performance and auditing operations. Avoid unnecessary modifications to the setup unless explicitly required.
Click on the "Get function URL" button (🔗) in the Azure Functions Console and copy the generated URL.
Test your function using the copied URL via a browser or a cURL client.
The response will match the responseBody
variable in your handler function.
Keep business logic separate from telemetry logic as demonstrated in the provided boilerplate code.
Use HTTPS configuration for your Astra Traffic Collector to ensure secure communication.