-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Monitor OpenTelemetry Exporter] Fix Dynamic Import #36085
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import type { AzureMonitorExporterOptions } from "../../config.js"; | |
import type { TelemetryItem as Envelope } from "../../generated/index.js"; | ||
import { resourceMetricsToEnvelope } from "../../utils/metricUtils.js"; | ||
import { AzureMonitorBaseExporter } from "../base.js"; | ||
import { HttpSender } from "../../platform/index.js"; | ||
|
||
/** | ||
* Azure Monitor Statsbeat Exporter | ||
|
@@ -21,21 +20,34 @@ export class AzureMonitorStatsbeatExporter | |
* Flag to determine if the Exporter is shutdown. | ||
*/ | ||
private _isShutdown = false; | ||
private _sender: HttpSender; | ||
private _sender: any; | ||
private _senderOptions: any; | ||
|
||
/** | ||
* Initializes a new instance of the AzureMonitorStatsbeatExporter class. | ||
* @param options - Exporter configuration | ||
*/ | ||
constructor(options: AzureMonitorExporterOptions) { | ||
super(options, true); | ||
this._sender = new HttpSender({ | ||
// Store sender options for lazy initialization to avoid circular dependency | ||
this._senderOptions = { | ||
endpointUrl: this.endpointUrl, | ||
instrumentationKey: this.instrumentationKey, | ||
trackStatsbeat: this.trackStatsbeat, | ||
exporterOptions: options, | ||
isStatsbeatSender: true, | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Lazily initialize the sender to avoid circular dependency | ||
*/ | ||
private async _getSender(): Promise<any> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type should be more specific than Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if (!this._sender) { | ||
const { HttpSender } = await import("../../platform/nodejs/httpSender.js"); | ||
this._sender = new HttpSender(this._senderOptions); | ||
} | ||
return this._sender; | ||
} | ||
|
||
/** | ||
|
@@ -79,7 +91,8 @@ export class AzureMonitorStatsbeatExporter | |
|
||
// Supress tracing until OpenTelemetry Metrics SDK support it | ||
context.with(suppressTracing(context.active()), async () => { | ||
resultCallback(await this._sender.exportEnvelopes(filteredEnvelopes)); | ||
const sender = await this._getSender(); | ||
resultCallback(await sender.exportEnvelopes(filteredEnvelopes)); | ||
}); | ||
} | ||
|
||
|
@@ -88,7 +101,9 @@ export class AzureMonitorStatsbeatExporter | |
*/ | ||
public async shutdown(): Promise<void> { | ||
this._isShutdown = true; | ||
return this._sender.shutdown(); | ||
if (this._sender) { | ||
return this._sender.shutdown(); | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ import { | |
ENV_APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL, | ||
RetriableRestErrorTypes, | ||
} from "../../Declarations/Constants.js"; | ||
import { CustomerSDKStatsMetrics } from "../../export/statsbeat/customerSDKStats.js"; | ||
|
||
const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000; | ||
|
||
|
@@ -38,7 +37,7 @@ export abstract class BaseSender { | |
private numConsecutiveRedirects: number; | ||
private retryTimer: NodeJS.Timeout | null; | ||
private networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined; | ||
private customerSDKStatsMetrics: CustomerSDKStatsMetrics | undefined; | ||
private customerSDKStatsMetrics: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
private longIntervalStatsbeatMetrics; | ||
private statsbeatFailureCount: number = 0; | ||
private batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS; | ||
|
@@ -79,12 +78,24 @@ export abstract class BaseSender { | |
); | ||
} | ||
} | ||
this.customerSDKStatsMetrics = CustomerSDKStatsMetrics.getInstance({ | ||
instrumentationKey: options.instrumentationKey, | ||
endpointUrl: options.endpointUrl, | ||
disableOfflineStorage: this.disableOfflineStorage, | ||
networkCollectionInterval: exportInterval, | ||
}); | ||
// Initialize customer SDK stats metrics asynchronously to avoid circular dependency | ||
// Only initialize if not already set (e.g., by tests) | ||
if (!this.customerSDKStatsMetrics) { | ||
import("../../export/statsbeat/customerSDKStats.js") | ||
.then(({ CustomerSDKStatsMetrics }) => CustomerSDKStatsMetrics.getInstance({ | ||
instrumentationKey: options.instrumentationKey, | ||
endpointUrl: options.endpointUrl, | ||
disableOfflineStorage: this.disableOfflineStorage, | ||
networkCollectionInterval: exportInterval, | ||
})) | ||
.then((metrics) => { | ||
this.customerSDKStatsMetrics = metrics; | ||
return; | ||
}) | ||
.catch((error) => { | ||
diag.warn("Failed to initialize customer SDK stats metrics:", error); | ||
}); | ||
} | ||
} | ||
} | ||
this.persister = new FileSystemPersist( | ||
|
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.
Using
any
types reduces type safety. Consider importing the HttpSender type separately from the implementation, or define proper interfaces for these properties to maintain type safety.Copilot uses AI. Check for mistakes.