/// <summary> /// Executes the logs query. /// </summary> /// <param name="workspaceId">The workspace id to include in the query (<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>).</param> /// <param name="query">The Kusto query to execute.</param> /// <param name="timeRange">The timespan over which to query data. Logs will be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param> /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsQueryResult"/> with the query results.</returns> public virtual async Task <Response <LogsQueryResult> > QueryWorkspaceAsync(string workspaceId, string query, QueryTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryWorkspace)}"); scope.Start(); try { return(await ExecuteAsync(workspaceId, query, timeRange, options, true, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Executes the logs query. /// </summary> /// <param name="workspaceId">The workspace id to include in the query (<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>).</param> /// <param name="query">The Kusto query to execute.</param> /// <param name="timeRange">The timespan over which to query data. Logs will be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param> /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsQueryResult"/> containing the query results.</returns> public virtual Response <LogsQueryResult> Query(string workspaceId, string query, QueryTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(Query)}"); scope.Start(); try { return(ExecuteAsync(workspaceId, query, timeRange, options, false, cancellationToken).EnsureCompleted()); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Executes the logs query. Deserializes the result into a strongly typed model class or a primitive type if the query returns a single column. /// /// Example of querying a model: /// <example snippet="Snippet:QueryLogsAsModelCall"> /// <code language="csharp"> /// Response<IReadOnlyList<MyLogEntryModel>> response = await client.QueryWorkspaceAsync<MyLogEntryModel>( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// </code> /// </example> /// /// Example of querying a primitive: /// <example snippet="Snippet:QueryLogsAsPrimitiveCall"> /// <code language="csharp"> /// Response<IReadOnlyList<string>> response = await client.QueryWorkspaceAsync<string>( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// </code> /// </example> /// </summary> /// <param name="workspaceId">The workspace id to include in the query (<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>).</param> /// <param name="query">The Kusto query to execute.</param> /// <param name="timeRange">The timespan over which to query data. Logs will be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param> /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>Query results mapped to a type <typeparamref name="T"/>.</returns> public virtual async Task <Response <IReadOnlyList <T> > > QueryWorkspaceAsync <T>(string workspaceId, string query, QueryTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default) { Response <LogsQueryResult> response = await QueryWorkspaceAsync(workspaceId, query, timeRange, options, cancellationToken).ConfigureAwait(false); return(Response.FromValue(RowBinder.Shared.BindResults <T>(response.Value.AllTables), response.GetRawResponse())); }
/// <summary> /// Executes the logs query. Deserializes the result into a strongly typed model class or a primitive type if the query returns a single column. /// /// Example of querying a model: /// <example snippet="Snippet:QueryLogsAsModelCall"> /// <code language="csharp"> /// Response<IReadOnlyList<MyLogEntryModel>> response = await client.QueryAsync<MyLogEntryModel>( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// </code> /// </example> /// /// Example of querying a primitive: /// <example snippet="Snippet:QueryLogsAsPrimitiveCall"> /// <code language="csharp"> /// Response<IReadOnlyList<string>> response = await client.QueryAsync<string>( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// </code> /// </example> /// </summary> /// <param name="workspaceId">The workspace id to include in the query (<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>).</param> /// <param name="query">The Kusto query to execute.</param> /// <param name="timeRange">The timespan over which to query data. Logs will be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param> /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>Query results mapped to a type <typeparamref name="T"/>.</returns> public virtual Response <IReadOnlyList <T> > Query <T>(string workspaceId, string query, QueryTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default) { Response <LogsQueryResult> response = Query(workspaceId, query, timeRange, options, cancellationToken); return(Response.FromValue(RowBinder.Shared.BindResults <T>(response.Value.AllTables), response.GetRawResponse())); }