Logging interactions / telemetry with front end jupyter lab extension

I have a front end extension for jupyter lab. I want to log user interactions such as when they open or close the extension. I have been able to capture these events but right now just print out the logs to the browser console. Is it possible to integrate with Jupyter’s telemetry system to save logs to a file somewhere?

I saw these repos with examples on how to do so from Python (GitHub - jupyter/telemetry: Configurable event-logging for Jupyter applications and extensions.) however my extension is a javascript extension

1 Like

The reboot of that effort is jupyter_events, and is already available inside recent jupyter_server versions.

It exposes POST /api/events, but an extension may have to define an event schema on the server, for example with a server extension, but likely wouldn’t need a new handler for the extension itself.

Being able to define those in well-known location on disk without building a serverextension would be lovely, e.g. through traitlets, or just putting them someplace.

2 Likes

Thanks for the reply! So just to make sure I’m understanding, I can make a post request from my lab extension to “/api/events” and then may have to use an event schema or server extension to handle this event and save to a logs file?

Do there happen to be any examples of doing this? Or saving logs from a front end extension in any other way. For example I think I need to authenticate my post request from my extension but not sure where to get the information for the header?

Part of the reason I am trying to save my extension logs through Jupyter is that we use an organization-wide Jupyter Hub instance and logging to an external site like google analytics isnt feasible. I’m hoping that whenever a user on the Jupyter Hub instance uses my extension I can write the logs to a common file on the server somewhere

make a post request from my lab extension

Yep.

use an event schema or server extension

Use a server extension to register the event schema, as described in docs. There are some core data fields but just very metadata-ish: timestamps and schema id, etc.

need to authenticate my post request from my extension

Since it’s talking to the jupyter server, this is all taken care of:

import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { ServerConnection } from '@jupyterlab/services';

// ... somewhere after `activate`
  const url = URLExt.join(PageConfig.getBaseUrl(), 'api/events');
  const {serverSettings} = app.serviceManager;
  const evt = {event: 'that conforms to', a: 'schema'};
  const response = await ServerConnection.makeRequest(url, evt, serverSettings);

Jupyter Hub instance

That’s a whole other ball of wax. I don’t know what integrations exist. If you go down the serverextension route, you can use that to subscribe to your events.