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

Emit metrics about API calls #134

Open
iainmaitland88 opened this issue Jan 16, 2023 · 0 comments
Open

Emit metrics about API calls #134

iainmaitland88 opened this issue Jan 16, 2023 · 0 comments

Comments

@iainmaitland88
Copy link

iainmaitland88 commented Jan 16, 2023

Would you accept a PR that allowed users to pass a callback function or object to the Hubspot3 class allowing it to publish metrics? For example a simple counter of HTTP requests and response codes? Something along the lines of

# hubspot3.metrics or somewhere similar
class MetricsClient(Protocol):
    def counter(self, name: str, value: int, tags: Optional[dict[str, str | int | float]]):
        pass

# hubspot3.base
class BaseClient:
    def __init__(..., metrics_client: MetricsClient = None):
        self.metrics_client = metrics_client

    def _counter(self, name: str, value: int, tags: Optional[dict[str, str | int | float]]):
        if not self.metrics_client:
            return
        try:
            self.metrics_client.counter(name, value, tags)
        except Exception:
            logging.exception("something went wrong publishing a metric")

    def _execute_raw_request(self, conn, request):
        ...
        self._counter("endpoint", 1, {"http_status": 123})
        return result


# user code
class MyMetricsClient:
    def counter(self, name: str, value: int, tags: Optional[dict[str, str | int | float]]):
        # user implemented method to publish the metric somewhere

client = Hubspot3(access_token="blah", metrics_client=MyMetricsClient)

My motivation is using the new Private Apps there is no equivalent to /integrations/v1/limit/daily that shows your API usage. I've raised a feature request with HubSpot but I'm not hopeful.

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

No branches or pull requests

1 participant