Inspect a Segment gateway
When Segment sits in the middle of your pipeline, events can change after they leave your apps. Protocols Transformations rename events and properties, destination filters drop events, and each destination receives its own version of the data. Avo Inspector can check events at more than one point along that path, so you can see where a change happened rather than only that the data in a destination looks wrong.
Gateways are in beta. Reach out at support@avo.app to get access and provide feedback.
This guide is for a Segment workspace modelled as a gateway in Avo. If you only want to inspect the events one Segment source collects, follow the Inspector Segment integration instead.
How it works
In Avo, a gateway describes a central point that events pass through. Its inputs are the sources that send events into Segment, and its outputs are the destinations Segment sends events on to. Each place where Avo Inspector checks events is called a checkpoint. A Segment gateway has two kinds:
- The gateway checkpoint. The “Avo Inspector v2” destination in Segment receives every track event as Segment receives it, after any source-scoped Protocols Transformations. It is a sibling of your other destinations, so it never sees what they receive.
- One checkpoint per output. Avo generates a Segment Destination Insert Function for each output. Attached to that output’s destination, it inspects each track event after the destination’s filters, its destination-scoped Protocols Transformations and, for Actions destinations, its mapping triggers. It runs before the destination’s field mappings, so it never sees the mapped payload.
Inspector checks track events. The function passes every other event type (identify, page, screen, group, alias and delete) on to the destination without inspecting it, and it passes track events on unchanged too: it only reads them and sends their schema to Avo.
Inspector receives the names and types of event properties, not their values. The one exception is the gateway checkpoint’s destination when you add an Avo Inspector Public Encryption Key to it: in development and staging, values are then sent end-to-end encrypted for property value validation. Leave the key empty if you don’t want that.
Before you begin
- The gateway exists in your Avo tracking plan, with its inputs and outputs. To find it, open Sources in the sidebar and then the Gateways tab.
- You can create Functions in your Segment workspace and edit the settings of the destinations you want to inspect.
- Your Segment workspace has the version of the “Avo Inspector v2” destination with a Gateway Support setting. This version arrives with an update to Segment’s destination. If you don’t see Gateway Support in the destination’s settings yet, the update hasn’t reached your workspace.
Step 1. Open the gateway’s Inspector setup
- In Avo, open Sources in the sidebar, then the Gateways tab, and select your gateway.
- Open the
Inspector setuptab. - Choose
Segmentas the sender. - Copy the Inspector API key shown at the top of the tab. The gateway has one key for all of its checkpoints.
Set up each environment (development, staging and production) separately, each with its own destination and functions.
Step 2. Add the destination for the gateway checkpoint
- In Segment, add the Avo Inspector v2 destination to each source that sends to this gateway.
- Paste the Inspector API key into
Avo Inspector API Key. - Choose the
Environment:dev,stagingorprod. - Make sure
Gateway Supportis on. It is on by default for new destinations. If you added the destination before the setting existed, turn it on. - Set
Inspected Fieldsto what you want to inspect. See What Inspector inspects below. The default isEverything. - Keep one
Track Schema From Eventmapping and leave itsOutput Referencefield empty. An empty reference is what marks these events as the gateway checkpoint.
Use a separate “Avo Inspector v2” destination for the gateway. A destination that inspects a regular Avo source must keep Gateway Support off.
Step 3. Inspect each output with an Insert Function
In Avo, the Inspect each output step of the Inspector setup tab lists one Insert Function per output, titled by the output’s destination. Each function already contains the Inspector API key and that output’s reference. Above the functions, choose:
- the
Environmentthe functions report to. It defaults toProduction, so change it before copying the code if you are setting up development or staging; - what to
Inspect. Pick the same choice asInspected Fieldson the destination, so the gateway and its outputs inspect the same fields.
The functions are regenerated whenever you change either choice, so make both choices before copying any code.
For each output:
- In Avo, expand the output’s Insert Function and copy its code.
- In Segment’s Functions catalog, choose
New Function, selectInsertand paste the code. - Choose
Connect a destinationand attach the function to that output’s destination. - In the destination’s
Functionstab, turn onEnable Function.
A few things to know:
- A destination takes one insert function. If the destination already has one, move its code into the
applyYourInsertFunctionfunction in Avo’s code. Avo inspects the track events your code returns. - Every event type is passed through. Segment blocks event types that an insert function has no handler for. Avo’s function handles every type, so if your old function left out a handler to keep an event type away from the destination, throw
EventNotSupportedfor that type inapplyYourInsertFunction. - Errors in your own code still apply. If
applyYourInsertFunctionthrows, the function fails as it would without Avo. Avo’s inspection never throws and never changes the event. - Storage destinations can’t be inspected this way. Segment doesn’t allow insert functions on storage destinations such as warehouses.
- Execution time. The function sends one request to Avo per track event and waits at most one second for it, well inside Segment’s five-second limit for a function. Segment bills function execution time.
- Outputs without a reference. An output created before output references existed shows no reference yet. Its function has an empty
AVO_OUTPUT_REFERENCEand sends nothing to Avo. Contact support@avo.app if you see this, and copy the regenerated function once the output has a reference.
Step 4. Set the origin hint (optional)
The origin hint tells Avo which source an event came from, so Inspector can attribute events at a checkpoint to the right Avo source.
Segment passes on the event it received, so the event’s own version is that source’s version. Avo uses it as the origin app version unless you set one to override it. With an origin hint, an event with no version anywhere is recorded without one.
Map the values to sources in Avo. For each source, open its Inspector setup tab and add the hint values that name it under Origin hints. A value can belong to only one source.
On the gateway checkpoint’s destination:
- On the “Avo Inspector v2” destination’s
Track Schema From Eventmapping, setOrigin Hintto a label that names this Segment source, such asios-app. - If one source carries events from several apps or platforms, map a path instead, such as
$.context.app.nameor$.context.library.name. - Leave
Origin App Versionempty to use the event’s own version: the destination’sApp Version Propertysetting, then the mapping’sApp Versionfield.App Versionreads$.context.app.version, which only mobile sources send, so for a web source setApp Version Propertyto the event property that carries the version, such asapp_version. - Set
Origin App Versiononly to read the version from somewhere else. When set, it replaces both of those.
On each Insert Function:
- In the function’s
Settingstab, add a setting labelledAvo Origin Hint. Segment names itavoOriginHint. - In the settings of each destination the function is connected to, give
Avo Origin Hintthe value that names that destination’s Segment source, such asios-app. You can editgetOriginHintin the code instead. - The function uses the event’s own version,
event.context.app.version, which only mobile sources send. For a web source, editgetOriginAppVersionin the code to return the event property that carries the version, for examplereturn event.properties && event.properties.app_version;. A value it returns overrides the event’s own version.
What Inspector inspects
A warehouse stores more than an event’s properties: it also stores the event’s context and envelope fields as columns. A gateway can inspect those too, named the way the warehouse names its columns. You choose this with Inspected Fields on the “Avo Inspector v2” destination, for the gateway checkpoint, and with Inspect in Avo, for the Insert Functions.
| Choice | What Inspector inspects |
|---|---|
| Event properties | The event properties only. |
| Event properties and context | Also every field in the event’s context, such as context_page_path or context_library_name. |
| Everything | Also anonymous_id, user_id, id (the message ID), event, timestamp, original_timestamp, sent_at and received_at. |
How fields are named:
- Context fields are flattened. Nested keys are joined with
_and the name is prefixed withcontext_, socontext.page.pathbecomescontext_page_path. - camelCase becomes snake_case, and a run of capitals ends before its last capital, so
userAgentDatabecomesuser_agent_dataandABTestbecomesab_test. - Arrays in
contextare inspected as their JSON text. Envelope fields that are missing ornullare skipped. - If an event property already has a column’s name, Inspector inspects the event property.
Only names and types are sent for these fields, never their values.
Your tracking plan doesn’t describe context and envelope fields yet, so with Event properties and context or Everything they appear in Inspector as properties that aren’t in your plan. Choose Event properties if you only want the properties you track to be checked.
Step 5. Check the events in Avo
After the destination and the functions are enabled, the Inspector Events view shows what Inspector observed at the gateway checkpoint and at each output, with event counts and issues per checkpoint. Development events appear within a couple of minutes. Production events can take up to 2 hours to appear. Make sure you are looking at the environment you set up.
If you run into problems with your setup, reach out at support@avo.app.