Path: blob/main/extensions/copilot/src/platform/otel/common/noopOtelService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../../util/vs/base/common/event';6import type { OTelConfig } from './otelConfig';7import type { ICompletedSpanData, IOTelService, ISpanEventData, ISpanHandle, SpanOptions, TraceContext } from './otelService';89const noopSpan: ISpanHandle = {10setAttribute() { },11setAttributes() { },12setStatus() { },13recordException() { },14addEvent() { },15getSpanContext() { return undefined; },16end() { },17};1819/**20* No-op implementation of IOTelService.21* All methods are zero-cost when OTel is disabled.22*/23export class NoopOTelService implements IOTelService {24declare readonly _serviceBrand: undefined;25readonly config: OTelConfig;2627constructor(config: OTelConfig) {28this.config = config;29}3031startSpan(_name: string, _options?: SpanOptions): ISpanHandle {32return noopSpan;33}3435startActiveSpan<T>(_name: string, _options: SpanOptions, fn: (span: ISpanHandle) => Promise<T>): Promise<T> {36return fn(noopSpan);37}3839getActiveTraceContext(): TraceContext | undefined {40return undefined;41}4243storeTraceContext(_key: string, _context: TraceContext): void { }4445getStoredTraceContext(_key: string): TraceContext | undefined {46return undefined;47}4849runWithTraceContext<T>(_traceContext: TraceContext, fn: () => Promise<T>): Promise<T> {50return fn();51}5253recordMetric(_name: string, _value: number, _attributes?: Record<string, string | number | boolean>): void { }5455incrementCounter(_name: string, _value?: number, _attributes?: Record<string, string | number | boolean>): void { }5657emitLogRecord(_body: string, _attributes?: Record<string, unknown>): void { }5859async flush(): Promise<void> { }6061async shutdown(): Promise<void> { }6263injectCompletedSpan(_span: ICompletedSpanData): void { }6465readonly onDidCompleteSpan: Event<ICompletedSpanData> = Event.None;66readonly onDidEmitSpanEvent: Event<ISpanEventData> = Event.None;67}686970