Events and the Secondary Event Provider¶
KnowledgeLake records an event for almost everything that happens on a tenant: a step starts and stops, a work item completes or errors, a user signs in, an administrator changes a content type, an API call succeeds or fails. A Secondary Event Provider sends a copy of those events to a database you own, an Azure Cosmos DB account or an Elastic index, so you can build your own reports, dashboards, audit trails and alerts on them.
This page explains what an event is, how to set up a provider, what arrives and in what shape, and the delivery limits you must design for.
At a glance
- Runs Inside the platform. Every service writes events through one router; the router copies them to each provider whose filter lets them through
- Delivers to Your own Azure Cosmos DB (SQL API) database or Elastic index. These are the only two provider types
- Configured in Configuration > Apps > Event Settings, with the permission Manage Event Settings
- Delivery Best effort, asynchronous, at most once. KnowledgeLake never reads back, deletes or expires what it sends
- Best for Volume and throughput dashboards, step timing, error alerts, AI token usage, sign-in and configuration audit, and your own business events from the Custom Event step
How events flow¶
graph TD
A["Apps: Index, Upload, Search, Monitor, Security, API"] --> R["Event router"]
W["Workflow worker"] --> R
J["Legacy worker and scheduled Jobs"] --> R
C["Content Services and Bot Service"] --> R
R --> P["KnowledgeLake primary stores: Monitor, Insight, history"]
R --> F{"Provider filter: scopes start with a ticked category?"}
F -->|"yes"| Q["In-memory queue, one per provider"]
Q --> D["Your Cosmos DB or Elastic"]
F -->|"no"| X["Dropped for this provider"]
Each service decides first which events it forwards to secondary providers at all (see Known limitations below). Then each provider's filter decides which of those it keeps. A provider receives an event only when both say yes.
What an event is¶
An event is a small record: an id, a time, the work item, workflow and step it belongs to (when it has one), the acting user (when there is one), and a bag of string properties.
An event is named by its scopes. There is no single event-name field. Scopes is an ordered list of strings, most general first. The first scope is the source (apps, KWorker, processing, custom, contentServices, botServices). Treat the whole list as the event's identity:
In this documentation an event is written as its scopes joined with commas, for example KWorker, AddHold, Completed. The Events Dictionary lists every event by its scopes.
The platform derives two fields from the scopes:
IndexedEventStatusbecomes Error when a scope is exactlyerror(lowercase).IndexedEventTypebecomes Start or Stop when a scope is exactlystartorstop. A start event and its stop event share oneEventId.
Set up a provider¶
You need the permission Manage Event Settings ("Allows a user to manage event settings."). Prepare the target first.
- In Azure, create a Cosmos DB account with the SQL API (NoSQL).
- Create a database. In it, create a container named exactly
Eventswith partition key/PartitionKey. The name is fixed. - Copy the account URI, a read-write key, and the database name.
The wizard asks for Host (the account URI), Read Write Password (the account key) and Database Name. Test Connection checks that a database with that name exists.
- Create an Elastic cluster and an index. The index name must be lowercase, at most 255 bytes, must not be
.or.., must not start with-,_,+or., and must not contain\ / * ? " < > | , #or a space. - Create a user with write access to the index.
The wizard asks for Host (the cluster URL), Index, User and Password (basic authentication). Test Connection pings the cluster. On startup the provider creates the index with a mapping if it does not exist, or applies the mapping if it does. The saved password is never shown again.
Then add the provider:
- Go to Configuration > Apps > Event Settings. The page heading is "Event Settings", sub heading "Secondary Event Provider".
- Select Add a Secondary Event Provider.
- Welcome: enter a provider name (the "Identifier"; it must be unique) and pick the type.
- Configure: enter the connection settings and select Test Connection. Save runs the test again and saves only when it passes.
- Filter Events: "Select the events you would like stored in the Self-Hosted Secondary Events Provider." Every category is ticked by default. Untick what you do not want.
A tenant can have more than one provider, each with its own name and filter. To change one, edit it (the wizard opens at Configure). To remove one, delete it. A save takes effect in every service without a restart.
The filter is saved at the Configure step
If you leave the wizard after Configure, the provider is saved with every category ticked. Open it again if you meant to narrow the filter.
The filter¶
Each provider keeps a list of scope prefixes, one or two per category. An event passes when its scopes start with one of the ticked prefixes, compared exactly and case-sensitively. An empty list blocks everything.
| Category in the wizard | Scope prefix |
|---|---|
| API | apps, openapi |
| Applications > Configuration | apps, configuration |
| Applications > Connections | apps, taxonomy |
| Applications > Designer | apps, processdesigner |
| Applications > Index | apps, webindex |
| Applications > Jobs | apps, jobs |
| Applications > Learn | apps, assist and apps, learn |
| Applications > Manage | apps, ContentServices |
| Applications > Monitor | apps, monitor |
| Applications > Portal | apps, Portal |
| Applications > RPA | apps, attendedautomation and apps, automation |
| Applications > Scan | apps, webcapture |
| Applications > Search | apps, search |
| Applications > Security | apps, security |
| Applications > Upload | apps, upload |
| Applications > View | apps, view |
| Applications > Workflow | apps, trigger and apps, workflow |
| Batch Service | batch |
| Bot Service | botServices |
| Content Services | contentServices |
| Custom | custom |
| Management Service | management |
| Processing | processing |
| Tasks Service | interactions |
| Workflow | KWorker |
Known limitations¶
Watch out
Some events never reach a provider set up in the UI, even with every category ticked. Plan your reports around these gaps, and check the Events Dictionary entry before you depend on an event.
- No category Events whose scopes start with
apps, insight(Insight dashboards and work item actions in Insight),apps, interactions(Tasks app deletes and task assignment),apps, intuitiveaiandapps, advancedcapture(the class builders),apps, botServices(attended automation consumption),Portal(Portal administration), anderror(Intuitive AI engine error events from workflow steps). No category covers them. - Case differs Monitor RPA job actions are written as
apps, Monitor, Rpa, ...(capital M), and upload profile changes and automatic file-type restriction removals asapps, Configuration, ...(capital C). The filter compares case, so the Monitor and Configuration categories do not match them. - Write Event API
V1_EventsAPI/WriteEventwrites scopes that start withopenapi, notapps, openapi, so the API category does not match them. To put your own events in your provider, use the Custom Event step. - Tasks service It does not forward. Task created, task completed, hold released by a task, and task purge events stay in KnowledgeLake's own store. The Tasks Service category receives nothing.
- Failed operations Failed repository operations are not stored. Content Services sends an audit event for each successful document operation, but a failed or denied operation is not stored anywhere.
- Empty categories The Batch Service and Management Service categories receive nothing.
- Legacy worker Work run by the legacy worker (Process Designer processes) forwards only its start, stop, error and update events and job events. A Custom Event step on the legacy worker writes nothing to a provider.
- Not audited Adding or editing a provider, and changing its filter, writes no event. Removing a provider writes
apps, configuration, RemoveEventProviderSettings.
What arrives: the event document¶
The two provider types store different shapes of the same event.
{
"Id": "5b0c9e2a-...",
"EventId": "c1f27d40-...",
"PartitionKey": "c1f27d40-...",
"ParentEventId": null,
"SubscriptionId": "<tenant subscription id>",
"Scopes": ["KWorker", "RunStep"],
"OccurredTime": 1791380000000,
"Timestamp": "2026-10-07T14:13:20Z",
"IndexedEventType": 2,
"IndexedEventStatus": 0,
"DurationMs": 1840,
"AppsUserToken": null,
"MachineId": "kworker-7d9f...",
"WorkItemId": "<work item id>",
"WorkItemRootId": "<root work item id>",
"ProcessId": "<workflow id>",
"ProcessVersion": 12,
"StepId": "<step id>",
"WorkType": "Index Your Documents",
"Properties": { },
"LongProperties": null,
"DoubleProperties": null,
"BoolProperties": null
}
| Field | Meaning |
|---|---|
Id |
A new GUID for each document |
PartitionKey |
The EventId as text |
EventId |
The event's GUID. A start event and its stop event share it |
ParentEventId |
The enclosing event, when one exists. Not guaranteed; do not build on it |
SubscriptionId |
Your tenant's subscription id. Cosmos only |
Timestamp |
The event time as a UTC date-time. Cosmos only |
OccurredTime |
Unix time in milliseconds, UTC. Sort by it |
IndexedEventType |
Standalone 0, Start 1, Stop 2 |
IndexedEventStatus |
Event 0, Verbose 1, Warning 2, Error 3 |
DurationMs |
Set on stop events and on API call events |
AppsUserToken |
The acting user's identity token, when there is one. Workflow steps have none |
MachineId |
The server or pod that wrote the event |
WorkItemId, WorkItemRootId, ProcessId, ProcessVersion, StepId, WorkType |
The work item, the root work item of a split, the workflow and version, the step and its step type |
Properties |
The string properties, key to text |
LongProperties, DoubleProperties, BoolProperties |
Typed properties that a few workflow events use |
The two enum fields (IndexedEventType, IndexedEventStatus) are written as numbers; confirm on one live document before you build on them.
The Elastic provider indexes the event record itself, not the Cosmos shape:
- The property bag is
StringProperties, notProperties. - There is no
Id,PartitionKey,SubscriptionIdorTimestamp. UseOccurredTime. TTLandWorkItemStateare included.- Field name casing and the format of the two enum fields follow the Elastic client's defaults. They were not confirmed for this page. Check one document in your index (for example in Kibana Discover) before you build a dashboard on field names.
Delivery behavior¶
Design for loss, duplicates within a key, and disorder.
- At most once Best effort. Each provider in each service process has an in-memory queue and one background writer. Nothing is written to disk before the provider accepts the event.
- Lost on stop Events still in the queue when a process stops or restarts are lost. The writer gets up to 5 seconds to drain.
- Cosmos DB retries once. On a failed write the writer waits 5 seconds and tries once more. If that fails, the event is logged as missed and dropped. A failure never stops the product.
- Elastic retries none. A write that throws is logged and dropped. A document that Elastic rejects without an exception (for example a mapping conflict) is dropped with no log.
- Trimming Above 1.5 MB (Cosmos DB only). If an event document is larger than 1.5 MB, every string property is cut to its first 5000 characters and
Properties.eventWasTrimmedis set to"true". - Order No global order. Events come from many processes. Sort by
OccurredTime. Pair start and stop events byEventId. - Unique key Start and stop share
EventId, so key a row onEventIdplusIndexedEventType. - Batching No batching or delay in the platform. Events are sent as fast as the writer can write.
- Retention yours. KnowledgeLake never deletes or expires events in your store. Set a TTL or an index lifecycle policy.
Some events are high volume: contentServices, audit, Search and GetRecordById, apps, webindex, workitem, batch, update, KeepBatchAlive (a heartbeat while a user has a work item open), and the apps, openapi, invoke, ... API audit events. Untick categories you do not need, and size your store for what is left.
Treat the store as sensitive
Some properties carry configuration as sent: job scriptBlock and job parameters, identity catalog parameterList and settings, upload profile JSON, Portal email template bodies, and full exception text. A job parameter that holds a credential is written into the event. Restrict access to your Cosmos DB account or Elastic index the way you restrict the tenant's configuration.
Query your events¶
Step failures in the last day (stop events with status Error):
SELECT c.Timestamp, c.WorkItemId, c.ProcessId, c.WorkType, c.Properties.error
FROM c
WHERE c.Scopes[0] = "KWorker" AND c.Scopes[1] = "RunStep"
AND c.IndexedEventType = 2 AND c.IndexedEventStatus = 3
AND c.OccurredTime >= @since
Work items completed per workflow:
SELECT c.ProcessId, COUNT(1) AS completed
FROM c
WHERE c.Scopes[0] = "KWorker" AND c.Scopes[1] = "AddHold" AND c.Scopes[2] = "Completed"
AND c.OccurredTime >= @since
GROUP BY c.ProcessId
Intuitive AI token usage per model. Values are strings, so cast them. Zero-shot classification calls carry model; Auto Extraction calls carry instance instead:
Failed steps. The field names here assume the Elastic client's default camel case (scopes, indexedEventType, occurredTime); check one document in your index and adjust.
Your own events¶
Two ways to write your own events exist. Only one reaches a UI-configured provider:
- Custom Event step Writes
custom, <your scopes>with the properties your script sets, from inside a workflow. It passes the Custom category. See Custom Event step. - Write Event API
V1_EventsAPI/WriteEventwritesopenapi, <your scopes>. No category matchesopenapi, so these events do not reach a provider set up in the UI (see Known limitations above).
Copy this into your assistant¶
Paste the block below into your AI assistant together with the AI Assistant Primer, then describe the query, dashboard feed or alert you want. It is the same contract as this page, written for a model.
# KnowledgeLake events: context for AI assistants
You write code or queries that consume KnowledgeLake platform events from the customer's own
store: an Azure Cosmos DB (SQL API) container named "Events", or an Elastic index. KnowledgeLake
writes to the store; it never reads, deletes or expires anything there. Produce queries, dashboard
feeds, or alert functions (for example an Azure Function on the Cosmos change feed, or an Elastic
watcher). Use only the fields and event names in this block or in event entries the user pastes.
## Event identity
- An event is named by its Scopes array (ordered strings, most general first). There is no name
field. Match on scope positions: Scopes[0] = source ("KWorker", "apps", "processing", "custom",
"contentServices", "botServices"), then the rest.
- Scope matching is case-sensitive. Some events use odd casing: "apps, Monitor, Rpa, ...",
"apps, Configuration, ...". Copy scopes exactly from the user's event list.
## Cosmos DB document (PascalCase)
Id (new GUID per document), EventId (GUID; start and stop share it), PartitionKey (EventId text),
ParentEventId (unreliable), SubscriptionId (tenant), Scopes (string[]), OccurredTime (Unix ms
UTC), Timestamp (UTC date-time), IndexedEventType (0 Standalone, 1 Start, 2 Stop),
IndexedEventStatus (0 Event, 1 Verbose, 2 Warning, 3 Error), DurationMs (stop and API events),
AppsUserToken (acting user, or null), MachineId, WorkItemId, WorkItemRootId, ProcessId,
ProcessVersion, StepId, WorkType (step type name), Properties (string to string),
LongProperties, DoubleProperties, BoolProperties (typed, rarely used).
## Elastic document
The event record itself: property bag is StringProperties (not Properties); no Id, PartitionKey,
SubscriptionId or Timestamp; field casing follows the Elastic client defaults and is not
confirmed. Ask the user to paste one real document before you write field names.
## Rules
1. Every property value is a string. Cast in the query (Cosmos: StringToNumber, or compare text).
2. Sort by OccurredTime. Global order is not guaranteed.
3. Pair start and stop events by EventId. A unique row key is EventId + IndexedEventType.
4. Delivery is best effort: events can be lost (process restart, write failure). Never treat a
missing event as proof that something did not happen. For counts that must be exact, reconcile
with the KnowledgeLake API.
5. A Cosmos document over 1.5 MB has every string property cut to 5000 characters and
Properties.eventWasTrimmed = "true". Check it before parsing a JSON property.
6. Filter on Scopes, not on IndexedEventStatus alone: "KWorker, AddHold, Error" keeps status Event.
7. The store can hold sensitive values (job parameters, configuration JSON, exception text). Never
copy whole property bags into alerts or chat messages; pick the fields you need.
8. Set retention yourself (Cosmos TTL, Elastic lifecycle policy).
## Events most consumers use (Cosmos scope positions)
- Step start/stop: ["KWorker","RunStep"]; stop has DurationMs; failure: IndexedEventStatus 3 and
Properties.error.
- Work item left the queue: ["KWorker","AddHold",status] with status "Hold", "Completed"
(workflow finished), "Error" (work item errored) or "Stopped".
- Route chosen: ["KWorker","RouteTaken"] with Properties.routeName, routeId, nextStepId.
- Document released: ["KWorker","update","Upload To Destination"] with documentId, documentUrl,
contentTypeName, connectorName.
- OCR done: ["KWorker","update","ExtractText"] with ocrdPageCount, ocrEngine.
- Document classified: ["KWorker","update","Classification Completed"] with className,
subclassName, classificationConfidence.
- LLM usage: ["KWorker","workitem","step","AIUsage"] with usage, model or instance,
promptTokens, completionTokens, totalTokens (strings).
- Upload: ["apps","upload","workitem","add","Upload"] with numDocuments, numPages.
- Scan import: ["apps","webcapture","consumption","RecordFileProcessingData"] with numImportedPages.
- Sign-in: ["apps","security","login","LoginWithUsernameAndPassword"] or "LoginUsingOAuth";
failure has "exception" inserted before the last scope.
- API call: ["apps","openapi","invoke","success"|"error",method] with tokenName, methodName.
- Job run: ["processing","job","start"|"stop"|"error","ExecuteJob"] with jobDisplayName,
jobInstanceID, exception on error.
- RPA job finished: ["botServices","consumption","finishBotAutomation"] with RPATaskId, Status.
- Your own events: ["custom", ...your scopes] with the properties the Custom Event script set.
## Not delivered (do not build on these)
apps, insight; apps, interactions; apps, intuitiveai; apps, advancedcapture; apps, botServices;
apps, Monitor (capital M); apps, Configuration (capital C); Portal; error (engine errors);
openapi (Write Event API); Tasks service events; failed Content Services operations.
## Example: Cosmos SQL, average step time per step type, last 24 hours
```sql
SELECT c.WorkType, AVG(c.DurationMs) AS avgMs, COUNT(1) AS runs
FROM c
WHERE c.Scopes[0] = "KWorker" AND c.Scopes[1] = "RunStep" AND c.IndexedEventType = 2
AND c.OccurredTime >= @since
GROUP BY c.WorkType
```
## Output
Produce the query or function, the parameters it needs (@since as Unix ms), and a "Test it" list.
Ask the user for the provider type, the database or index name, and one sample document if field
names matter. Do not guess scope names: ask for the Events Dictionary entry.
Related¶
- Events Dictionary: every event, its scopes, properties and whether it arrives.
- Custom Event step: write your own business events.
- Jobs, RPA and Monitoring API: query jobs and RPA tasks directly.
- Error message index