logging for Webapps

Peter_R_Knight
Peter_R_Knight Registered Posts: 32 ✭✭✭✭
edited July 16 in Using Dataiku

I’ve written a Webapp that is published to a dashboard. I’d ideally like to be able to keep a log of who runs the web app, and some info about each run. Do you have any ideas how I can do this? I think it is fairly easy in python to get the user name (see below), but I’m assuming that the user who only has dashboard read permission won’t have permission to either append rows to a Greenplum table to store my logs in, or write to a file in a Dataiku folder? Any ideas much appreciated.

import dataiku
client = dataiku.api_client()
auth_info = client.get_auth_info()
print("User running this code is %s" % auth_info["authIdentifier"])

Thanks

Best Answer

  • fchataigner2
    fchataigner2 Dataiker Posts: 355 Dataiker
    edited July 17 Answer ✓

    in Bokeh it's true that it's much harder to get the connected user from their headers. If you're fine with using unsupported internal APIs, you can do

    # get the identifier of the webapp instance for bokeh
    session_id = curdoc().session_context.id
    # import the helper func from dataiku.webapps.run_bokeh import get_session_headers as get_bokeh_session_headers
    # grab the http headers at the time of the websocket creation h = get_bokeh_session_headers(session_id)
    # get the user from the headers, with the public API auth_info = dataiku.api_client().get_auth_info_from_browser_headers(h)

Answers

Setup Info
    Tags
      Help me…