Path: blob/main/extensions/copilot/src/platform/otel/common/test/noopOtelService.spec.ts
13406 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 { describe, expect, it } from 'vitest';6import { NoopOTelService } from '../noopOtelService';7import { resolveOTelConfig } from '../otelConfig';8import { SpanStatusCode } from '../otelService';910describe('NoopOTelService', () => {11const config = resolveOTelConfig({ env: {}, extensionVersion: '1.0.0', sessionId: 'test' });12const service = new NoopOTelService(config);1314it('has disabled config', () => {15expect(service.config.enabled).toBe(false);16});1718it('startSpan returns a noop handle', () => {19const span = service.startSpan('test-span', { attributes: { foo: 'bar' } });20// All methods should be callable without error21span.setAttribute('key', 'value');22span.setAttributes({ a: 1, b: 'c' });23span.setStatus(SpanStatusCode.OK);24span.setStatus(SpanStatusCode.ERROR, 'msg');25span.recordException(new Error('test'));26span.end();27});2829it('startActiveSpan runs the function and returns its result', async () => {30const result = await service.startActiveSpan('test', { attributes: {} }, async (span) => {31span.setAttribute('key', 'val');32return 42;33});34expect(result).toBe(42);35});3637it('recordMetric is a noop', () => {38service.recordMetric('test.metric', 42, { dim: 'val' });39});4041it('incrementCounter is a noop', () => {42service.incrementCounter('test.counter', 1, { dim: 'val' });43});4445it('emitLogRecord is a noop', () => {46service.emitLogRecord('test body', { key: 'val' });47});4849it('flush resolves immediately', async () => {50await service.flush();51});5253it('shutdown resolves immediately', async () => {54await service.shutdown();55});56});575859