Netlify Edge Function

Prev Next

Netlify is a deployment platform for modern web applications. It provides a global content delivery network, builds automation, serverless functions, and Edge Functions. Edge Functions allow you to run JavaScript at the edge of the Netlify network. They can intercept, inspect, and modify HTTP requests and responses before they reach your application. This makes them suitable for tasks such as routing, access control, performance optimization, and traffic inspection.

Traceable integrates with Netlify Edge Functions to capture request and response data and send it to the Traceable Platform Agent. This enables API discovery, monitoring, and security analysis for applications deployed on Netlify. The integration does not require changes to your backend code. You only need to ensure that the Traceable Platform Agent is reachable from the Netlify environment.

What you will learn in this topic

In this topic, you will learn the following:

  • How Traceable uses Netlify Edge Functions to capture API traffic

  • What prerequisites must you complete before starting the integration

  • How to download the Traceable Netlify Edge Function

  • How to configure the required environment variables in your Netlify project

  • How to place and register the Traceable Edge Function in your repository

  • How to deploy the updated configuration to Netlify

  • How to verify that Traceable is receiving the data correctly


How the integration works

Traceable provides a JavaScript file named traceable.js that runs as a Netlify Edge Function. When this function is invoked, it captures request and response metadata based on your configuration. The data is then exported to the Traceable Platform Agent. Exporting is asynchronous and does not affect the user response.

To enable the integration, you must configure environment variables in Netlify, add the Traceable Edge Function file to your project, and reference it in your netlify.toml configuration file.

The netlify.toml file is the main configuration file for a Netlify project. It defines how Netlify builds, deploys, and runs features in your site or application. This file enables you to configure settings in a structured and version-controlled manner, rather than relying solely on the Netlify UI.

You can use netlify.toml to:

  • Configure build settings

  • Define environment variables

  • Set up redirects and rewrites

  • Enable plugins

  • Register Edge Functions

  • Control how Netlify handles specific paths or behaviors during deployment

When you add the Traceable Edge Function entry to netlify.toml, you are instructing Netlify to run the traceable function for specific HTTP paths. This is how Netlify knows when to trigger the function during incoming requests.


Before you begin

Before starting the installation, ensure that the following prerequisites are met.

Traceable Platform Agent Deployment

You must have a Traceable Platform Agent instance deployed and reachable from your Netlify Edge Function. This can be a self-hosted instance or a Traceable-hosted agent endpoint. For more information, see Installation.

Access to your Netlify project

You must be able to:

  • Add or edit environment variables

  • Add files to your project repository

  • Update the netlify.toml configuration file


Step 1. Download the Traceable Netlify Edge Function

Download the latest version of the Traceable Netlify Edge Function from Traceable’s download site.

This download contains the traceable.js file that captures and exports traffic data.

Step 2. Configure Environment Variables

Open your Netlify project and navigate to:

Project → Project Configuration → Environment Variables

Add the following variables in the Netlify UI. These variables must be created in the Site settings → Environment variables section of the Netlify dashboard. Edge Functions read these values at runtime from the Netlify environment.

Variable Name

Default Value

Description

TA_TPA_ADDRESS

undefined

Address of the Traceable Platform Agent. This is a mandatory value.

TA_SERVICE_NAME

website

Name of the service that appears in the Traceable platform.

TA_ENVIRONMENT_NAME

undefined

Defaults to the environment configured in the Traceable Platform Agent if not set.

TA_GUID

undefined

Required when sending data to a Traceable hosted agent.

TA_MAX_SIZE_BYTES

131072

Maximum number of bytes to capture from request or response bodies.

TA_DEBUG

false

Enables debug logging.

TA_CAPTURE_CONTENT_TYPES

["json", "xml", "grpc", "x-www-form-urlencoded"]

List of content types to capture.

TA_TIMEOUT_MS

500

The maximum amount of time allowed for export processing.

Note

TA_TPA_ADDRESS is the only mandatory variable. All other variables are optional and can be configured as needed.

After adding or updating environment variables, you must redeploy your Netlify site. Netlify does not apply new environment variables to an existing deployment. A new deployment ensures that the updated values are available to the Traceable Edge Function at runtime.

To redeploy:

  1. Navigate to Deploys in your Netlify dashboard.

  2. Select Trigger deploy → Deploy site, or push a new commit to your repository.

Step 3. Add the Traceable Edge Function

Create the Edge Function Directory

Ensure that the following directory exists in your project:

your-project-repo/netlify/edge-functions

Copy the Traceable File

Place the downloaded traceable.js file into this directory.

Register the Edge Function in netlify.toml

Add the following configuration to your netlify.toml file:

[[edge_functions]]
function = "traceable"
path = "/api/*"

This configuration instructs Netlify to execute the Traceable Edge Function for all requests whose paths begin with /api/. You may adjust the path according to your application requirements.

Netlify also supports additional configuration options such as filtering, exclusion rules, and execution ordering. Refer to the Netlify documentation for further information.


Deploy your changes

After updating your repository by adding the Traceable Edge Function file and modifying netlify.toml, you must deploy your site again. This deployment applies the new files, registers the Edge Function, and activates the updated configuration.

To deploy:

  • Commit and push your changes to your repository, or

  • Trigger a manual deploy from the Netlify dashboard.

Netlify will build and publish the latest version of your project, and the Traceable Edge Function will begin capturing traffic.


Verify Data Collection

After deployment:

  1. Trigger requests to the configured paths in your application

  2. Log in to the Traceable platform

  3. Navigate to sections such as API Catalog or API Activity

  4. Confirm that API traffic is being collected

If traffic appears in the platform, the integration is working correctly.