docs/design/features/raw-eventlistener.md
The goal of this design document is to describe what a Raw EventListener API will look like and how it will work.
A raw API is one that dispatches events, but does not decode the data payload. It simply provides a raw blob and a metadata blob that can be used to interpret the data when desired.
The existing EventListener API usage pattern is to:
The proposed extension of this pattern is the following:
[Flags]
public enum EventListenerSettings
{
None,
RawEventDispatch
}
This parameter is used to specify the desired dispatch behavior (in this case, do not deserialize event payloads).
The new raw dispatch API will be:
public void OnEventWrittenRaw(RawEventWrittenEventArgs args);
public sealed class RawEventWrittenEventArgs
{
// Event metadata copied from EventWrittenEventArgs (for consistency).
public string EventName { get; }
public int EventId { get; }
public Guid ActivityId { get; }
public Guid RelatedActivityId { get; }
public EventSource EventSource { get; }
public EventKeywords Keywords { get; }
public EventOpcode Opcode { get; }
public EventTask Task { get; }
public EventTags Tags { get; }
public string Message { get; }
public byte Version { get; }
public EventLevel Level { get; }
public long OSThreadId { get; }
public DateTime TimeStamp { get; }
// Replacement properties for Payload and PayloadNames.
public ReadOnlySpan<byte> Metadata { get; }
public ReadOnlySpan<byte> Payload { get; }
}
The lifetime of the RawEventWrittenEventArgs object will be the lifetime of the callback. Thus, we can recycle the object and reduce the overhead of this API. This is similar to how TraceEvent works today, but is different than the existing EventListener.OnEventWritten callback.
NOTE: Until the API becomes public, testing can be performed by reflection using the following steps:
It is possible that due to this reflection requirement, some calls to the deserialized payload API will be made until EventListener discovers that this is no longer needed. This will occur if setting the flag from the constructor. This can be worked around by setting the flag from OnEventSourceCreated prior to calling EnableEvents.
As of today, when an EventListener subscribes to an event, this is the determining factor on whether or not the event data is deserialized and the event dispatched.
The following changes will be needed to support raw dispatch: