Skip to content

Conversation

@JacksonWeber
Copy link
Contributor

@JacksonWeber JacksonWeber commented Jul 9, 2025

This pull request includes updates to dependencies, refactors for compatibility with the latest OpenTelemetry SDK, and improvements to resource handling and telemetry processing. It also includes test updates and minor bug fixes. Below is a summary of the most important changes:

Dependency Updates

  • Updated Node.js version in the GitHub Actions workflow from 16.x to 18.x. (.github/workflows/integration.yml)
  • Upgraded various OpenTelemetry and Azure Monitor dependencies in package.json to their latest versions, including @opentelemetry/core and @azure/monitor-opentelemetry.

OpenTelemetry Refactors

  • Replaced Resource with resourceFromAttributes for resource creation in src/agent/appServicesLoader.ts and src/agent/azureFunctionsLoader.ts for compatibility with the updated OpenTelemetry SDK. [1] [2] [3] [4]
  • Replaced Resource.default() and environment-based resource detection with defaultResource() in src/shared/configuration/config.ts. [1] [2]

Telemetry Processing Enhancements

  • Refactored useAzureMonitor in src/main.ts to dynamically add OTLP exporters and processors for spans and logs based on configuration. [1] [2]
  • Added support for a new flushAzureMonitor method in src/main.ts to improve telemetry flushing capabilities.

Bug Fixes

  • Fixed incorrect parent span context handling in CorrelationContextManager by replacing parentSpanId with parentSpanContext?.spanId. [1] [2]
  • Updated ignoreOutgoingRequestHook in src/shared/util/common.ts to cast headers as a typed object for better type safety.

Test Updates

  • Updated unit tests to use ES module imports for assert and sinon instead of CommonJS imports. [1] [2]
  • Adjusted assertions in aksLoader.tests.ts to reflect changes in telemetry exporter registration.

@JacksonWeber JacksonWeber requested a review from Copilot July 10, 2025 01:18

This comment was marked as outdated.

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 pull request upgrades AppInsights from 3.x to use OpenTelemetry JS 2.x dependencies, focusing on dependency version upgrades, testing approach improvements, and compatibility updates. The most significant changes include updating OpenTelemetry-related packages to 2.x versions, modernizing import statements throughout test files, and adapting to new OpenTelemetry 2.x APIs.

  • Updated OpenTelemetry dependencies from 1.30.x/0.57.x versions to 2.x/0.202.x versions
  • Modernized import statements from CommonJS-style to ES6 imports across test files
  • Updated span context handling to use new OpenTelemetry 2.x API patterns
  • Modified testing strategies to work with the new processor architecture

Reviewed Changes

Copilot reviewed 30 out of 32 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
package.json Updated OpenTelemetry dependencies to 2.x versions
test/unitTests/**/*.tests.ts Modernized import statements and updated test implementations
src/main.ts Refactored OTLP exporter handling to work with new architecture
src/shim/correlationContextManager.ts Updated span context API usage for 2.x compatibility
src/shared/configuration/config.ts Simplified resource creation using new APIs
src/agent/*.ts Updated resource creation methods
Comments suppressed due to low confidence (1)

// Add test processors through the Azure Monitor options
client.config.azureMonitorOpenTelemetryOptions = {
spanProcessors: [testProcessor],
logRecordProcessors: [logProcessor as any] // Type assertion needed for version compatibility
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

The type assertion 'as any' bypasses type safety. Consider creating a proper type adapter or interface to handle the version compatibility issue more safely.

Suggested change
logRecordProcessors: [logProcessor as any] // Type assertion needed for version compatibility
logRecordProcessors: [new LogProcessorAdapter(logProcessor)] // Use adapter for version compatibility

Copilot uses AI. Check for mistakes.
traceFlags: 1,
}),
name: "testSpan",
} as unknown as Span;
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

The double type assertion 'as unknown as Span' indicates a potential type mismatch. Consider creating a proper mock object that implements the Span interface correctly.

Suggested change
} as unknown as Span;
// Mock implementations for required methods
setAttribute: () => mockSpan,
setAttributes: () => mockSpan,
addEvent: () => mockSpan,
setStatus: () => mockSpan,
updateName: () => mockSpan,
end: () => {},
isRecording: () => false,
recordException: () => {},
};

Copilot uses AI. Check for mistakes.
assert.equal(options.enableTraceBasedSamplingForLogs, false, "wrong enableTraceBasedSamplingForLogs");
assert.equal(options.enableLiveMetrics, false, "wrong enableTraceBasedSamplingForLogs");
assert.equal(options.enableStandardMetrics, false, "wrong enableTraceBasedSamplingForLogs");
assert.equal(options.enableLiveMetrics, false, "wrong enableLiveMetrics");
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The error message should be more descriptive than 'wrong enableLiveMetrics'. Consider using 'incorrect enableLiveMetrics value' or similar.

Suggested change
assert.equal(options.enableLiveMetrics, false, "wrong enableLiveMetrics");
assert.equal(options.enableLiveMetrics, false, "incorrect enableLiveMetrics value");

Copilot uses AI. Check for mistakes.
assert.equal(options.enableLiveMetrics, false, "wrong enableTraceBasedSamplingForLogs");
assert.equal(options.enableStandardMetrics, false, "wrong enableTraceBasedSamplingForLogs");
assert.equal(options.enableLiveMetrics, false, "wrong enableLiveMetrics");
assert.equal(options.enableStandardMetrics, false, "wrong enableStandardMetrics");
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The error message should be more descriptive than 'wrong enableStandardMetrics'. Consider using 'incorrect enableStandardMetrics value' or similar.

Suggested change
assert.equal(options.enableStandardMetrics, false, "wrong enableStandardMetrics");
assert.equal(options.enableStandardMetrics, false, "incorrect enableStandardMetrics value");

Copilot uses AI. Check for mistakes.
Utils.Logging.error("FAILED EXPECTATION - Unexpected child telemetry item(s)!");
Utils.Logging.error(JSON.stringify(dataSet, null, 2));
hadFailed = true;
dataSet[0].data.baseData?.message
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

This line appears to be a dangling expression that serves no purpose. It should either be assigned to a variable, used in a condition, or removed.

Suggested change
dataSet[0].data.baseData?.message

Copilot uses AI. Check for mistakes.
@JacksonWeber JacksonWeber merged commit 040f4be into main Jul 24, 2025
16 checks passed
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