---
title: Tracking your origin's name, IP, and port
summary: >-
  To help debug issues and monitor backend behavior, you can capture and log the
  origin server's name, IP, and port, ensuring visibility into where requests
  are routed, even when responses aren't cached.
url: >-
  https://www.fastly.com/documentation/solutions/tutorials/custom-vcl/track-origin-name-ip-and-port
---

Being able to track information related to your origin can be helpful in troubleshooting errors and making sure requests are processed as expected. Fastly provides three VCL variables that allow you to see and track origin information:

- [`beresp.backend.name`](https://www.fastly.com/documentation/reference/vcl/variables/backend-response/beresp-backend-name/)
- [`beresp.backend.port`](https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/beresp-backend-port/)
- [`beresp.backend.ip`](https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/beresp-backend-ip/)

You can create VCL snippets that use these variables to capture information about an origin and then [set up remote log streaming](https://www.fastly.com/documentation/solutions/tutorials/custom-vcl/track-origin-name-ip-and-port#set-up-remote-log-streaming) to save that information.

## Retrieve the origin information

Create a regular [VCL Snippet](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/using-vcl-snippets) to retrieve the origin information:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL snippets**.

5. Click **Add snippet**.

6. Fill out the **Add VCL snippet** fields as follows:

   - Using the **Type** controls, select **Regular** to create a regular VCL snippet.
   - In the **Name** field, enter an appropriate name (for example, `Retrieve-Origin-Information`).
   - Using the **Placement** controls, select **Within subroutine**.
   - From the **Subroutine** menu, select **fetch (`vcl_fetch`)**.
   - _(Optional)_ In the **Priority** field, enter the order in which you want the snippet to execute. Lower numbers execute first.
   - In the VCL editor, add the following VCL logic:

   ```vcl
   # save the variables for access in deliver
   set beresp.http.Your-Backend-Name = beresp.backend.name;
   set beresp.http.Your-Backend-IP-Port = beresp.backend.ip ":" beresp.backend.port;
   ```

7. Click **Add** to create the snippet.

## Change the response header to a request header

Create another regular VCL Snippet that changes the response header to a request header before logging the information:

1. Click **VCL snippets**.

2. Click **Add snippet**.

3. Fill out the **Add VCL snippet** fields as follows:

   - Using the **Type** controls, select **Regular** to create a regular VCL snippet.
   - Using the **Placement** controls, select **Within subroutine**.
   - From the **Subroutine** menu, select **deliver (`vcl_deliver`)**.
   - _(Optional)_ In the **Priority** field, enter the order in which you want the snippet to execute. Lower numbers execute first.
   - In the VCL editor, add the following VCL logic:

     ```vcl
     if (fastly_info.state ~ "(MISS|PASS)") {
        # only on a miss or pass
        # save the responses back to req.request because
        # request headers are not sent back to the client
        set req.http.Your-Backend-Name = resp.http.Your-Backend-Name;
        set req.http.Your-Backend-IP-Port = resp.http.Your-Backend-IP-Port;
        }

     # remove the identifying information from the response
     unset resp.http.Your-Backend-Name;
     unset resp.http.Your-Backend-IP-Port;
     ```

4. Click **Add** to create the snippet.

> **HINT:** If a response header like `beresp.http.Your-Backend-Name` exists in `vcl_fetch` when VCL is processed, then a corresponding response header `resp.http.Your-Backend-Name` will exist in `vcl_deliver` and will be logged by default. This means that response headers will be included in response output, exposing origin information (e.g., IP address, port number, or origin name) in the process. Fortunately, request headers are not passed back to the client, but their information remains accessible from `vcl_log`.

## Set up remote log streaming

Once your snippets are created, you can set up remote log streaming for tracking purposes. Do this by adding `req.http.Header-Name` to the **Log format** field in the logging endpoint you configured in the [remote log streaming](https://www.fastly.com/documentation/guides/integrations/streaming-logs/setting-up-remote-log-streaming) guide. Using the example above, you would add `req.http.Your-Backend-Name` and `req.http.Your-Backend-IP-Port`. Once you've reviewed the changes you've made, click the **Activate** button to deploy these configuration changes for your service.

> **HINT:** When you configure remote log streaming to capture this information, remember the VCL is executed twice, once on the shield node and again on the edge node. This means that the first log (from the shield node) will have the origin's information and the second log (from the edge node) will have the shield's information.
