Logging

Errors in Siddhi can be handled at the Streams and in the Sinks. This example explains how errors are handled at Sink level.

There can be cases where external systems becoming unavailable or coursing errors when the events are published to them. By default sinks log and drop the events causing event losses, and this can be handled gracefully by configuring on.error parameter of the @sink annotation.

Refer the Siddhi query guide for more information.

define stream GlucoseReadingStream (locationRoom string,
    locationBed string, timeStamp string, sensorID long,
    patientFirstName string, patientLastName string,
    sensorValue double);

@sink(type = 'http', on.error='log',
    publisher.url = "http://localhost:8080/logger",
    method = "POST",
    @map(type = 'json'))
define stream AbnormalGlucoseReadingStream
    (timeStampInLong long, locationRoom string,
    locationBed string, sensorID long,
    patientFullName string, sensorReadingValue double);

@info(name='abnormal-reading-identifier')
from GlucoseReadingStream[sensorValue > 220]
select math:parseLong(timeStamp) as timeStampInLong,
    locationRoom, locationBed, sensorID,
    str:concat(patientFirstName, " ", patientLastName)
        as patientFullName,
        sensorValue as sensorReadingValue
insert into AbnormalGlucoseReadingStream;
define stream GlucoseReadingStream (locationRoom string,
    locationBed string, timeStamp string, sensorID long,
    patientFirstName string, patientLastName string,
    sensorValue double);

Defines GlucoseReadingStream stream which contains events related to Glucose readings.

@sink(type = 'http', on.error='log',
    publisher.url = "http://localhost:8080/logger",
    method = "POST",
    @map(type = 'json'))

If HTTP endpoint which defined in sink annotation is unavailable then it logs the event with the error and drops the event. Errors can be gracefully handled by configuring on.error parameter.

define stream AbnormalGlucoseReadingStream
    (timeStampInLong long, locationRoom string,
    locationBed string, sensorID long,
    patientFullName string, sensorReadingValue double);
@info(name='abnormal-reading-identifier')
from GlucoseReadingStream[sensorValue > 220]
select math:parseLong(timeStamp) as timeStampInLong,
    locationRoom, locationBed, sensorID,

Identifies the abnormal Glucose reading if sensorValue > 220

    str:concat(patientFirstName, " ", patientLastName)
        as patientFullName,

Concatenate string attributes patientFirstName and patientLastName

        sensorValue as sensorReadingValue
insert into AbnormalGlucoseReadingStream;

Above is a simple example to publish abnormal Glucose reading events to an unavailable HTTP endpoint and error is handled by logging the events to the logs.

Input

Below event is sent to GlucoseReadingStream stream,

['Get-1024', 'Level2', '1576829362', 10348, 'Alex', 'John', 250]

Output

After processing, the following log gets printed in the console:

ERROR {io.siddhi.core.stream.output.sink.Sink} - Error on 'ErrorHandling'. Dropping event at Sink 'http' at 'AbnormalGlucoseReadingStream' as its still trying to reconnect!, events dropped '{"event":{"timeStampInLong":1576829362,"locationRoom":"1024","locationBed":"Level2","sensorID":10348,"patientFullName":"Alex John","sensorReadingValue":250.0}}'

Top