logging for Webapps

Solved!
Peter_R_Knight
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
1 Solution
fchataigner2
Dataiker

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)

View solution in original post

5 Replies
fchataigner2
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
Peter_R_Knight
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
CoreyS
Dataiker Alumni

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!

Looking for more resources to help you use Dataiku effectively and upskill your knowledge? Check out these great resources: Dataiku Academy | Documentation | Knowledge Base

A reply answered your question? Mark as ‘Accepted Solution’ to help others like you!
0 Kudos
fchataigner2
Dataiker

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

Many thanks - that seems to be working.

0 Kudos

Labels

?
Labels (4)
A banner prompting to get Dataiku