Skip to content

Commit 7899fce

Browse files
feature: added datadog integration for send metrics
1 parent 18ed7d2 commit 7899fce

File tree

7 files changed

+67
-18
lines changed

7 files changed

+67
-18
lines changed

.idea/api-to-dataframe.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ repos:
55
- id: check-yaml
66
- id: trailing-whitespace
77

8-
- repo: local
9-
hooks:
10-
- id: pylint
11-
name: pylint
12-
entry: pylint
13-
language: system
14-
types: [python]
15-
args:
16-
[
17-
"-rn", # Only display messages
18-
"--disable=C0114,C0115,C0116, R0903",
19-
]
8+
# - repo: local
9+
# hooks:
10+
# - id: pylint
11+
# name: pylint
12+
# entry: pylint
13+
# language: system
14+
# types: [python]
15+
# args:
16+
# [
17+
# "-rn", # Only display messages
18+
# "--disable=C0114,C0115,C0116, R0903",
19+
# ]
2020

2121
# - repo: local
2222
# hooks:

poetry.lock

+17-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "api-to-dataframe"
3-
version = "1.3.11"
3+
version = "1.3.12"
44
description = "A package to convert API responses to pandas dataframe"
55
authors = ["IvanildoBarauna <[email protected]>"]
66
readme = "README.md"
@@ -27,6 +27,7 @@ python = "^3.9"
2727
pandas = "^2.2.3"
2828
requests = "^2.32.3"
2929
logging = "^0.4.9.6"
30+
datadog = "^0.50.2"
3031

3132
[tool.poetry.group.dev.dependencies]
3233
poetry-dynamic-versioning = "^1.3.0"

src/api_to_dataframe/controller/client_builder.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from api_to_dataframe.models.retainer import retry_strategies, Strategies
22
from api_to_dataframe.models.get_data import GetData
33
from api_to_dataframe.utils.logger import log, LogLevel
4+
from api_to_dataframe.utils.metrics import MetricsClient
45

56

67
class ClientBuilder:
@@ -52,6 +53,10 @@ def __init__( # pylint: disable=too-many-positional-arguments,too-many-argument
5253
self.headers = headers
5354
self.retries = retries
5455
self.delay = initial_delay
56+
self.metrics_client = MetricsClient()
57+
58+
self.metrics_client.increment("builded_client")
59+
5560

5661
@retry_strategies
5762
def get_api_data(self):
@@ -65,12 +70,18 @@ def get_api_data(self):
6570
Returns:
6671
dict: The JSON response from the API as a dictionary.
6772
"""
73+
74+
self.metrics_client.increment("get_api_data_attempt")
75+
6876
response = GetData.get_response(
6977
endpoint=self.endpoint,
7078
headers=self.headers,
7179
connection_timeout=self.connection_timeout,
7280
)
7381

82+
83+
self.metrics_client.increment("get_api_data_success")
84+
7485
return response.json()
7586

7687
@staticmethod
@@ -88,5 +99,9 @@ def api_to_dataframe(response: dict):
8899
Returns:
89100
DataFrame: A pandas DataFrame containing the data from the API response.
90101
"""
102+
MetricsClient().increment("api_to_dataframe_attempt")
103+
91104
df = GetData.to_dataframe(response)
105+
106+
MetricsClient().increment("api_to_dataframe_success")
92107
return df

src/api_to_dataframe/utils/metrics.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from datadog import initialize, statsd
2+
3+
4+
class MetricsClient:
5+
def __init__(self) -> None:
6+
self.options = options = {
7+
"statsd_host": "node-metrics-ba28.ivanildobarauna.dev",
8+
"statsd_port": 8125,
9+
}
10+
self.client = initialize(**options)
11+
self.application_name = "api-to-dataframe"
12+
13+
def increment(
14+
self, action: str, tags: list[str] = ["env:production"], value: float = 1.0
15+
):
16+
17+
tags.append(f"action:{action}")
18+
19+
statsd.increment(metric=self.application_name, tags=tags, value=value)

0 commit comments

Comments
 (0)