Skip to content

Commit

Permalink
Add analytics
Browse files Browse the repository at this point in the history
Closes #691
  • Loading branch information
cthoyt committed Jun 8, 2023
1 parent a466eb2 commit 03c76a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ web =
bootstrap-flask<=2.0.0
markdown
curies[fastapi]
api-analytics

[options.entry_points]
console_scripts =
Expand Down
9 changes: 9 additions & 0 deletions src/bioregistry/app/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from textwrap import dedent
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

import pystow
from curies.mapping_service import MappingServiceGraph, MappingServiceSPARQLProcessor
from fastapi import APIRouter, FastAPI
from flask import Flask
Expand Down Expand Up @@ -186,6 +187,14 @@ def get_app(
fast_api.include_router(_get_sparql_router(app))
fast_api.mount("/", WSGIMiddleware(app))

analytics_api_key = conf.get("ANALYTICS_API_KEY") or pystow.get_config(
"bioregistry", "analytics_api_key"
)
if analytics_api_key:
from api_analytics.fastapi import Analytics

fast_api.add_middleware(Analytics, api_key=analytics_api_key) # Add middleware

# Make manager available in all jinja templates
app.jinja_env.globals.update(
manager=manager,
Expand Down

0 comments on commit 03c76a1

Please sign in to comment.