<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Azure application insights logging not working  after upgrading cluster to databricks runtime 14.x in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101552#M40718</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have a basic code setup to read a stream from a Delta table and write it into another Delta table. I am using logging to send logs to Application Insights. However, within the&amp;nbsp;&lt;/SPAN&gt;foreachBatch&lt;SPAN&gt;&amp;nbsp;function, the logs I write are not being sent to Application Insights. For example, in the code below, logging works in the&amp;nbsp;&lt;/SPAN&gt;_write_stream&lt;SPAN&gt;&amp;nbsp;method as it is &lt;STRONG&gt;outside&lt;/STRONG&gt; the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;foreachBatch&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;function, but it does not work in the&amp;nbsp;&lt;/SPAN&gt;_merge_streaming_data&lt;SPAN&gt;&amp;nbsp;method because its &lt;STRONG&gt;inside&lt;/STRONG&gt; &lt;STRONG&gt;foreachBatch&lt;/STRONG&gt;. When I say it doesn't work, I mean the logs are not sent or captured in Application Insights. Below is the sample code.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;get_logger&lt;/SPAN&gt;&lt;SPAN&gt;():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; logging&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; opencensus.ext.azure.log_exporter &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; AzureLogHandler&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; logger &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; logging.getLogger(&lt;/SPAN&gt;&lt;SPAN&gt;__name__&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;key &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;"*******&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; logger.addHandler(AzureLogHandler(connection_string&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;key))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt; logger&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;properties = {'custom_dimensions': {'test': 'test'}}&lt;/P&gt;&lt;P&gt;def _merge_streaming_data(batch_df, batch_id):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; spark = batch_df.sparkSession&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger = get_logger()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.warning('_merge_streaming_data1 amit', extra=properties)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; batch_df.write.mode("overwrite").saveAsTable("table_name2")&lt;/P&gt;&lt;P&gt;def _write_stream(main_df):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger = get_logger()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.warning('_write_stream', extra=properties)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; write_df = (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; main_df.writeStream&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .foreachBatch(lambda batch_df, batch_id: _merge_streaming_data(batch_df, batch_id))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .option("checkpointLocation", checkpoint)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.trigger(availableNow=True)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.queryName("Query : test").start())&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return write_df&lt;/P&gt;&lt;P&gt;checkpoint = '****'&lt;BR /&gt;raw_full_table_name = 'table_name'&lt;/P&gt;&lt;P&gt;source_df = spark.readStream.table(raw_full_table_name)&lt;/P&gt;&lt;P&gt;write_stream = _write_stream(source_df)&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;write_stream.awaitTermination()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(f"Completed Processing table: {raw_full_table_name}")&lt;BR /&gt;except Exception as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(e)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;raise&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 07:50:34 GMT</pubDate>
    <dc:creator>abaghel</dc:creator>
    <dc:date>2024-12-10T07:50:34Z</dc:date>
    <item>
      <title>Azure application insights logging not working  after upgrading cluster to databricks runtime 14.x</title>
      <link>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101552#M40718</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a basic code setup to read a stream from a Delta table and write it into another Delta table. I am using logging to send logs to Application Insights. However, within the&amp;nbsp;&lt;/SPAN&gt;foreachBatch&lt;SPAN&gt;&amp;nbsp;function, the logs I write are not being sent to Application Insights. For example, in the code below, logging works in the&amp;nbsp;&lt;/SPAN&gt;_write_stream&lt;SPAN&gt;&amp;nbsp;method as it is &lt;STRONG&gt;outside&lt;/STRONG&gt; the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;foreachBatch&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;function, but it does not work in the&amp;nbsp;&lt;/SPAN&gt;_merge_streaming_data&lt;SPAN&gt;&amp;nbsp;method because its &lt;STRONG&gt;inside&lt;/STRONG&gt; &lt;STRONG&gt;foreachBatch&lt;/STRONG&gt;. When I say it doesn't work, I mean the logs are not sent or captured in Application Insights. Below is the sample code.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;get_logger&lt;/SPAN&gt;&lt;SPAN&gt;():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; logging&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; opencensus.ext.azure.log_exporter &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; AzureLogHandler&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; logger &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; logging.getLogger(&lt;/SPAN&gt;&lt;SPAN&gt;__name__&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;key &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;"*******&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; logger.addHandler(AzureLogHandler(connection_string&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;key))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt; logger&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;properties = {'custom_dimensions': {'test': 'test'}}&lt;/P&gt;&lt;P&gt;def _merge_streaming_data(batch_df, batch_id):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; spark = batch_df.sparkSession&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger = get_logger()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.warning('_merge_streaming_data1 amit', extra=properties)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; batch_df.write.mode("overwrite").saveAsTable("table_name2")&lt;/P&gt;&lt;P&gt;def _write_stream(main_df):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger = get_logger()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.warning('_write_stream', extra=properties)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; write_df = (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; main_df.writeStream&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .foreachBatch(lambda batch_df, batch_id: _merge_streaming_data(batch_df, batch_id))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .option("checkpointLocation", checkpoint)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.trigger(availableNow=True)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.queryName("Query : test").start())&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return write_df&lt;/P&gt;&lt;P&gt;checkpoint = '****'&lt;BR /&gt;raw_full_table_name = 'table_name'&lt;/P&gt;&lt;P&gt;source_df = spark.readStream.table(raw_full_table_name)&lt;/P&gt;&lt;P&gt;write_stream = _write_stream(source_df)&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;write_stream.awaitTermination()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(f"Completed Processing table: {raw_full_table_name}")&lt;BR /&gt;except Exception as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(e)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;raise&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 07:50:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101552#M40718</guid>
      <dc:creator>abaghel</dc:creator>
      <dc:date>2024-12-10T07:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Azure application insights logging not working  after upgrading cluster to databricks runtime 14</title>
      <link>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101553#M40719</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/127860"&gt;@abaghel&lt;/a&gt;&amp;nbsp;There are some changes in foreachBatch in Databricks Runtime 14.0.&lt;BR /&gt;&lt;BR /&gt;Please check:&amp;nbsp;&lt;A href="https://docs.databricks.com/en/structured-streaming/foreach.html#behavior-changes-for-foreachbatch-in-databricks-runtime-140" target="_blank"&gt;https://docs.databricks.com/en/structured-streaming/foreach.html#behavior-changes-for-foreachbatch-in-databricks-runtime-140&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 07:57:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101553#M40719</guid>
      <dc:creator>MuthuLakshmi</dc:creator>
      <dc:date>2024-12-10T07:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Azure application insights logging not working  after upgrading cluster to databricks runtime 14</title>
      <link>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101557#M40721</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/89478"&gt;@MuthuLakshmi&lt;/a&gt;&amp;nbsp;&amp;nbsp;Thank you for getting back to me. I have read the article and understand that "Any files, modules, or objects referenced in the function must be serializable and available on Spark." However, based on the code provided, can you help me identify where I might be encountering serialization issues? The code seems quite basic. Additionally, could you suggest a sample code for reference?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:05:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/azure-application-insights-logging-not-working-after-upgrading/m-p/101557#M40721</guid>
      <dc:creator>abaghel</dc:creator>
      <dc:date>2024-12-10T08:05:35Z</dc:date>
    </item>
  </channel>
</rss>

