Skip to content

Commit

Permalink
Use custom params to record search params (#5434)
Browse files Browse the repository at this point in the history
* Use custom params to record search params

Previously, custom metrics was used. There are a couple reasons
why using custom parameters are better in this instance:
1) The parameters will be linked to a particular transaction which
    helps during debug.
2) The parameters allow recording of the actual value as opposed to
    simply whether it was used or not and in cases like offset that
    is an important distinction.
3) Since the params are linked to a particular transaction and we have
    info on who was logged in, we can get a better sense of which
    market segment is using which search features.

* Use es_ prefix on param names
  • Loading branch information
Hannah Stepanek committed Nov 30, 2018
1 parent e0792a5 commit 7ef0c63
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions h/views/api/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,32 @@ def _annotation_resource(request, annotation):

def _record_search_api_usage_metrics(
params,
record_metrics=newrelic.agent.record_custom_metrics,
record_param=newrelic.agent.add_custom_parameter,
):
metrics = [
# Record usage of deprecated offset.
('Custom/SearchApi/offset', int("offset" in params)),

# Record usage of search params and associate them with a transaction.
keys = [
# Record usage of inefficient offset and it's alternative search_after.
"offset",
"search_after",
"sort",
# Record usage of url/uri (url is an alias of uri).
('Custom/SearchApi/url', int("url" in params)),
('Custom/SearchApi/uri', int("uri" in params)),

"url",
"uri",
# Record usage of tags/tag (tags is an alias of tag).
('Custom/SearchApi/tags', int("tags" in params)),
('Custom/SearchApi/tag', int("tag" in params)),
"tags",
"tag",
# Record usage of _separate_replies which will help distinguish client calls
# for loading the sidebar annotations from other api calls.
"_separate_replies",
# Record group and user-these help in identifying slow queries.
"group",
"user",
# Record usage of wildcard feature.
"wildcard_uri",
]
record_metrics(metrics)

for k in keys:
if k in params:
# The New Relic Query Language does not permit _ at the begining
# and offset is a reserved key word.
record_param("es_{}".format(k), str(params[k]))

0 comments on commit 7ef0c63

Please sign in to comment.