Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log graphql requests #526

Merged
merged 18 commits into from
Nov 5, 2024
Merged

feat: log graphql requests #526

merged 18 commits into from
Nov 5, 2024

Conversation

jsstevenson
Copy link
Contributor

@jsstevenson jsstevenson commented Oct 14, 2024

This PR does two things

  • Logs query types and variables for things that you type into the search bar, basically.
  • Logs the complete query and variables for requests made to the API endpoint NOT from the frontend client.

For example, the frontend logs look like:

# Logfile created on 2024-10-24 15:35:22 -0400 by logger.rb/v1.5.0
I, [2024-10-24T16:24:18.135312 #77300]  INFO -- : {:user_ip=>nil, :query_type=>"drugMatches", :query_variables=>{"searchTerms"=>["BRAF", "NTRK1", "NTRK2"]}}
I, [2024-10-24T16:24:25.670429 #77300]  INFO -- : {:user_ip=>nil, :query_type=>"drugMatches", :query_variables=>{"searchTerms"=>["IMATINIB"]}}

and the API logs look like

# Logfile created on 2024-10-24 15:35:22 -0400 by logger.rb/v1.5.0
I, [2024-10-24T16:20:56.239529 #76634]  INFO -- : {:user_ip=>nil, :query=>"query interaction($id: ID!) { interaction(id: $id) { gene { name conceptId } drug { name conceptId } interactionTypes { directionality type } interactionScore publications { id pmid citation } sources { fullName } interactionAttributes { name value } } }", :query_variables=>{"id"=>"a80d7cbb-d350-45c9-9800-6044db8dace0"}}
I, [2024-10-24T16:20:58.727886 #76634]  INFO -- : {:user_ip=>nil, :query=>"query gene($conceptId: String!) { gene(conceptId: $conceptId) { conceptId name geneAttributes { name value } geneAliases { alias } geneClaims { source { citation } } geneCategories { name } } }", :query_variables=>{"conceptId"=>"hgnc:3765"}}

Similarly, I was thinking it'd be nice to grab a reduced list of ambiguous results when those come up, but I haven't had a chance to look through the way to explore the query tree and I'm sort of supposed to get this thing shipped.

@jsstevenson jsstevenson marked this pull request as ready for review October 21, 2024 20:27
require 'net/http'

class SubmitAnalyticsEvent < ApplicationJob
# TODO not entirely sure what goes here
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

{
searchTerms: names,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to double check that it works as expected, but it looks like (based on this example here) you can set an HTTP Header when your initialize the graphql client.

That might be better than stapling it into each query individually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acoffman yeah, I was a little unsure of whether we wanted to set different headers for different queries and to filter out noisier or less informative ones. We should probably set a base one at client initialization and then maybe use an additional one for chosen queries if we go that route.

Copy link
Member

@acoffman acoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small things, but its looking good overall!

server/app/controllers/concerns/analytics.rb Outdated Show resolved Hide resolved
server/app/controllers/graphql_controller.rb Outdated Show resolved Hide resolved
server/app/lib/frontend_analytics_tracer.rb Show resolved Hide resolved
@jsstevenson jsstevenson requested a review from acoffman November 5, 2024 17:33
Copy link
Contributor

@mcannon068nw mcannon068nw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per our discussion, this looks to be capturing what we are intending for our research goals.

approved but I would also defer to @acoffman 's feedback on his earlier requested changes. If those look good, we should be good to go

Copy link
Member

@acoffman acoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor question, looks good overall!

def analyze_query(query: )
query_type = query.selected_operation.selections&.first&.name

return unless query_type == '__schema'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be inverted right? We skip analytics if it is an introspection query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, thanks, I always goof these

@jsstevenson jsstevenson requested a review from acoffman November 5, 2024 18:17
Copy link
Member

@acoffman acoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jsstevenson jsstevenson merged commit 174637f into dev Nov 5, 2024
3 checks passed
@jsstevenson jsstevenson deleted the graphql-logging branch November 5, 2024 18:30
mcannon068nw added a commit that referenced this pull request Dec 6, 2024
* feat: store score components in DB (#518)

* fix: update JAX-CKB URL (#521)

* feat: jax-ckb -> ckb-core (#522)

* fix: chembl version (#524)

* feat: define rake task to generate TSVs (#523)

* fix: remove redundant field (#527)

* build: remove some unused rails boilerplate/imports (#528)

* fix: use declared data version value (#525)

* fix: remove redundant code (#529)

* cicd: update actions revs (#530)

* feat: log graphql requests (#526)

* feat: log API client (#531)

* chore: remove unused readme (#532)

* fix: use docm snapshot data (#533)

* fix: update api uri (#538)

* cicd: add DB check script (#543)

* chore: fix a couple of typos/omissions (#541)

* fix: use latest GO api changes (#542)

* add rows for Download table for 2024 tsvs (#549)

* new row for old Downloads file

* added one more row

---------

Co-authored-by: Cannon <[email protected]>

---------

Co-authored-by: James Stevenson <[email protected]>
Co-authored-by: Cannon <[email protected]>
mcannon068nw added a commit that referenced this pull request Dec 6, 2024
* feat: store score components in DB (#518)

* fix: update JAX-CKB URL (#521)

* feat: jax-ckb -> ckb-core (#522)

* fix: chembl version (#524)

* feat: define rake task to generate TSVs (#523)

* fix: remove redundant field (#527)

* build: remove some unused rails boilerplate/imports (#528)

* fix: use declared data version value (#525)

* fix: remove redundant code (#529)

* cicd: update actions revs (#530)

* feat: log graphql requests (#526)

* feat: log API client (#531)

* chore: remove unused readme (#532)

* fix: use docm snapshot data (#533)

* fix: update api uri (#538)

* cicd: add DB check script (#543)

* chore: fix a couple of typos/omissions (#541)

* fix: use latest GO api changes (#542)

* add rows for Download table for 2024 tsvs (#549)

* new row for old Downloads file

* added one more row

---------

Co-authored-by: Cannon <[email protected]>

---------

Co-authored-by: James Stevenson <[email protected]>
Co-authored-by: Cannon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants