Check out the first Dataiku 8 Deep Dive focusing on Productivity on October 29th Read More

logging for Webapps

Level 2
logging for Webapps

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

0 Kudos
5 Replies
Dataiker
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

0 Kudos
Level 2
Author

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

0 Kudos
Community Manager
Community Manager

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!

Don't forget to mark as "Accepted Solution" when someone provides the correct answer to your question.
0 Kudos

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)
Level 2
Author

Many thanks - that seems to be working.

0 Kudos