Skip to content

Commit bcd5ef9

Browse files
authored
fix: use logging instead of lspConsole (#545)
1 parent 0568a44 commit bcd5ef9

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

runtimes/runtimes/operational-telemetry/operational-telemetry-service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('OperationalTelemetryService with OpenTelemetry SDK', () => {
8080
return {
8181
serviceName: mockServiceName,
8282
serviceVersion: mockServiceVersion,
83-
lspConsole: {
83+
logging: {
8484
debug: () => {},
8585
error: () => {},
8686
info: () => {},

runtimes/runtimes/operational-telemetry/operational-telemetry-service.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { OperationalEventAttributes, OperationalTelemetry } from './operational-
33
import { diag, DiagLogLevel, metrics } from '@opentelemetry/api'
44
import { Resource, resourceFromAttributes } from '@opentelemetry/resources'
55
import { randomUUID } from 'crypto'
6-
import { RemoteConsole } from 'vscode-languageserver'
76
import { logs } from '@opentelemetry/api-logs'
8-
import { ExtendedClientInfo } from '../../server-interface'
7+
import { ExtendedClientInfo, Logging } from '../../server-interface'
98
import { OperationalTelemetryResource, MetricName } from './types/generated/telemetry'
109
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
1110
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'
@@ -16,7 +15,7 @@ type OperationalTelemetryConfig = {
1615
serviceName: string
1716
serviceVersion?: string
1817
extendedClientInfo?: ExtendedClientInfo
19-
lspConsole: RemoteConsole
18+
logging: Logging
2019
endpoint: string
2120
telemetryOptOut: boolean
2221
exportIntervalMillis?: number
@@ -34,7 +33,7 @@ export class OperationalTelemetryService implements OperationalTelemetry {
3433
private readonly scheduledDelayMillis: number
3534
private loggerProvider: LoggerProvider | null = null
3635
private meterProvider: MeterProvider | null = null
37-
private readonly lspConsole: RemoteConsole
36+
private readonly logging: Logging
3837

3938
static getInstance(config: OperationalTelemetryConfig): OperationalTelemetryService {
4039
if (!OperationalTelemetryService.instance) {
@@ -47,7 +46,7 @@ export class OperationalTelemetryService implements OperationalTelemetry {
4746
this.exportIntervalMillis = config.exportIntervalMillis ?? this.FIVE_MINUTES
4847
this.scheduledDelayMillis = config.scheduledDelayMillis ?? this.FIVE_MINUTES
4948

50-
this.lspConsole = config.lspConsole
49+
this.logging = config.logging
5150

5251
const operationalTelemetryResource: OperationalTelemetryResource = {
5352
'server.name': config.serviceName,
@@ -135,11 +134,11 @@ export class OperationalTelemetryService implements OperationalTelemetry {
135134
private startApi() {
136135
diag.setLogger(
137136
{
138-
debug: message => this.lspConsole.debug(message),
139-
error: message => this.lspConsole.error(message),
140-
info: message => this.lspConsole.info(message),
141-
verbose: message => this.lspConsole.log(message),
142-
warn: message => this.lspConsole.warn(message),
137+
debug: message => this.logging.debug(message),
138+
error: message => this.logging.error(message),
139+
info: message => this.logging.info(message),
140+
verbose: message => this.logging.log(message),
141+
warn: message => this.logging.warn(message),
143142
},
144143
DiagLogLevel.ALL
145144
)

runtimes/runtimes/util/telemetryLspServer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ export function getTelemetryLspServer(
4545

4646
lspServer.setInitializeHandler(async (params: InitializeParams): Promise<InitializeResult> => {
4747
const optOut = params.initializationOptions?.telemetryOptOut ?? true // telemetry disabled if option not provided
48-
4948
const endpoint = runtime.getConfiguration('TELEMETRY_GATEWAY_ENDPOINT') ?? DEFAULT_TELEMETRY_ENDPOINT
5049

50+
logging.debug(`Configuring Runtimes OperationalTelemetry with endpoint: ${endpoint}`)
51+
5152
const optel = OperationalTelemetryService.getInstance({
5253
serviceName: props.name,
5354
serviceVersion: props.version,
5455
extendedClientInfo: params.initializationOptions?.aws?.clientInfo,
55-
lspConsole: lspConnection.console,
56+
logging: logging,
5657
endpoint: endpoint,
5758
telemetryOptOut: optOut,
5859
})
5960

6061
OperationalTelemetryProvider.setTelemetryInstance(optel)
6162

63+
logging.info(`Initialized Runtimes OperationalTelemetry with optOut=${optOut}`)
64+
6265
setServerCrashTelemetryListeners()
6366
setMemoryUsageTelemetry()
6467

@@ -73,6 +76,7 @@ export function getTelemetryLspServer(
7376
})
7477

7578
if (typeof optOut === 'boolean') {
79+
logging.info(`Updating Runtimes OperationalTelemetry with optOut=${optOut}`)
7680
OperationalTelemetryProvider.getTelemetryForScope('').toggleOptOut(optOut)
7781
setMemoryUsageTelemetry()
7882
}

0 commit comments

Comments
 (0)