Overview
Whenever changes occur in your ngrok account or when traffic transits through
your endpoints, a log is generated. You may export these logs and in some cases, filter
them to those relevant to you and publish them to any number of destinations.
ngrok’s logging system was designed for three primary use cases:
- Sending logs of your ngrok traffic to external services such as Datadog and
Amazon CloudWatch Logs
- Sending audit logs of ngrok configuration changes to your SIEM
- Enabling you to programmatically respond to events on your ngrok account
There are over 40 log sources published via ngrok at the time of writing.
They break down into two important classes of logs:
- Traffic Logs: When traffic transits through your endpoints like processing an HTTP request or TCP connection
- Audit Logs: Changes to your account like create/update/delete of Domains, API Keys, IP Policies, etc.
Concepts
ngrok’s logging system is composed of three simple primitives. You create
a Log Export to subscribe to a set of Log Sources and
publish those logs to one or more Log Destinations.
- Log Exporting: Define which Log
Sources to capture and which Log Destinations to publish to.
- Log Sources: The ngrok log types to capture and
optionally a set of fields to record and a boolean filter expression.
- Log Destinations: Where logs are sent, e.g.
Datadog, CloudWatch, Kinesis.
Quickstart
You can create your first Log Export on the Log Exporting page of your ngrok
Dashboard to begin capturing
and publishing logs.
We also publish guides to get started with each of ngrok’s Log Destinations:
Log Exporting
A Log Export defines which Log Sources to capture and which
destinations to publish to. If you’re familiar with other logging systems, they may
call this a listener, a hook, a probe or a tap.
When you create a Log Export, you select:
- One or more Log Sources to subscribe to
- One or more Log Destinations to publish the subscribed logs to
Log Exports can be created on the ngrok
Dashboard or via the
Log Exporting API Resource.
Log Sources
Log Sources choose which logs a Log Export captures. Other logging
systems may call this a selector.
The ngrok Log Sources reference documents the full list
of Log Sources and their fields.
Versioning and Payload Stability
Log Sources include a version number in their name. Each Log Source ends
with a version string after a dot, e.g. api_key_created.v0
.
New fields may be added to the payloads of a Log Source without a version
change. Any other change to the log representation will lead to the
introduction of a new version of the Log Source.
Audit Logs
ngrok emits Audit Logs when changes are made to
your account like create/update/delete of Domains, API Keys, IP Policies, etc.
Traffic Logs
When traffic transits through your endpoints, ngrok emits Traffic
Logs like processing an HTTP request or TCP
connection.
Traffic Logs support the ability to select exactly which fields you’d like to
include in the captured log. This provides you with control over how much
data is sent to the destinations.
Traffic Logs also support the ability to be filtered. As part of the Log Source
definition you can specify a CEL expression which is evaluated against each log
to determine if it should be captured. See the Filters section
for further detail.
Filters
You may specify a filter on Traffic
Logs since the velocity of these logs can be quite high. Filters are a boolean
expression defined in Google’s Common Expression Language
(CEL).
Filters are evaluated on each log as it is published to determine whether it
should be sent to the Log Export’s destinations.
Traffic Logs are often high cardinality. We support filters because you may
only interested in logging a subset of traffic (e.g. specific client IPs).
Filters also enable you to control spend on downstream destinations where you
incur costs based on the quantity of data processed and stored.
The log object is made available to the CEL filter expression as the ev
variable. ev
corresponds to the object
field of the captured log. Use
standard JSONPath syntax to access
the fields of the log you want to use in your filters.
Filter expressions have the following limitations:
- Only some fields of an log are available in the
ev
object. The Log
Source’s reference documentation will specify whether a field may be evaluated
in a filter expression.
- Log metadata fields like
principal
or event_timestamp
are not available
Filter Examples
Filter for connections from a particular hostname
ev.conn.server_name.matches("ngrok-docs-examples\\.ngrok\\.dev")
Filter for connections to an endpoint that didn’t use HTTPS
ev.conn.server_name.matches(".*-your-org\\.ngrok\\.dev") &&
ev.conn.server_port == 80
Filter for connections to a hostname that exclude traffic from a client IP
ev.conn.client_ip != "2601:0:8200:0:4cd7:fd52:0:7823" &&
ev.conn.server_name == "ngrok-docs-examples.ngrok.dev"
Log Destinations
An Log Destination encapsulates the configuration to publish logs to other
systems. Other logging systems may call this a sink or output.
Log Destinations are typically third-party logging aggregators. The following
destinations are currently supported:
Each destination requires provider-specific configuration. If you create a
destination in the ngrok dashboard, you’ll be prompted to send a test log to
verify the integration.
When configuring AWS destinations you’ll be prompted to optionally download a
small helper script which will automatically configure the appropriate IAM
objects necessary for integration. You may also set these values up via the AWS
Console or tools like Terraform or Pulumi.
Amazon S3 is not a directly supported destination. Instead, configure Amazon Firehose to
deliver logs into an S3
bucket.
Log Payloads
Logs are serialized as JSON when they are published to a destination.
All logs include the following fields:
Name | Description | Example |
---|
account_id | unique identifier for the account, always prefixed with ac_ | ac_2OtNvAlhso10Gx6s7eupzX3F98q |
event_id | unique identifier for this log, always prefixed with ev_ | ev_1vPlyBW3OR44bpPphS4HIZyajDD |
event_type | identifies the object, action, and version of the log | ip_policy_created.v0 |
event_timestamp | timestamp of when the log fired in RFC 3339 format | 2021-07-16T21:44:37Z |
object | the log object | See examples below |
principal | an object of the principal who emitted this log, null for traffic logs | See example below |
The object
property of the log is distinct for each Log Source and contain a JSON object with additional information about the log.
For Audit Logs, the object
representation is identical to its API resource at the time of capture.
Traffic Logs define their own object
representation because they have no corresponding API resource definition.
Principal Object
The principal
object in every log describe the user or bot user responsible
for initiating the log. Principal is defined for all Audit Logs
and it is null
for Traffic Logs (since they do not include a credential).
Name | Description | Example |
---|
id | unique identifier for the principal, either a user or bot | usr_2OtNv9qH5Nk4NuNeszZ39gBxZ4H |
subject | human readable unique identifier for the principal, either a user email or a bot user name | foo@example.com |
source | where the principal initiated the log, either ‘Dashboard’ or ‘API’ | API |
credential | id and uri resource for the credential used for authentication, null if source is ‘Dashboard’ | {"id": "ak_2Oxt94wYsBTLwFUoMZcJRvJTaub","uri": "https://api.ngrok.com/api_keys/ak_2Oxt94wYsBTLwFUoMZcJRvJTaub"} |
Example Payloads
{
"event_id": "ev_25X2AsJ5xpvuOParTYUQWe12XKo",
"event_type": "ip_policy_created.v0",
"event_timestamp": "2022-02-23T23:29:29Z",
"account_id": "ac_2OtNvAlhso10Gx6s7eupzX3F98q",
"principal": {
"id": "usr_2OtNv9qH5Nk4NuNeszZ39gBxZ4H",
"subject": "foo@example.com",
"source": "API",
"credential": {
"id": "ak_2Oxt94wYsBTLwFUoMZcJRvJTaub",
"uri": "https://api.ngrok.com/api_keys/ak_2Oxt94wYsBTLwFUoMZcJRvJTaub"
}
},
"object": {
"id": "ipp_25X2Ao39z73FlVQKZ1iReMPe6Qv",
"uri": "https://api.ngrok.com/ip_policies/ipp_25X2Ao39z73FlVQKZ1iReMPe6Qv",
"created_at": "2022-02-23T23:29:29Z",
"description": "Home network IP",
"metadata": "",
"action": "allow"
}
}
{
"event_id": "ev_25X3yFS6TDkig1KDJWIc4nnJO0c",
"event_type": "http_request_complete.v0",
"event_timestamp": "2022-02-23T23:44:16Z",
"account_id": "ac_2OtNvAlhso10Gx6s7eupzX3F98q",
"object": {
"conn": {
"client_ip": "2601:0:8200:9e:4cd7:0:c97f:7823",
"server_name": "ngrok-docs-example.ngrok.app",
"server_port": ""
},
"http": {
"request": {
"first_byte_ts": null,
"last_byte_ts": null,
"method": "GET",
"url": {
"path": "/docs/obs"
},
"version": "HTTP/2.0"
},
"response": {
"body_length": 13079,
"first_byte_ts": "2022-02-23T23:44:16.732791273Z",
"last_byte_ts": "2022-02-23T23:44:16.737257209Z",
"status_code": 200
}
}
}
}
{
"event_id": "ev_25X4osod1q306srserDeFyghTC4",
"event_type": "tcp_connection_closed.v0",
"event_timestamp": "2022-02-23T23:51:14Z",
"account_id": "ac_2OtNvAlhso10Gx6s7eupzX3F98q",
"object": {
"conn": {
"bytes_in": 3437,
"bytes_out": 90256,
"client_ip": "2601:0:8200:9e:4cd7:0:c97f:7823",
"end_ts": "2022-02-23T23:51:14.005372199Z",
"server_name": "ngrok-docs-example.ngrok.app",
"server_port": "",
"start_ts": "2022-02-23T23:44:16.528374173Z"
}
}
}
Pricing
Log Exports are available to free and Pay-as-you-go plans. For more details, see our ngrok pricing page.
The Traffic Inspector is included with all ngrok accounts with a
retention period starting at 1 day and going up to 3 days. An additional 90 days can be purchased as
an add-on to the Pay-as-you-go plan. For more details, see our ngrok pricing page.