Skip to content

Commit 28ee764

Browse files
authored
fix: initialize telemetry asynchronously without blocking (#666)
## Problem VSCode Q chat experiences ~60-second delays when the telemetry endpoint `aws-language-servers.us-east-1.amazonaws.com` is not allowlisted in corporate networks. Root Cause: - Telemetry initialization runs synchronously during LSP server startup - OTLPMetricExporter and OTLPLogExporter each attempt HTTP connections with timeouts - Chat remains unresponsive until all telemetry timeouts complete https://github.com/user-attachments/assets/88f89a4d-5321-4019-a3ec-8e6c87631d77 ## Solution Make telemetry initialization to be non-blocking. Changes: - Wrap telemetry setup in setImmediate() callback - LSP initialization returns immediately with `{ capabilities: {} }` - Telemetry initializes asynchronously in background ## Testing Chat responds quickly even when telemetry URL is blocked https://github.com/user-attachments/assets/463bff7f-df24-4daf-80e9-086b073551f2 <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots if applicable --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1f14063 commit 28ee764

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

runtimes/runtimes/util/telemetryLspServer.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,30 @@ export function getTelemetryLspServer(
4747
const optOut = params.initializationOptions?.telemetryOptOut ?? true // telemetry disabled if option not provided
4848
const endpoint = runtime.getConfiguration('TELEMETRY_GATEWAY_ENDPOINT') ?? DEFAULT_TELEMETRY_ENDPOINT
4949

50-
logging.debug(`Configuring Runtimes OperationalTelemetry with endpoint: ${endpoint}`)
50+
// Initialize telemetry asynchronously without blocking
51+
setImmediate(() => {
52+
try {
53+
logging.debug(`Configuring Runtimes OperationalTelemetry with endpoint: ${endpoint}`)
5154

52-
const optel = OperationalTelemetryService.getInstance({
53-
serviceName: props.name,
54-
serviceVersion: props.version,
55-
extendedClientInfo: params.initializationOptions?.aws?.clientInfo,
56-
logging: logging,
57-
endpoint: endpoint,
58-
telemetryOptOut: optOut,
59-
})
55+
const optel = OperationalTelemetryService.getInstance({
56+
serviceName: props.name,
57+
serviceVersion: props.version,
58+
extendedClientInfo: params.initializationOptions?.aws?.clientInfo,
59+
logging: logging,
60+
endpoint: endpoint,
61+
telemetryOptOut: optOut,
62+
})
6063

61-
OperationalTelemetryProvider.setTelemetryInstance(optel)
64+
OperationalTelemetryProvider.setTelemetryInstance(optel)
6265

63-
logging.info(`Initialized Runtimes OperationalTelemetry with optOut=${optOut}`)
66+
logging.info(`Initialized Runtimes OperationalTelemetry with optOut=${optOut}`)
6467

65-
setServerCrashTelemetryListeners()
66-
setMemoryUsageTelemetry()
68+
setServerCrashTelemetryListeners()
69+
setMemoryUsageTelemetry()
70+
} catch (error) {
71+
logging.warn(`Failed to initialize telemetry: ${error}`)
72+
}
73+
})
6774

6875
return {
6976
capabilities: {},

0 commit comments

Comments
 (0)