Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/otel/common/test/noopOtelService.spec.ts
13406 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 { describe, expect, it } from 'vitest';
7
import { NoopOTelService } from '../noopOtelService';
8
import { resolveOTelConfig } from '../otelConfig';
9
import { SpanStatusCode } from '../otelService';
10
11
describe('NoopOTelService', () => {
12
const config = resolveOTelConfig({ env: {}, extensionVersion: '1.0.0', sessionId: 'test' });
13
const service = new NoopOTelService(config);
14
15
it('has disabled config', () => {
16
expect(service.config.enabled).toBe(false);
17
});
18
19
it('startSpan returns a noop handle', () => {
20
const span = service.startSpan('test-span', { attributes: { foo: 'bar' } });
21
// All methods should be callable without error
22
span.setAttribute('key', 'value');
23
span.setAttributes({ a: 1, b: 'c' });
24
span.setStatus(SpanStatusCode.OK);
25
span.setStatus(SpanStatusCode.ERROR, 'msg');
26
span.recordException(new Error('test'));
27
span.end();
28
});
29
30
it('startActiveSpan runs the function and returns its result', async () => {
31
const result = await service.startActiveSpan('test', { attributes: {} }, async (span) => {
32
span.setAttribute('key', 'val');
33
return 42;
34
});
35
expect(result).toBe(42);
36
});
37
38
it('recordMetric is a noop', () => {
39
service.recordMetric('test.metric', 42, { dim: 'val' });
40
});
41
42
it('incrementCounter is a noop', () => {
43
service.incrementCounter('test.counter', 1, { dim: 'val' });
44
});
45
46
it('emitLogRecord is a noop', () => {
47
service.emitLogRecord('test body', { key: 'val' });
48
});
49
50
it('flush resolves immediately', async () => {
51
await service.flush();
52
});
53
54
it('shutdown resolves immediately', async () => {
55
await service.shutdown();
56
});
57
});
58
59