Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/otel/common/noopOtelService.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../util/vs/base/common/event';
7
import type { OTelConfig } from './otelConfig';
8
import type { ICompletedSpanData, IOTelService, ISpanEventData, ISpanHandle, SpanOptions, TraceContext } from './otelService';
9
10
const noopSpan: ISpanHandle = {
11
setAttribute() { },
12
setAttributes() { },
13
setStatus() { },
14
recordException() { },
15
addEvent() { },
16
getSpanContext() { return undefined; },
17
end() { },
18
};
19
20
/**
21
* No-op implementation of IOTelService.
22
* All methods are zero-cost when OTel is disabled.
23
*/
24
export class NoopOTelService implements IOTelService {
25
declare readonly _serviceBrand: undefined;
26
readonly config: OTelConfig;
27
28
constructor(config: OTelConfig) {
29
this.config = config;
30
}
31
32
startSpan(_name: string, _options?: SpanOptions): ISpanHandle {
33
return noopSpan;
34
}
35
36
startActiveSpan<T>(_name: string, _options: SpanOptions, fn: (span: ISpanHandle) => Promise<T>): Promise<T> {
37
return fn(noopSpan);
38
}
39
40
getActiveTraceContext(): TraceContext | undefined {
41
return undefined;
42
}
43
44
storeTraceContext(_key: string, _context: TraceContext): void { }
45
46
getStoredTraceContext(_key: string): TraceContext | undefined {
47
return undefined;
48
}
49
50
runWithTraceContext<T>(_traceContext: TraceContext, fn: () => Promise<T>): Promise<T> {
51
return fn();
52
}
53
54
recordMetric(_name: string, _value: number, _attributes?: Record<string, string | number | boolean>): void { }
55
56
incrementCounter(_name: string, _value?: number, _attributes?: Record<string, string | number | boolean>): void { }
57
58
emitLogRecord(_body: string, _attributes?: Record<string, unknown>): void { }
59
60
async flush(): Promise<void> { }
61
62
async shutdown(): Promise<void> { }
63
64
injectCompletedSpan(_span: ICompletedSpanData): void { }
65
66
readonly onDidCompleteSpan: Event<ICompletedSpanData> = Event.None;
67
readonly onDidEmitSpanEvent: Event<ISpanEventData> = Event.None;
68
}
69
70