Comments (2)
you can do it by creating a custom logger class extending the LokiTaskHandler
and overriding the get_labels
method. here is an example:
~/airflow/config/lokilogger.py
from grafana_loki_provider.log.loki_task_handler import LokiTaskHandler
from typing import Dict, TYPE_CHECKING
if TYPE_CHECKING:
from airflow.models.taskinstance import TaskInstance
class CustomLokiHandler(LokiTaskHandler):
def get_labels(self, ti: "TaskInstance")-> Dict[str, str]:
labels = super().get_labels(ti)
labels['run_id'] =str(ti.run_id)
labels['my_custom_label']='xyz'
return labels
update the airflow log_config to use the custom class
elif REMOTE_BASE_LOG_FOLDER.startswith('loki'):
LOKI_HANDLER: Dict[str, Dict[str, Union[str, bool]]] = {
'task': {
'class': 'lokilogger.CustomLokiHandler',
'formatter': 'airflow',
'name':"airflow_task",
'base_log_folder': str(os.path.expanduser(BASE_LOG_FOLDER)),
'filename_template': FILENAME_TEMPLATE
},
}
DEFAULT_LOGGING_CONFIG['handlers'].update(LOKI_HANDLER)
from airflow-provider-grafana-loki.
As examples
I need to tag logs with X-Scope-OrgID, there are also several others that would be useful statically to identify specific instances etc
Furthermore it would be great if each task log was labelled with
dag id
task id
run id
logical_date
from airflow-provider-grafana-loki.
Related Issues (10)
- No module named 'airflow.providers.grafana_loki_provider' HOT 2
- Date intervals in Loki queries too wide? HOT 2
- Not pushing logs to Loki HOT 12
- Configurable log reading range HOT 1
- Error viewing logs in UI HOT 35
- Debug: Error viewing logs when running in airflow standlone mode HOT 2
- Plugin does not work with Python 3.7 (cannot import name 'cached_property' from 'functools') HOT 2
- TypeError: unsupported operand type(s) for +: 'NoneType' and 'datetime.timedelta' HOT 1
- Grafana Loki (Loki) connection hook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from airflow-provider-grafana-loki.