-
Notifications
You must be signed in to change notification settings - Fork 144
Upgrade AppInsights 3.x to use OpenTelemetry JS 2.x Dependencies #1449
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
Conversation
There was a problem hiding this 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 |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| logRecordProcessors: [logProcessor as any] // Type assertion needed for version compatibility | |
| logRecordProcessors: [new LogProcessorAdapter(logProcessor)] // Use adapter for version compatibility |
| traceFlags: 1, | ||
| }), | ||
| name: "testSpan", | ||
| } as unknown as Span; |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| } as unknown as Span; | |
| // Mock implementations for required methods | |
| setAttribute: () => mockSpan, | |
| setAttributes: () => mockSpan, | |
| addEvent: () => mockSpan, | |
| setStatus: () => mockSpan, | |
| updateName: () => mockSpan, | |
| end: () => {}, | |
| isRecording: () => false, | |
| recordException: () => {}, | |
| }; |
| 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"); |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| assert.equal(options.enableLiveMetrics, false, "wrong enableLiveMetrics"); | |
| assert.equal(options.enableLiveMetrics, false, "incorrect enableLiveMetrics value"); |
| 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"); |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| assert.equal(options.enableStandardMetrics, false, "wrong enableStandardMetrics"); | |
| assert.equal(options.enableStandardMetrics, false, "incorrect enableStandardMetrics value"); |
| 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 |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| dataSet[0].data.baseData?.message | |
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
16.xto18.x. (.github/workflows/integration.yml)package.jsonto their latest versions, including@opentelemetry/coreand@azure/monitor-opentelemetry.OpenTelemetry Refactors
ResourcewithresourceFromAttributesfor resource creation insrc/agent/appServicesLoader.tsandsrc/agent/azureFunctionsLoader.tsfor compatibility with the updated OpenTelemetry SDK. [1] [2] [3] [4]Resource.default()and environment-based resource detection withdefaultResource()insrc/shared/configuration/config.ts. [1] [2]Telemetry Processing Enhancements
useAzureMonitorinsrc/main.tsto dynamically add OTLP exporters and processors for spans and logs based on configuration. [1] [2]flushAzureMonitormethod insrc/main.tsto improve telemetry flushing capabilities.Bug Fixes
CorrelationContextManagerby replacingparentSpanIdwithparentSpanContext?.spanId. [1] [2]ignoreOutgoingRequestHookinsrc/shared/util/common.tsto cast headers as a typed object for better type safety.Test Updates
assertandsinoninstead of CommonJS imports. [1] [2]aksLoader.tests.tsto reflect changes in telemetry exporter registration.