telemetry icon indicating copy to clipboard operation
telemetry copied to clipboard

Cleaner syntax for linking event schemas to event methods

Open Zsailer opened this issue 4 years ago • 2 comments

This is a syntax sugar. It adds a new decorator, event_schema, that can be called above a method to describe what telemetry data is collected by that method. This cleanly separates the telemetry definition logic from the application logic.

Before:

    def method_to_record(self):
        ...
        self.eventlog.record_event(
            schema_name="my_event",
            version=1,
            event=...
        )

After this PR:

    @event_schema(
        schema_name="my_event",
        version=1
    )
    def method_to_record(self):
        ...
        self.eventlog.record_event(event=...)

Normally, I don't think this kind of syntax sugar is necessary. In this case, though, it makes the code more readable. You can quickly scan through multiple methods to see which methods emit telemetry data and what data each method emits. No need to sift through the source code of the methods themselves.

This is fully backwards compatible. It's merely for readability.

Zsailer avatar Oct 09 '20 23:10 Zsailer

@kiendang, what do you think of this PR? (ignoring the linting errors for now 😆 )

Zsailer avatar Apr 28 '21 18:04 Zsailer

I like the syntax. Currently waiting until the jupyter_server PR get merged so we can test this with the events over there.

kiendang avatar Apr 29 '21 17:04 kiendang