Skip to content

Commit 3fd2f35

Browse files
kalenkevichcopybara-github
authored andcommitted
Generate docs for the @google/adk-js package using TypeDoc
PiperOrigin-RevId: 861331482
1 parent a3232ee commit 3fd2f35

File tree

7 files changed

+778
-320
lines changed

7 files changed

+778
-320
lines changed

.github/workflows/validation.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ jobs:
2828

2929
- name: Run tests
3030
run: npm run test
31+
32+
- name: Check documentation can be built
33+
run: npm run docs:check

core/test/telemetry/setup_test.ts

Lines changed: 100 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import {metrics, trace} from '@opentelemetry/api';
8+
import {logs} from '@opentelemetry/api-logs';
79

8-
import {maybeSetOtelProviders} from '../../src/telemetry/setup.js';
910
import type {OTelHooks} from '../../src/telemetry/setup.js';
10-
import {trace} from '@opentelemetry/api';
11-
import {metrics} from '@opentelemetry/api';
12-
import {logs} from '@opentelemetry/api-logs';
11+
import {maybeSetOtelProviders} from '../../src/telemetry/setup.js';
1312

1413
// Mock OpenTelemetry modules
1514
vi.mock('@opentelemetry/exporter-trace-otlp-http');
@@ -35,67 +34,86 @@ describe('maybeSetOtelProviders', () => {
3534
/**
3635
* Test initializing correct providers in maybeSetOtelProviders
3736
* when providing OTel env variables.
38-
*
37+
*
3938
* This test is parameterized to test different combinations of env variables
4039
* and verify that the correct providers are set up.
4140
*/
4241
const testCases: Array<{
43-
envVars: Record<string, string>;
44-
shouldSetupTrace: boolean;
42+
envVars: Record<string, string>; shouldSetupTrace: boolean;
4543
shouldSetupMetrics: boolean;
4644
shouldSetupLogs: boolean;
4745
description: string;
48-
}> = [
49-
{
50-
envVars: { OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'some-endpoint' },
51-
shouldSetupTrace: true,
52-
shouldSetupMetrics: false,
53-
shouldSetupLogs: false,
54-
description: 'should set up trace provider when OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is set',
55-
},
56-
{
57-
envVars: { OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: 'some-endpoint' },
58-
shouldSetupTrace: false,
59-
shouldSetupMetrics: true,
60-
shouldSetupLogs: false,
61-
description: 'should set up metrics provider when OTEL_EXPORTER_OTLP_METRICS_ENDPOINT is set',
62-
},
63-
{
64-
envVars: { OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: 'some-endpoint' },
65-
shouldSetupTrace: false,
66-
shouldSetupMetrics: false,
67-
shouldSetupLogs: true,
68-
description: 'should set up logs provider when OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is set',
69-
},
70-
{
71-
envVars: { OTEL_EXPORTER_OTLP_ENDPOINT: 'some-endpoint' },
72-
shouldSetupTrace: true,
73-
shouldSetupMetrics: true,
74-
shouldSetupLogs: true,
75-
description: 'should set up all providers when OTEL_EXPORTER_OTLP_ENDPOINT is set',
76-
},
77-
];
78-
79-
testCases.forEach(({ envVars, shouldSetupTrace, shouldSetupMetrics, shouldSetupLogs, description }) => {
80-
it(description, async () => {
81-
// Arrange
82-
Object.entries(envVars).forEach(([key, value]) => {
83-
vi.stubEnv(key, value);
84-
});
85-
86-
const traceProviderMock = vi.mocked(trace.setGlobalTracerProvider);
87-
const meterProviderMock = vi.mocked(metrics.setGlobalMeterProvider);
88-
const logsProviderMock = vi.mocked(logs.setGlobalLoggerProvider);
89-
90-
// Act
91-
await maybeSetOtelProviders();
92-
93-
// Assert
94-
expect(traceProviderMock).toHaveBeenCalledTimes(shouldSetupTrace ? 1 : 0);
95-
expect(meterProviderMock).toHaveBeenCalledTimes(shouldSetupMetrics ? 1 : 0);
96-
expect(logsProviderMock).toHaveBeenCalledTimes(shouldSetupLogs ? 1 : 0);
97-
});
98-
});
46+
}> =
47+
[
48+
{
49+
envVars: {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'some-endpoint'},
50+
shouldSetupTrace: true,
51+
shouldSetupMetrics: false,
52+
shouldSetupLogs: false,
53+
description:
54+
'should set up trace provider when OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is set',
55+
},
56+
{
57+
envVars: {OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: 'some-endpoint'},
58+
shouldSetupTrace: false,
59+
shouldSetupMetrics: true,
60+
shouldSetupLogs: false,
61+
description:
62+
'should set up metrics provider when OTEL_EXPORTER_OTLP_METRICS_ENDPOINT is set',
63+
},
64+
{
65+
envVars: {OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: 'some-endpoint'},
66+
shouldSetupTrace: false,
67+
shouldSetupMetrics: false,
68+
shouldSetupLogs: true,
69+
description:
70+
'should set up logs provider when OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is set',
71+
},
72+
{
73+
envVars: {OTEL_EXPORTER_OTLP_ENDPOINT: 'some-endpoint'},
74+
shouldSetupTrace: true,
75+
shouldSetupMetrics: true,
76+
shouldSetupLogs: true,
77+
description:
78+
'should set up all providers when OTEL_EXPORTER_OTLP_ENDPOINT is set',
79+
},
80+
];
81+
82+
testCases.forEach(
83+
({
84+
envVars,
85+
shouldSetupTrace,
86+
shouldSetupMetrics,
87+
shouldSetupLogs,
88+
description,
89+
}) => {
90+
it(description, async () => {
91+
// Arrange
92+
Object.entries(envVars).forEach(([key, value]) => {
93+
vi.stubEnv(key, value);
94+
});
95+
96+
const traceProviderMock = vi.mocked(trace.setGlobalTracerProvider);
97+
const meterProviderMock = vi.mocked(metrics.setGlobalMeterProvider);
98+
const logsProviderMock = vi.mocked(logs.setGlobalLoggerProvider);
99+
100+
// Act
101+
await maybeSetOtelProviders();
102+
103+
// Assert
104+
expect(traceProviderMock)
105+
.toHaveBeenCalledTimes(
106+
shouldSetupTrace ? 1 : 0,
107+
);
108+
expect(meterProviderMock)
109+
.toHaveBeenCalledTimes(
110+
shouldSetupMetrics ? 1 : 0,
111+
);
112+
expect(logsProviderMock)
113+
.toHaveBeenCalledTimes(shouldSetupLogs ? 1 : 0);
114+
});
115+
},
116+
);
99117

100118
it('should not set up any providers when no env vars are set', async () => {
101119
// Act
@@ -109,10 +127,29 @@ describe('maybeSetOtelProviders', () => {
109127

110128
it('should set up providers with custom hooks', async () => {
111129
// Arrange
112-
const mockSpanProcessor = { forceFlush: vi.fn() };
113-
const mockMetricReader = { forceFlush: vi.fn() };
114-
const mockLogProcessor = { forceFlush: vi.fn() };
115-
130+
const mockSpanProcessor = {
131+
forceFlush: vi.fn(),
132+
onStart: vi.fn(),
133+
onEnd: vi.fn(),
134+
shutdown: vi.fn(),
135+
};
136+
const mockMetricReader = {
137+
forceFlush: vi.fn(),
138+
setMetricProducer: vi.fn(),
139+
selectAggregation: vi.fn(),
140+
selectAggregationTemporality: vi.fn(),
141+
selectCardinalityLimit: vi.fn(),
142+
collect: vi.fn(),
143+
shutdown: vi.fn(),
144+
} as unknown as any;
145+
const mockLogProcessor = {
146+
forceFlush: vi.fn(),
147+
onStart: vi.fn(),
148+
onEnd: vi.fn(),
149+
shutdown: vi.fn(),
150+
onEmit: vi.fn(),
151+
};
152+
116153
const hooks: OTelHooks = {
117154
spanProcessors: [mockSpanProcessor],
118155
metricReaders: [mockMetricReader],
@@ -127,4 +164,4 @@ describe('maybeSetOtelProviders', () => {
127164
expect(metrics.setGlobalMeterProvider).toHaveBeenCalledTimes(1);
128165
expect(logs.setGlobalLoggerProvider).toHaveBeenCalledTimes(1);
129166
});
130-
});
167+
});

0 commit comments

Comments
 (0)