Skip to content

Commit

Permalink
Move telemetry out to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-turner-1 committed Dec 23, 2024
1 parent 940042b commit 20e958e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 115 deletions.
1 change: 0 additions & 1 deletion ci/environment-3.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
- pre-commit
- pytest
- xarray
- ipython
- pip
- pip:
- codecov
Expand Down
1 change: 0 additions & 1 deletion ci/environment-3.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
- pre-commit
- pytest
- xarray
- ipython
- pip
- pip:
- codecov
Expand Down
1 change: 0 additions & 1 deletion ci/environment-3.12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
- pre-commit
- pytest
- xarray
- ipython
- pip
- pip:
- codecov
Expand Down
1 change: 0 additions & 1 deletion ci/environment-3.13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
- pre-commit
- pytest
- xarray
- ipython
- pip
- pip:
- codecov
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = [
"jsonschema",
"pooch",
"xarray",
"httpx>=0.28"
"access-ipy-telemetry>=0.1.0",
]
dynamic = ["version"]

Expand Down
26 changes: 8 additions & 18 deletions src/access_nri_intake/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,25 @@

import intake
import intake.catalog
from IPython import get_ipython
from IPython.core.magic import register_line_magic
from access_ipy_telemetry.cli import configure_telemetry
from access_ipy_telemetry.utils import ApiHandler

from access_nri_intake.utils import get_catalog_fp

from .telemetry import capture_datastore_searches
api_handler = ApiHandler()

CATALOG_NAME_FORMAT = (
r"^v(?P<yr>2[0-9]{3})\-(?P<mon>1[0-2]|0[1-9])\-(?P<day>0[1-9]|[1-2][0-9]|3[0-1])$"
)


def load_ipython_extension(ipython):
@register_line_magic("capture_func_calls")
def capture_func_calls(info):
"""
Returns the function calls from the code in the cell
"""
ipython.events.register("pre_run_cell", capture_datastore_searches)


# Register the extension
ip = get_ipython()
if ip:
load_ipython_extension(ip)
ip.run_line_magic("capture_func_calls", "")

try:
data = intake.open_catalog(get_catalog_fp()).access_nri
cat_version = data._captured_init_kwargs.get("metadata", {}).get(
"version", "latest"
) # Get the catalog version number and set it to "latest" if it can't be found
configure_telemetry(["--enable", "--silent"])
api_handler.add_extra_field("catalog", {"catalog_version": cat_version})
except FileNotFoundError:
warnings.warn(
"Unable to access a default catalog location. Calling intake.cat.access_nri will not work.",
Expand Down
92 changes: 0 additions & 92 deletions src/access_nri_intake/data/telemetry.py

This file was deleted.

0 comments on commit 20e958e

Please sign in to comment.