-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Logging README #4395
Merged
Merged
Logging README #4395
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -6,7 +6,53 @@ The Events module is the implmentation for structured logging. These events repr | |
The event module provides types that represent what is happening in dbt in `events.types`. These types are intended to represent an exhaustive list of all things happening within dbt that will need to be logged, streamed, or printed. To fire an event, `events.functions::fire_event` is the entry point to the module from everywhere in dbt. | ||
|
||
# Adding a New Event | ||
In `events.types` add a new class that represents the new event. This may be a simple class with no values, or it may be a dataclass with some values to construct downstream messaging. Only include the data necessary to construct this message within this class. You must extend all destinations (e.g. - if your log message belongs on the cli, extend `CliEventABC`) as well as the loglevel this event belongs to. | ||
In `events.types` add a new class that represents the new event. All events must be a dataclass with, at minimum, a code. You may also include some other values to construct downstream messaging. Only include the data necessary to construct this message within this class. You must extend all destinations (e.g. - if your log message belongs on the cli, extend `Cli`) as well as the loglevel this event belongs to. This system has been designed to take full advantage of mypy so running it will catch anything you may miss. | ||
|
||
## Required for Every Event | ||
|
||
- A unique `code` that indicates the type | ||
- a loglevel | ||
- a message() | ||
- extend `File` and/or `Cli` based on where it should output | ||
|
||
Example | ||
``` | ||
@dataclass | ||
class SuperImportantNodeEvent(DebugLevel, Cli, File): | ||
node_name: str | ||
code: str = "Q035" | ||
|
||
def message(self) -> str: | ||
return f"Running important node {self.node_name}" | ||
|
||
``` | ||
|
||
## Optional (based on your event) | ||
|
||
- Events associated with node status changes must have `report_node_data` passed in and be extended with `Cache` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should mention extending the |
||
- define `asdict` if your data is not serializable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serializable to json |
||
|
||
Example | ||
``` | ||
@dataclass | ||
class SuperImportantNodeEvent(InfoLevel, File): | ||
node_name: str | ||
run_result: RunResult | ||
report_node_data: ParsedModelNode # may vary | ||
code: str = "Q036" | ||
|
||
def message(self) -> str: | ||
return f"{self.node_name} had overly verbose result of {run_result}" | ||
|
||
@classmethod | ||
def asdict(cls, data: list) -> dict: | ||
return dict((k, str(v)) for k, v in data) | ||
|
||
``` | ||
|
||
All values other than `code` and `report_node_data` will be included in the `data` node of the json log output. | ||
|
||
Once your event has been added, add a dummy call to your new event at the bottom of `types.py` and also add your new Event to the list `sample_values` in `test/unit/test_events.py'. | ||
nathaniel-may marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Adapter Maintainers | ||
To integrate existing log messages from adapters, you likely have a line of code like this in your adapter already: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd follow suit with the 4th bullet and mention extending the class with an example.