|
| 1 | +import { getPhoenixTracer } from './handler' |
| 2 | + |
| 3 | +jest.mock('@opentelemetry/exporter-trace-otlp-proto', () => { |
| 4 | + return { |
| 5 | + ProtoOTLPTraceExporter: jest.fn().mockImplementation((args) => { |
| 6 | + return { args } |
| 7 | + }) |
| 8 | + } |
| 9 | +}) |
| 10 | + |
| 11 | +import { OTLPTraceExporter as ProtoOTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' |
| 12 | + |
| 13 | +describe('URL Handling For Phoenix Tracer', () => { |
| 14 | + const apiKey = 'test-api-key' |
| 15 | + const projectName = 'test-project-name' |
| 16 | + |
| 17 | + const makeOptions = (baseUrl: string) => ({ |
| 18 | + baseUrl, |
| 19 | + apiKey, |
| 20 | + projectName, |
| 21 | + enableCallback: false |
| 22 | + }) |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + jest.clearAllMocks() |
| 26 | + }) |
| 27 | + |
| 28 | + const cases: [string, string][] = [ |
| 29 | + ['http://localhost:6006', 'http://localhost:6006/v1/traces'], |
| 30 | + ['http://localhost:6006/v1/traces', 'http://localhost:6006/v1/traces'], |
| 31 | + ['https://app.phoenix.arize.com', 'https://app.phoenix.arize.com/v1/traces'], |
| 32 | + ['https://app.phoenix.arize.com/v1/traces', 'https://app.phoenix.arize.com/v1/traces'], |
| 33 | + ['https://app.phoenix.arize.com/s/my-space', 'https://app.phoenix.arize.com/s/my-space/v1/traces'], |
| 34 | + ['https://app.phoenix.arize.com/s/my-space/v1/traces', 'https://app.phoenix.arize.com/s/my-space/v1/traces'], |
| 35 | + ['https://my-phoenix.com/my-slug', 'https://my-phoenix.com/my-slug/v1/traces'], |
| 36 | + ['https://my-phoenix.com/my-slug/v1/traces', 'https://my-phoenix.com/my-slug/v1/traces'] |
| 37 | + ] |
| 38 | + |
| 39 | + it.each(cases)('baseUrl %s - exporterUrl %s', (input, expected) => { |
| 40 | + getPhoenixTracer(makeOptions(input)) |
| 41 | + expect(ProtoOTLPTraceExporter).toHaveBeenCalledWith( |
| 42 | + expect.objectContaining({ |
| 43 | + url: expected, |
| 44 | + headers: expect.objectContaining({ |
| 45 | + api_key: apiKey, |
| 46 | + authorization: `Bearer ${apiKey}` |
| 47 | + }) |
| 48 | + }) |
| 49 | + ) |
| 50 | + }) |
| 51 | +}) |
0 commit comments