AzureMLApplicationInsightsNotebookHandler 类

表示基于 Application Insights 的笔记本执行处理程序。

继承
azureml.contrib.notebook._notebook_handler.NotebookExecutionHandler
AzureMLApplicationInsightsNotebookHandler

构造函数

AzureMLApplicationInsightsNotebookHandler(appinsights_key, tag, payload=None, history=True, timeout=None, **kwargs)

参数

appinsights_key
str
必需

Application Insights 密钥。

tag
str
必需

事件名称。

payload
dict
默认值: None

事件负载。

history
bool
默认值: True

是否启用指标日志以运行历史记录。 默认值为 True。

timeout
int
默认值: None

单元执行超时(以秒为单位)。

kwargs
dict
必需

可选参数的字典。 请参阅 supported_options

注解


   # Import dependencies
   from azureml.core import Workspace, Experiment, RunConfiguration
   from azureml.contrib.notebook import NotebookRunConfig, AzureMLApplicationInsightsNotebookHandler

   # Create new experiment
   workspace = Workspace.from_config()
   experiment_name = "azureml_notebook_experiment"
   exp = Experiment(workspace, experiment_name)

   # Customize run configuration to execute in user managed environment
   run_config_user_managed = RunConfiguration()
   run_config_user_managed.environment.python.user_managed_dependencies = True

   # Instante AzureML Application Insights notebook handler
   handler = AzureMLApplicationInsightsNotebookHandler(appinsights_key=_appinsights_key,
                                                       tag="notebook-test",
                                                       payload={"experiment_name": experiment_name},
                                                       timeout=600)

   # Create notebook run configuration
   cfg = NotebookRunConfig(source_directory="./notebooks",
                           notebook="notebook-sample.ipynb",
                           handler=handler,
                           parameters={"arg2": "Universe"},
                           run_config=run_config_user_managed)

   # Submit experiment and wait for completion
   run = exp.submit(cfg)
   run.wait_for_completion(show_output=True)

此处理程序将笔记本执行状态作为名为标记的事件记录到 ApplicationInsights 中。 CustomDimensions 有效负载包含:

  • papermill 执行中的笔记本元数据

  • 用户指定的有效负载

  • 状态 - 失败、已完成或超时之一

如果出现故障,则使用以下属性扩展 CustomDimensions:

  • 失败单元的 cell_index 执行计数

  • 源 - 单元的源代码

  • error_type - 异常类型

  • error_message - 异常消息

  • 回溯 - 堆栈跟踪

属性

supported_options

supported_options = ['progress_bar', 'log_output', 'kernel_name', 'cwd']