{"id":1214,"date":"2021-06-16T11:09:08","date_gmt":"2021-06-16T18:09:08","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sdk\/?p=1214"},"modified":"2021-06-16T15:47:10","modified_gmt":"2021-06-16T22:47:10","slug":"new-azure-monitor-libraries-query","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sdk\/new-azure-monitor-libraries-query\/","title":{"rendered":"Introducing new Azure Monitor libraries for querying Logs and Metrics **Beta**"},"content":{"rendered":"<p><a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\">Azure Monitor<\/a> helps you maximize the availability and performance of your apps. It delivers a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments.<\/p>\n<p>All data collected by Azure Monitor fits into one of two fundamental types:<\/p>\n<ul>\n<li><strong>Metrics<\/strong>\u2014Numerical values that describe some aspect of a system at a particular point in time. They&#8217;re lightweight and can support near real-time scenarios.<\/li>\n<li><strong>Logs<\/strong>\u2014Contain different kinds of data organized into records with different sets of properties for each type. In addition to performance data, telemetry such as events, exceptions, and traces are stored as Logs.<\/li>\n<\/ul>\n<p>To better support analyzing these data sources, we&#8217;re pleased to announce the 1.0 Beta 1 release of the Azure Monitor Query client library. The library:<\/p>\n<ul>\n<li>Enables querying both <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/logs\/data-platform-logs\">Azure Monitor Logs<\/a> and <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/essentials\/data-platform-metrics\">Azure Monitor Metrics<\/a> data.<\/li>\n<li>Supports .NET, Java, JavaScript\/TypeScript, and Python.<\/li>\n<li>Follows the new <a href=\"https:\/\/aka.ms\/azsdk\/guide\">Azure SDK guidelines<\/a>.<\/li>\n<\/ul>\n<p>This blog post will highlight new features of the library.<\/p>\n<h2>Azure Monitor Query library highlights<\/h2>\n<p>The new packages offer the following benefits over their predecessors.<\/p>\n<h2>Unified client library<\/h2>\n<p>Before this release, the libraries used for querying Logs and Metrics data were maintained as separate packages. The two distinct querying libraries have been combined into a single package. The table below lists packages being replaced by these new packages.<\/p>\n<table border=\"1\">\n<tr>\n<th>\n      Language\n    <\/th>\n<th>\n      New package\n    <\/th>\n<th>\n      Old packages being replaced\n    <\/th>\n<\/tr>\n<tr>\n<td>\n      .NET\n    <\/td>\n<td>\n      <a href=\"https:\/\/www.nuget.org\/packages\/Azure.Monitor.Query\">Azure.Monitor.Query<\/a>\n    <\/td>\n<td>\n<ul>\n<li>\n          <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Azure.ApplicationInsights.Query\">Microsoft.Azure.ApplicationInsights.Query<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Azure.OperationalInsights\">Microsoft.Azure.OperationalInsights<\/a>\n        <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n      Java\n    <\/td>\n<td>\n      <a href=\"https:\/\/search.maven.org\/artifact\/com.azure\/azure-monitor-query\">com.azure\/azure-monitor-query<\/a>\n    <\/td>\n<td>\n<ul>\n<li>\n          <a href=\"https:\/\/search.maven.org\/artifact\/com.microsoft.azure\/azure-applicationinsights-query\">com.microsoft.azure\/azure-applicationinsights-query<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/search.maven.org\/artifact\/com.microsoft.azure\/azure-loganalytics\">com.microsoft.azure\/azure-loganalytics<\/a>\n        <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n      JavaScript \/ TypeScript\n    <\/td>\n<td>\n      <a href=\"https:\/\/www.npmjs.com\/package\/@azure\/monitor-query\">@azure\/monitor-query<\/a>\n    <\/td>\n<td>\n<ul>\n<li>\n          <a href=\"https:\/\/www.npmjs.com\/package\/azure-applicationinsights-query\">azure-applicationinsights-query<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/www.npmjs.com\/package\/@azure\/applicationinsights-query\">@azure\/applicationinsights-query<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/www.npmjs.com\/package\/azure-loganalytics\">azure-loganalytics<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/www.npmjs.com\/package\/@azure\/loganalytics\">@azure\/loganalytics<\/a>\n        <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n      Python\n    <\/td>\n<td>\n      <a href=\"https:\/\/pypi.org\/project\/azure-monitor-query\">azure-monitor-query<\/a>\n    <\/td>\n<td>\n<ul>\n<li>\n          <a href=\"https:\/\/pypi.org\/project\/azure-applicationinsights\">azure-applicationinsights<\/a>\n        <\/li>\n<li>\n          <a href=\"https:\/\/pypi.org\/project\/azure-loganalytics\">azure-loganalytics<\/a>\n        <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/table>\n<h2>New client library features<\/h2>\n<p>The new libraries were updated to include the following new features:<\/p>\n<h3>Batch API for Logs query<\/h3>\n<p>The new libraries support the execution of multiple Logs queries in a single request. Consider this C# example, which executes two <a href=\"https:\/\/docs.microsoft.com\/azure\/data-explorer\/kusto\/query\">Kusto<\/a> queries:<\/p>\n<pre><code class=\"language-csharp\">\/\/ code omitted for brevity\n\nvar client = new LogsQueryClient(endpoint, new DefaultAzureCredential());\n\n\/\/ Query TOP 10 resource groups by event count\n\/\/ And total event count\nvar batch = new LogsBatchQuery();\nstring countQueryId = batch.AddQuery(\n    workspace: workspaceId,\n    query: \"AzureActivity | count\",\n    timeRange: TimeSpan.FromDays(1));\nstring topQueryId = batch.AddQuery(\n    workspace: workspaceId, \n    query: \"AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count\",\n    timeRange: TimeSpan.FromDays(1));\n\nResponse&lt;LogsBatchQueryResult&gt; response = await client.QueryBatchAsync(batch);<\/code><\/pre>\n<h3>Performance statistics<\/h3>\n<p>Logs query performance statistics, such as execution time and resource usage, can be included in the response by opting in. Consider the following C# example, which opts in via the <code>LogsQueryOptions<\/code> class&#8217; <code>IncludeStatistics<\/code> property:<\/p>\n<pre><code class=\"language-csharp\">\/\/ code omitted for brevity\n\nvar client = new LogsQueryClient(endpoint, new DefaultAzureCredential());\nResponse&lt;LogsQueryResult&gt; response = await client.QueryAsync(\n    workspaceId, \"AzureActivity | top 10 by TimeGenerated\", TimeSpan.FromDays(1),\n    new LogsQueryOptions\n    {\n        IncludeStatistics = true\n    });<\/code><\/pre>\n<h3>Server timeout<\/h3>\n<p>Logs query execution times vary widely based on several factors. Examples of such factors include:<\/p>\n<ul>\n<li>The query&#8217;s complexity.<\/li>\n<li>The amount of data being analyzed.<\/li>\n<li>The system and workspace load at the time of the query.<\/li>\n<\/ul>\n<p>Some Logs queries take longer than three minutes to execute. The default server timeout is three minutes. With the new libraries, you can increase the server timeout to a maximum of 10 minutes. Consider the following C# example, which sets the server timeout to five minutes:<\/p>\n<pre><code class=\"language-csharp\">\/\/ code omitted for brevity\n\nvar client = new LogsQueryClient(endpoint, new DefaultAzureCredential());\nResponse&lt;LogsQueryResult&gt; response = await client.QueryAsync(\n    workspaceId, \"AzureActivity | top 10 by TimeGenerated\", TimeSpan.FromDays(1),\n    new LogsQueryOptions\n    {\n        ServerTimeout = TimeSpan.FromMinutes(5)\n    });<\/code><\/pre>\n<h2>Handwritten client libraries<\/h2>\n<p>Except for the .NET library, code generation was used to produce the old libraries. The new libraries for Java, JavaScript\/TypeScript, and Python are handwritten to achieve parity with .NET. Per the <a href=\"https:\/\/aka.ms\/azsdk\/guide#design-principles\">design principles<\/a> for the new Azure SDK libraries, the libraries strive to be idiomatic. As a developer in the target language, interacting with the library should feel natural.<\/p>\n<h2>Azure Active Directory authentication<\/h2>\n<p>The new library includes Azure Active Directory authentication support for both Logs and Metrics queries. <a href=\"https:\/\/devblogs.microsoft.com\/azure-sdk\/azure-identity-august-2020-ga\/\">Azure Identity<\/a> is used, which improves the local development experience in editors and IDEs. Some popular examples include IntelliJ, Visual Studio Code, and Visual Studio.<\/p>\n<h2>Conclusion<\/h2>\n<p>The Azure Monitor Query libraries have enhanced querying Logs and Metrics data sources. To get started with the library, see the language-specific instructions below.<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-net\/tree\/master\/sdk\/monitor\/Azure.Monitor.Query#getting-started\">.NET<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-java\/tree\/master\/sdk\/monitor\/azure-monitor-query#getting-started\">Java<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/tree\/master\/sdk\/monitor\/monitor-query#getting-started\">JavaScript\/TypeScript<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/tree\/master\/sdk\/monitor\/azure-monitor-query#getting-started\">Python<\/a><\/li>\n<\/ul>\n<p>For language-specific examples, see the following code samples:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-net\/tree\/master\/sdk\/monitor\/Azure.Monitor.Query#examples\">.NET<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-java\/tree\/master\/sdk\/monitor\/azure-monitor-query\/src\/samples\/java\">Java<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/tree\/master\/sdk\/monitor\/monitor-query\/samples\/v1\/javascript\">JavaScript<\/a> \/ <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/tree\/master\/sdk\/monitor\/monitor-query\/samples\/v1\/typescript\">TypeScript<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/tree\/master\/sdk\/monitor\/azure-monitor-query\/samples\">Python<\/a><\/p>\n<\/li>\n<\/ul>\n<p>You&#8217;re encouraged to provide feedback before the library reaches general availability. To report issues or send feedback to the Azure SDK engineering team, use the language-specific links below:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-net\/issues\/new\/choose\">.NET<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-java\/issues\/new\/choose\">Java<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-js\/issues\/new\/choose\">JavaScript<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/issues\/new\/choose\">Python<\/a><\/p>\n<\/li>\n<\/ul>\n<p><!-- FOOTER: DO NOT EDIT OR REMOVE --><\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/aka.ms\/azsdk\/releases\" target=\"_blank\">Azure SDK Releases<\/a><\/div><\/p>\n<h2>Azure SDK Blog Contributions<\/h2>\n<p>Thank you for reading this Azure SDK blog post! We hope that you learned something new and welcome you to share this post. We are open to Azure SDK blog contributions. Please contact us at <a href=\"&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x61;z&#115;&#x64;&#107;&#x62;&#108;&#x6f;&#103;&#x40;&#109;&#105;&#x63;&#114;&#x6f;&#115;&#x6f;&#102;&#x74;&#46;&#x63;o&#109;\">&#x61;z&#115;&#x64;&#107;&#x62;&#108;&#x6f;&#103;&#x40;&#109;&#105;&#x63;&#114;&#x6f;&#115;&#x6f;&#102;&#x74;&#46;&#x63;o&#109;<\/a> with your topic and we&#8217;ll get you set up as a guest blogger.<\/p>\n<h2>Azure SDK Links<\/h2>\n<ul>\n<li>Azure SDK Website: <a href=\"https:\/\/aka.ms\/azsdk\">aka.ms\/azsdk<\/a><\/li>\n<li>Azure SDK Intro (3 minute video): <a href=\"https:\/\/aka.ms\/azsdk\/intro\">aka.ms\/azsdk\/intro<\/a><\/li>\n<li>Azure SDK Intro Deck (PowerPoint deck): <a href=\"https:\/\/aka.ms\/azsdk\/intro\/deck\">aka.ms\/azsdk\/intro\/deck<\/a><\/li>\n<li>Azure SDK Releases: <a href=\"https:\/\/aka.ms\/azsdk\/releases\">aka.ms\/azsdk\/releases<\/a><\/li>\n<li>Azure SDK Blog: <a href=\"https:\/\/aka.ms\/azsdk\/blog\">aka.ms\/azsdk\/blog<\/a><\/li>\n<li>Azure SDK Twitter: <a href=\"https:\/\/twitter.com\/AzureSDK\">twitter.com\/AzureSDK<\/a><\/li>\n<li>Azure SDK Design Guidelines: <a href=\"https:\/\/aka.ms\/azsdk\/guide\">aka.ms\/azsdk\/guide<\/a><\/li>\n<li>Azure SDKs &amp; Tools: <a href=\"https:\/\/azure.microsoft.com\/downloads\">azure.microsoft.com\/downloads<\/a><\/li>\n<li>Azure SDK Central Repository: <a href=\"https:\/\/github.com\/azure\/azure-sdk#azure-sdk\">github.com\/azure\/azure-sdk<\/a><\/li>\n<li>Azure SDK for .NET: <a href=\"https:\/\/github.com\/azure\/azure-sdk-for-net\">github.com\/azure\/azure-sdk-for-net<\/a><\/li>\n<li>Azure SDK for Java: <a href=\"https:\/\/github.com\/azure\/azure-sdk-for-java\">github.com\/azure\/azure-sdk-for-java<\/a><\/li>\n<li>Azure SDK for Python: <a href=\"https:\/\/github.com\/azure\/azure-sdk-for-python\">github.com\/azure\/azure-sdk-for-python<\/a><\/li>\n<li>Azure SDK for JavaScript\/TypeScript: <a href=\"https:\/\/github.com\/azure\/azure-sdk-for-js\">github.com\/azure\/azure-sdk-for-js<\/a><\/li>\n<li>Azure SDK for Android: <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-android\">github.com\/Azure\/azure-sdk-for-android<\/a><\/li>\n<li>Azure SDK for iOS: <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-ios\">github.com\/Azure\/azure-sdk-for-ios<\/a><\/li>\n<li>Azure SDK for Go: <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-go\">github.com\/Azure\/azure-sdk-for-go<\/a><\/li>\n<li>Azure SDK for C: <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-c\">github.com\/Azure\/azure-sdk-for-c<\/a><\/li>\n<li>Azure SDK for C++: <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-cpp\">github.com\/Azure\/azure-sdk-for-cpp<\/a><\/li>\n<\/ul>\n<p><!-- FOOTER: DO NOT EDIT OR REMOVE --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article introduces the 1.0 Beta 1 release of the Azure Monitor Query client library for .NET, Java, JavaScript\/TypeScript, and Python.<\/p>\n","protected":false},"author":63456,"featured_media":1201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[701,734,804,706,160,159,805,806,162,732,24],"class_list":["post-1214","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sdk","tag-net","tag-azure","tag-azure-monitor","tag-azuresdk","tag-java","tag-javascript","tag-logs","tag-metrics","tag-python","tag-release","tag-releases"],"acf":[],"blog_post_summary":"<p>This article introduces the 1.0 Beta 1 release of the Azure Monitor Query client library for .NET, Java, JavaScript\/TypeScript, and Python.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts\/1214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/users\/63456"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/comments?post=1214"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts\/1214\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/media\/1201"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/media?parent=1214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/categories?post=1214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/tags?post=1214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}