Skip to content

Commit e4a6af9

Browse files
committed
feat(v3): ✨ Add custom fields in message
1 parent 62b0608 commit e4a6af9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

usagelogger/http_logger.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22
# © 2016-2021 Resurface Labs Inc.
3-
from typing import List, Optional
3+
from typing import Dict, List, Optional
44

55
from .base_logger import BaseLogger
66
from .http_rules import HttpRules
@@ -60,12 +60,24 @@ def __init__(
6060
def rules(self) -> HttpRules:
6161
return self._rules
6262

63-
def submit_if_passing(self, details: List[List[str]]) -> None:
63+
def submit_if_passing(
64+
self, details: List[List[str]], custom_fields: Optional[Dict[str, str]]
65+
) -> None:
6466
# apply active rules
6567
details = self._rules.apply(details) # type: ignore
6668
if details is None:
6769
return
6870

71+
# add custom fields
72+
if custom_fields:
73+
details.extend(
74+
[
75+
[k, v]
76+
for k, v in custom_fields.items()
77+
if k not in [k for k, v in details]
78+
]
79+
)
80+
6981
# finalize message
7082
details.append(["host", self.host])
7183

usagelogger/http_message.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# © 2016-2021 Resurface Labs Inc.
33
from re import match
44
from time import time
5-
from typing import List, Optional
5+
from typing import Dict, List, Optional
66
from urllib import parse
77

88
from .http_logger import HttpLogger
@@ -19,6 +19,7 @@ def send(
1919
request_body: Optional[str] = None,
2020
now=None,
2121
interval=None,
22+
custom_fields: Optional[Dict[str, str]] = None,
2223
) -> None:
2324

2425
if not logger.enabled:
@@ -50,7 +51,7 @@ def send(
5051
if interval is not None:
5152
message.append(["interval", interval])
5253

53-
logger.submit_if_passing(message)
54+
logger.submit_if_passing(message, custom_fields)
5455

5556
@classmethod
5657
def build( # noqa: C901

0 commit comments

Comments
 (0)