If your pipelines already publish to Kafka, Phield can read PII counts straight from a topic instead of receiving them over HTTP. When a count spikes, it can page the on-call engineer through PagerDuty as well as post to Slack. A jump in SSNs from one service at 2 a.m. is the kind of event that should wake someone, not wait in a channel until morning.
This guide connects Phield to a Kafka topic, publishes counts to it, and shows the PagerDuty event Phield sends when one breaches. The messages carry counts per PII type, never the values.
1. Start a broker and create the topic
Skip this step if you have a Kafka cluster. For a local test, run a single-node broker on a Docker network that Phield will share:
docker network create phield-net
docker run -d --name kafka --network phield-net \
-e KAFKA_NODE_ID=1 -e KAFKA_PROCESS_ROLES=broker,controller \
-e KAFKA_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 \
-e KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT \
-e KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka:9093 \
-e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 -e KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 \
-e KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 -e KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 \
apache/kafka:3.9.1
docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:9092 \
--create --topic phield-pii-counts --partitions 1 --replication-factor 1
Created topic phield-pii-counts.
phield-pii-counts is the topic Phield reads by default.
Phield’s Kafka consumer has no settings for TLS or SASL, so it connects to a plaintext listener without authentication. On a production cluster, give Phield a listener it can reach that way and restrict that listener at the network level. Producers can still authenticate on the cluster’s other listeners.
2. Start Phield with Kafka and PagerDuty
In PagerDuty, add an Events API V2 integration to the service that should be paged and copy its integration key. Then start Phield on the same network:
docker run -d --name phield --network phield-net -p 8443:8443 \
-e PHIELD_API_KEY=replace-with-a-long-random-key \
-e PHIELD_KAFKA_BROKERS=kafka:9092 \
-e PHIELD_KAFKA_TOPIC=phield-pii-counts \
-e PHIELD_KAFKA_GROUP_ID=phield \
-e PHIELD_PAGERDUTY_ROUTING_KEY=0123456789abcdef0123456789abcdef \
-e PHIELD_PAGERDUTY_SEVERITY=critical \
-e PHIELD_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T000/B000/XXXX \
philterd/phield:1.0.0
| Variable | Purpose | Default |
|---|---|---|
PHIELD_KAFKA_BROKERS | Comma-separated brokers. Setting it turns the consumer on. | none |
PHIELD_KAFKA_TOPIC | The topic to read. | phield-pii-counts |
PHIELD_KAFKA_GROUP_ID | The consumer group. | phield |
PHIELD_PAGERDUTY_ROUTING_KEY | The Events API V2 integration key. Setting it turns PagerDuty on. | none |
PHIELD_PAGERDUTY_SEVERITY | The severity on each event. | critical |
PHIELD_SLACK_WEBHOOK_URL | Optional. A Slack Incoming Webhook that gets the same alert text. | none |
Phield passes PHIELD_PAGERDUTY_SEVERITY through without checking it, so use one of the values the Events API accepts: critical, error, warning, or info.
This walkthrough keeps counts in memory, so baselines are lost when the container restarts. Set PHIELD_MONGO_URI for anything that should keep its baselines, as in Alerting on PII spikes with Phield.
The log confirms the consumer started:
2026/12/01 17:53:51 API key authentication is enabled
2026/12/01 17:53:51 Dashboard enabled at /dashboard
2026/12/01 17:53:51 Initializing Kafka consumer for topic phield-pii-counts and brokers kafka:9092
2026/12/01 17:53:51 Starting Kafka consumer loop...
2026/12/01 17:53:51 Phield API starting with HTTPS on port 8443
3. Publish counts to the topic
Each message is the same JSON as a POST /ingest body, one count set per message, with the field names source_id, organization, context, and pii_types. Save these as counts.jsonl, one message per line:
{"source_id": "claims-intake-worker", "organization": "example-corp", "context": "production", "pii_types": {"email": 118, "ssn": 4}}
{"source_id": "claims-intake-worker", "organization": "example-corp", "context": "production", "pii_types": {"email": 121, "ssn": 4}}
{"source_id": "claims-intake-worker", "organization": "example-corp", "context": "production", "pii_types": {"email": 119, "ssn": 27}}
Publish them with the console producer:
docker exec -i kafka /opt/kafka/bin/kafka-console-producer.sh \
--bootstrap-server kafka:9092 --topic phield-pii-counts < counts.jsonl
In your own services, publish the same JSON with your Kafka client after each batch or on a fixed interval. PHIELD_API_KEY does not apply to the topic, so control who can write to it with Kafka’s own access controls.
The third message breaches the default percentage_delta threshold. A few seconds later, since the consumer reads in batches, Phield logs:
2026/12/01 17:54:05 [TREND BREACH] Source: claims-intake-worker, Organization: example-corp, Context: production, PII Type: ssn, Current: 27, Avg: 11.67, Increase: 131.43%
The average of 11.67 includes the count being judged: (4 + 4 + 27) / 3.
4. What PagerDuty receives
Phield posts each breach to https://events.pagerduty.com/v2/enqueue as a trigger event. The URL is fixed in Phield and cannot be changed. This is the body it sent, captured by pointing PagerDuty’s hostname at a local test server, since the URL cannot be configured:
{"event_action":"trigger","payload":{"severity":"critical","source":"phield","summary":"[TREND BREACH] Source: claims-intake-worker, Organization: example-corp, Context: production, PII Type: ssn, Current: 27, Avg: 11.67, Increase: 131.43%"},"routing_key":"0123456789abcdef0123456789abcdef"}
The Slack webhook received the same text as {"text": "..."}.
Plan for how these events behave in PagerDuty:
- The
summaryis the full breach line, so the incident title names the source, organization, context, PII type, and numbers. - Every event is a
triggerwith nodedup_key, and Phield never sends aresolve. Resolve the incident in PagerDuty once you have checked the source. - After an alert, the same series stays quiet for
PHIELD_COOLDOWN_MINUTES(default60), and the cooldown also ends early after three counts in a row back near the baseline. A sustained spike therefore pages at most once per cooldown, not once per message, and underpercentage_deltaa level that stays high lifts the average and can stop alerting altogether. - If PagerDuty cannot be reached or refuses the event, Phield prints
Notification error: ...and carries on with its other channels. It does not retry. - A muted context is not paged. See muting a context for planned changes.
5. What happens to a bad message
The consumer commits each message as it reads it, so delivery is at most once. A message that is not JSON, or that fails the same validation /ingest applies, is logged and skipped:
2026/12/01 17:54:14 Error unmarshaling Kafka message: invalid character 'o' in literal null (expecting 'u')
2026/12/01 17:54:14 Error processing Kafka ingest: source_id is required
The second line came from a message that used sourceId and piiCounts instead of source_id and pii_types. Unknown field names are ignored, so the message arrived with no source. Check the field names first when counts do not appear.
A skipped message is not retried. For counts that must not be lost, keep them on the producing side or send them to POST /ingest, which reports a failure to the caller.
To spread the load, run several Phield instances with the same PHIELD_KAFKA_GROUP_ID and a shared MongoDB, and give the topic at least as many partitions as instances. Instances with different group IDs would each read every message and count it twice in the shared baselines.
Phield reports how counts move. A page means something changed in that source, such as a new field carrying card numbers or a redaction step that stopped running. Check the source before you rely on the alert as the cause.