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
- 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 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 theev
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
orevent_timestamp
are not available
Filter Examples
Filter for connections from a particular hostname
Filter for connections to an endpoint that didn’t use HTTPS
Filter for connections to a hostname that exclude traffic from a client IP
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:- Amazon CloudWatch
- Amazon Firehose
- Amazon Kinesis
- AWS S3 (via Kinesis Firehose)
- Azure Logs Ingestion
- Datadog Logs
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.
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 |
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
Theprincipal
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"} |