Skip to content

Conversation

@JacksonWeber
Copy link
Contributor

This pull request introduces logic in the AKSLoader class to temporarily remove the OTEL_TRACES_EXPORTER and OTEL_LOGS_EXPORTER environment variables during initialization, ensuring these variables do not interfere with Azure Monitor setup. Comprehensive unit tests are added to verify correct handling and restoration of these environment variables under various scenarios, including error cases and partial variable presence.

Environment variable management:

  • Added an initialize method to AKSLoader that temporarily removes OTEL_TRACES_EXPORTER and OTEL_LOGS_EXPORTER from process.env during initialization, and restores them afterward, to prevent interference with Azure Monitor setup.

Testing and reliability:

  • Added a new test suite in aksLoader.tests.ts to verify that AKSLoader.initialize() correctly removes and restores the OTEL environment variables during and after initialization, including tests for cases when variables are missing, partially set, or when errors occur during parent initialization.

Copy link
Contributor

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 environment variable management to the AKSLoader class to prevent OTEL exporter environment variables from interfering with Azure Monitor setup in AKS auto-attach scenarios.

  • Temporarily removes OTEL_TRACES_EXPORTER and OTEL_LOGS_EXPORTER during initialization
  • Restores the environment variables after parent initialization completes
  • Includes comprehensive test coverage for various scenarios including error handling

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/agent/aksLoader.ts Implements the initialize method with environment variable removal and restoration logic
test/unitTests/agent/aksLoader.tests.ts Adds comprehensive test suite covering environment variable handling scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +77 to +78
const originalInitialize = Object.getPrototypeOf(Object.getPrototypeOf(agent)).initialize;
const parentInitializeSpy = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').callsFake(function() {
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

The double Object.getPrototypeOf() calls are difficult to read and maintain. Consider storing the parent class in a variable or using a more explicit approach to access the grandparent's initialize method.

Suggested change
const originalInitialize = Object.getPrototypeOf(Object.getPrototypeOf(agent)).initialize;
const parentInitializeSpy = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').callsFake(function() {
const grandparentProto = Object.getPrototypeOf(Object.getPrototypeOf(agent));
const originalInitialize = grandparentProto.initialize;
const parentInitializeSpy = sandbox.stub(grandparentProto, 'initialize').callsFake(function() {

Copilot uses AI. Check for mistakes.
const agent = new AKSLoader();

// Stub parent initialize to throw an error
const parentInitializeStub = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').throws(new Error("Test error"));
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Same issue with double Object.getPrototypeOf() calls making the code hard to read and maintain. Consider extracting this pattern into a helper variable.

Suggested change
const parentInitializeStub = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').throws(new Error("Test error"));
const parentPrototype = Object.getPrototypeOf(Object.getPrototypeOf(agent));
const parentInitializeStub = sandbox.stub(parentPrototype, 'initialize').throws(new Error("Test error"));

Copilot uses AI. Check for mistakes.
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.

2 participants