Use error streams to monitor other streams for errors and the events that cause them.
CREATE ERROR STREAM AllErrors ON InputStream, DerivedStream1, DerivedStream2;
CREATE OUTPUT WINDOW errorHandlerAgg SCHEMA (errorNum integer, cnt long) PRIMARY KEY DEDUCED AS SELECT e.errorCode AS errorNum, COUNT(*) AS cnt FROM AllErrors e GROUP BY e.errorCode ;
CREATE OUTPUT ERROR STREAM vwapErrors ON DerivedStream3;
CREATE OUTPUT vwapMessages SCHEMA (errorNum integer, streamName string, errorRecord string) AS SELECT e.errorcode AS errorNum, e.streamName AS streamName, recordDataToString(e.sourceStreamName, e.errorRecord) AS errorRecord FROM vwapErrors e;
CREATE OUTPUT vwapMessages SCHEMA (errorNum integer, streamName string, errorRecord string) AS SELECT e.errorcode AS errorNum, e.streamName AS streamName, recordDataToRecord(e.sourceStreamName, e.errorRecord) AS errorRecord FROM vwapErrors e;