Handler that integrates with Stackdriver.

Module Contents



Handler that directly makes Stackdriver logging API calls.


DEFAULT_LOGGER_NAME = 'airflow'[source]
class, scopes=_DEFAULT_SCOPESS, name=NOTSET, transport=BackgroundThreadTransport, resource=_GLOBAL_RESOURCE, labels=None, gcp_log_name=DEFAULT_LOGGER_NAME)[source]

Bases: logging.Handler

Handler that directly makes Stackdriver logging API calls.

This is a Python standard logging handler using that can be used to route Python standard logging messages directly to the Stackdriver Logging API.

It can also be used to save logs for executing tasks. To do this, you should set as a handler with the name “tasks”. In this case, it will also be used to read the log for display in Web UI.

This handler supports both an asynchronous and synchronous transport.

  • gcp_key_path (str | None) – Path to Google Cloud Credential JSON file. If omitted, authorization based on the Application Default Credentials will be used.

  • scopes (Collection[str] | None) – OAuth scopes for the credentials,

  • name (str | airflow.utils.types.ArgNotSet) – the name of the custom log in Stackdriver Logging. Defaults to ‘airflow’. The name of the Python logger will be represented in the python_logger field.

  • transport (type[]) – Class for creating new transport objects. It should extend from the base type and implement :meth``. Defaults to The other option is

  • resource ( – (Optional) Monitored resource of the entry, defaults to the global resource type.

  • labels (dict[str, str] | None) – (Optional) Mapping of labels for the entry.

property log_name[source]

Return log name.

LABEL_TASK_ID = 'task_id'[source]
LABEL_DAG_ID = 'dag_id'[source]
LABEL_EXECUTION_DATE = 'execution_date'[source]
LABEL_TRY_NUMBER = 'try_number'[source]
LOG_VIEWER_BASE_URL = ''[source]
LOG_NAME = 'Google Stackdriver'[source]
trigger_supported = True[source]
trigger_should_queue = False[source]
trigger_should_wrap = False[source]
trigger_send_end_marker = False[source]

Actually log the specified logging record.


record (logging.LogRecord) – The record to be logged.


Configure the logger to add information with information about the current task.


task_instance (airflow.models.TaskInstance) – Currently executed task

read(task_instance, try_number=None, metadata=None)[source]

Read logs of given task instance from Stackdriver logging.

  • task_instance (airflow.models.TaskInstance) – task instance object

  • try_number (int | None) – task instance try_number to read logs from. If None it returns all logs

  • metadata (dict | None) – log metadata. It is used for steaming log reading and auto-tailing.


a tuple of ( list of (one element tuple with two element tuple - hostname and logs) and list of metadata)

Return type

tuple[list[tuple[tuple[str, str]]], list[dict[str, str | bool]]]

get_external_log_url(task_instance, try_number)[source]

Create an address for an external log collecting service.

  • task_instance (airflow.models.TaskInstance) – task instance object

  • try_number (int) – task instance try_number to read logs from


URL to the external log collection service

Return type



Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

Was this entry helpful?