Skip to main content

Offload Analytics to a Secondary Service

ngrok and Traffic Policy let you integrate your "front door" gateway with an analytics service you host within your network to capture vital information about your traffic as a part of the request-response lifecycle.

With this gateway setup and the http-request action, you can:

  • Host your analytics service in any network, region, or cloud.
  • Leave your analytics service completely unexposed to the public internet.
  • Simplify your upstream services by removing libraries and code for instrumenting them directly.
  • Configure for exactly the timeout and retry conditions your services require.

1. Create endpoints for your services

Start an internal Agent Endpoint, replacing $PORT based on where your upstream service listens. You can also use one of our SDKs or the Kubernetes Operator.

Loading…

Start a second endpoint for your analytics service.

Loading…

2. Reserve a domain

Navigate to the Domains section of the ngrok dashboard and click New + to reserve a free static domain like https://your-service.ngrok.app or a custom domain you already own.

3. Create a Cloud Endpoint

Navigate to the Endpoints section of the ngrok dashboard, then click New + and Cloud Endpoint.

In the URL field, enter the domain you just reserved to finish creating your Cloud Endpoint.

4. Request customer data from your CRM and apply rate limiting with Traffic Policy

While still viewing your new cloud endpoint in the dashboard, copy and paste the policy below into the Traffic Policy editor.

Loading…

What's happening here? This policy sends all requests directly to your upstream service at https://service.internal.

As part of the response lifecycle, this policy also sends an authenticated request to your analytics service with a body containing attributes, injected with CEL interpolation, about the user's request and your server's response. The http-request action is purposely given a short timeout and no retry logic to ensure this analytics request doesn't add unnecessarily slow your service's response time.

5. Try out your endpoint

Visit the domain you reserved either in the browser or in the terminal using a tool like curl. You should see the app or service at the port connected to your internal Agent Endpoint.

What's next?

← Check out more examples