Skip to content

Addition & Deserialization of Azure Log Analytics Properties #2727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 16, 2025

Why make this change?

Fixes issue #2726

What is this change?

Adds the properties needed to support Azure Log Analytics to the DAB schema and configuration objects as well as the deserialization of those properties.

How was this tested?

  • Integration Tests
  • Unit Tests
  • Manual Testing

@Copilot Copilot AI changed the title [WIP] Deserialize Azure Log Analytics Properties Add Azure Log Analytics properties to DAB schema and configuration objects Jun 16, 2025
@Copilot Copilot AI requested a review from RubenCerna2079 June 16, 2025 19:11
Copilot finished work on behalf of RubenCerna2079 June 16, 2025 19:11
@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

@RubenCerna2079 RubenCerna2079 marked this pull request as ready for review June 19, 2025 22:21
@Copilot Copilot AI review requested due to automatic review settings June 19, 2025 22:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Azure Log Analytics telemetry by extending the DAB schema, configuration objects, and deserialization handling while updating related tests accordingly.

  • Introduces AzureLogAnalyticsOptions in Startup.cs and a corresponding configuration method.
  • Updates TelemetryOptions and JSON schema to include Azure Log Analytics properties.
  • Adds unit tests and configuration tests covering the new telemetry options.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Service/Startup.cs Adds Azure Log Analytics options initialization and configuration logic.
src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs Updates test JSON to include the "azure-log-analytics" property.
src/Service.Tests/Configuration/AzureLogAnalyticsConfigurationTests.cs Provides tests for Azure Log Analytics configuration setup.
src/Config/ObjectModel/TelemetryOptions.cs Extends the telemetry options record with Azure Log Analytics support.
src/Config/ObjectModel/AzureLogAnalyticsOptions.cs Introduces a new record for defining Azure Log Analytics options.
src/Config/ObjectModel/AzureLogAnalyticsAuthOptions.cs Introduces a new record for Azure Log Analytics authentication options.
schemas/dab.draft.schema.json Adds schema definitions for configuring Azure Log Analytics telemetry.
Comments suppressed due to low confidence (1)

src/Service.Tests/Configuration/AzureLogAnalyticsConfigurationTests.cs:65

  • [nitpick] The test method name references 'OpenTelemetry' even though it is defined in the Azure Log Analytics tests; consider renaming it to 'TestAzureLogAnalyticsServicesEnabled' for consistency.
    public void TestOpenTelemetryServicesEnabled()


if (AzureLogAnalyticsOptions.Auth is null)
{
_logger.LogWarning("Logs won't be sent to Azure Log Analytics because the Authorization options are not avaiable in the runtime config.");
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the misspelling of 'avaiable' to 'available' in the log message for clarity.

Suggested change
_logger.LogWarning("Logs won't be sent to Azure Log Analytics because the Authorization options are not avaiable in the runtime config.");
_logger.LogWarning("Logs won't be sent to Azure Log Analytics because the Authorization options are not available in the runtime config.");

Copilot uses AI. Check for mistakes.

@RubenCerna2079 RubenCerna2079 changed the title Add Azure Log Analytics Properties and Deserialization Addition & Deserialization of Azure Log Analytics Properties Jun 19, 2025
/// <summary>
/// Represents the options for configuring Azure Log Analytics.
/// </summary>
public record AzureLogAnalyticsOptions(
Copy link
Contributor

@aaronburtle aaronburtle Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of the options in this and the other classes required? If not, you might wan to follow the pattern used in the other options classes, where a default value is maintained as a property, as well as a bool that indicates if the user provided the property or not. That way the default value can be set when the property is excluded, and we can avoid writing properties back to the config file if that property wasn't included by the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both classes to follow the established pattern. Added UserProvided flags for properties with defaults (Enabled, LogType, FlushIntervalSeconds) and constructor logic to handle default values. The auth properties remain nullable since they don't have meaningful defaults. Changes in commit 5dac9fc.

Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just wondering how we will integrate this with the CLI, and handle reading/writing correctly.

@Copilot Copilot AI requested a review from aaronburtle June 26, 2025 17:07
Copilot finished work on behalf of aaronburtle June 26, 2025 17:07
}
else
{
this.Enabled = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we are not using a default value for Enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using a default value for Enabled. In the constructor (line 62), when Enabled is not provided by the user, it defaults to false. The property is declared as nullable to support the CLI merge config pattern, but gets assigned the default value during construction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the other default values have their own constant property, why is this one just assigned on its own in the constructor?

/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
[MemberNotNullWhen(true, nameof(Enabled))]
public bool UserProvidedEnabled { get; init; } = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the UserProvided flags, but for these to actually be used will require an implementation that extends JsonConverterFactory so that the logic for writing can use these flags in order to determine if they should be written to the config file or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this planned for another PR? I think we also need to have the configure command from the CLI that configures the runtime settings to include logic for these new properties as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the JsonConverterFactory implementation for AzureLogAnalyticsOptions. The converter only serializes properties when their corresponding UserProvided flags are true, preventing default values from polluting the config file. The converter is registered in RuntimeConfigLoader and includes tests to verify the behavior. Changes in commit 066e6ff.

@Copilot Copilot AI requested a review from aaronburtle June 27, 2025 15:13
Copilot finished work on behalf of aaronburtle June 27, 2025 15:13
/// <inheritdoc/>
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
return new AzureLogAnalyticsOptionsConverter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we not passing along _replaceEnvVar here?

/// <summary>
/// Defines how DAB reads and writes Azure Log Analytics options.
/// </summary>
internal class AzureLogAnalyticsOptionsConverterFactory : JsonConverterFactory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need a constructor that can take a bool for replacing environment variables?

/// Uses default deserialize.
/// </summary>
/// <exception cref="JsonException">Thrown when improperly formatted Azure Log Analytics options are provided.</exception>
public override AzureLogAnalyticsOptions? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will simply calling the deserialize function from JsonSerializer be enough here or do we need explicity read logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants