logging for Webapps

Peter_R_Knight
Peter_R_Knight Registered Posts: 34 ✭✭✭✭
edited July 2024 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 2024 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

  • fchataigner2
    fchataigner2 Dataiker Posts: 355 Dataiker

    Hi,

    you can use get_auth_info_from_browser_headers() (see this sample ) to know which DSS user is making calls to the webapp. Since this will return the 'effective' user, you can run the webapp with a specific user that has access to greenplum using the 'run as' in the webapp's Settings

  • Peter_R_Knight
    Peter_R_Knight Registered Posts: 34 ✭✭✭✭

    Thanks for the input. I'm new to web apps and I'm actually doing a bokeh web app. Seems I don't have access to things like app? do you have any pointers?

    Thanks

  • CoreyS
    CoreyS Dataiker Alumni, Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Registered Posts: 1,149 ✭✭✭✭✭✭✭✭✭

    Hey @Peter_R_Knight
    since you are new to webapps, I just wanted to recommend this resource from the Dataiku Academy: Web Apps in Dataiku DSS tutorial. I hope this helps!

  • Peter_R_Knight
    Peter_R_Knight Registered Posts: 34 ✭✭✭✭

    Many thanks - that seems to be working.

Setup Info
    Tags
      Help me…