Giter Club home page Giter Club logo

Comments (2)

snjypl avatar snjypl commented on July 18, 2024 1

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.

lozbrown avatar lozbrown commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.