-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow configuring a dedicated metrics logger (#978)
Co-authored-by: Aaron ("AJ") Steers <[email protected]>
- Loading branch information
1 parent
3c8e213
commit 6d74490
Showing
12 changed files
with
744 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,49 @@ | ||
# Logging | ||
|
||
Logs are configurable by the environment variables `<PLUGIN_NAME>_LOGLEVEL` (preferred) or `LOGLEVEL`. Use `LOGLEVEL` when you intend to control the log output for all taps and targets running within the environment. In contrast, we recommend setting `<PLUGIN_NAME>_LOGLEVEL` for more granual control of each tap or target individually. | ||
Logs are configurable by the environment variables `<PLUGIN_NAME>_LOGLEVEL` (preferred) | ||
or `LOGLEVEL`. Use `LOGLEVEL` when you intend to control the log output for all taps | ||
and targets running within the environment. In contrast, we recommend setting | ||
`<PLUGIN_NAME>_LOGLEVEL` for more granual control of each tap or target individually. | ||
|
||
From most verbose to least verbose, the accepted values for logging level are `debug`, `info`, `warning`, and `error`. Logging level inputs are case insensitive. | ||
From most verbose to least verbose, the accepted values for logging level are `debug`, | ||
`info`, `warning`, and `error`. Logging level inputs are case-insensitive. | ||
|
||
## Custom logging configuration | ||
|
||
Users of a tap can configure the SDK logging by setting the `SINGER_SDK_LOG_CONFIG` | ||
environment variable. The value of this variable should be a path to a YAML file in the | ||
[Python logging dict format](https://docs.python.org/3/library/logging.config.html#dictionary-schema-details). | ||
|
||
For example, to send [metrics](./metrics.md) (with logger name `singer_sdk.metrics`) to a file, you could use the following config: | ||
|
||
```yaml | ||
version: 1 | ||
disable_existing_loggers: false | ||
formatters: | ||
metrics: | ||
format: "{asctime} {message}" | ||
style: "{" | ||
handlers: | ||
metrics: | ||
class: logging.FileHandler | ||
formatter: metrics | ||
filename: metrics.log | ||
loggers: | ||
singer_sdk.metrics: | ||
level: INFO | ||
handlers: [ metrics ] | ||
propagate: yes | ||
``` | ||
This will send metrics to a `metrics.log`: | ||
|
||
``` | ||
2022-09-29 00:48:52,746 INFO METRIC: {"metric_type": "timer", "metric": "http_request_duration", "value": 0.501743, "tags": {"stream": "continents", "endpoint": "", "http_status_code": 200, "status": "succeeded"}} | ||
2022-09-29 00:48:52,775 INFO METRIC: {"metric_type": "counter", "metric": "http_request_count", "value": 1, "tags": {"stream": "continents", "endpoint": ""}} | ||
2022-09-29 00:48:52,776 INFO METRIC: {"metric_type": "timer", "metric": "sync_duration", "value": 0.7397160530090332, "tags": {"stream": "continents", "context": {}, "status": "succeeded"}} | ||
2022-09-29 00:48:52,776 INFO METRIC: {"metric_type": "counter", "metric": "record_count", "value": 7, "tags": {"stream": "continents", "context": {}}} | ||
2022-09-29 00:48:53,225 INFO METRIC: {"metric_type": "timer", "metric": "http_request_duration", "value": 0.392148, "tags": {"stream": "countries", "endpoint": "", "http_status_code": 200, "status": "succeeded"}} | ||
2022-09-29 00:48:53,302 INFO METRIC: {"metric_type": "counter", "metric": "http_request_count", "value": 1, "tags": {"stream": "countries", "endpoint": ""}} | ||
2022-09-29 00:48:53,302 INFO METRIC: {"metric_type": "timer", "metric": "sync_duration", "value": 0.5258760452270508, "tags": {"stream": "countries", "context": {}, "status": "succeeded"}} | ||
2022-09-29 00:48:53,303 INFO METRIC: {"metric_type": "counter", "metric": "record_count", "value": 250, "tags": {"stream": "countries", "context": {}}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 1 | ||
disable_existing_loggers: false | ||
formatters: | ||
console: | ||
format: "{asctime} {message}" | ||
style: "{" | ||
handlers: | ||
default: | ||
class: logging.StreamHandler | ||
formatter: console | ||
stream: ext://sys.stderr | ||
root: | ||
level: INFO | ||
propagate: true | ||
handlers: [default] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from types import ModuleType | ||
|
||
if sys.version_info >= (3, 9): | ||
import importlib.resources as importlib_resources | ||
from importlib.abc import Traversable | ||
else: | ||
import importlib_resources | ||
from importlib_resources.abc import Traversable | ||
|
||
|
||
def get_package_files(package: str | ModuleType) -> Traversable: | ||
"""Load a file from a package. | ||
Args: | ||
package: The package to load the file from. | ||
file: The file to load. | ||
Returns: | ||
The file as a Traversable object. | ||
""" | ||
return importlib_resources.files(package) |
Oops, something went wrong.