mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
## Summary Large refactor changing the TSource type to a true discriminated union. This means that the expected fields for `kind: 'log'` will differ from those for `'trace', 'session', 'metrics'`. This avoids the current laissez faire source type that currently exists, and required extensive changes across the api and app packages. Also includes a nice addition to `useSource` - you can now specify a `kind` field, which will properly infer the type of the returned source. This also makes use of discriminators in mongoose. This does change a bit of the way that we create and update sources. Obvious changes to sources have also been made, namely making `timeValueExpression` required on sources. Care has been taken to avoid requiring a migration. ### How to test locally or on Vercel 1. `yarn dev` 2. Play around with the app, especially around source creation, source edits, and loading existing sources from a previous version ### References - Linear Issue: References HDX-3352 - Related PRs: Ref: HDX-3352
31 lines
973 B
TypeScript
31 lines
973 B
TypeScript
import { SourceKind, TTraceSource } from '@hyperdx/common-utils/dist/types';
|
|
|
|
import { getEventBody } from '../source';
|
|
|
|
describe('getEventBody', () => {
|
|
// Added to prevent regression back to HDX-3361
|
|
it('returns spanNameExpression for trace kind source when both bodyExpression and spanNameExpression are present', () => {
|
|
const source = {
|
|
kind: SourceKind.Trace,
|
|
from: {
|
|
databaseName: 'default',
|
|
tableName: 'otel_traces',
|
|
},
|
|
timestampValueExpression: 'Timestamp',
|
|
connection: 'test-connection',
|
|
name: 'Traces',
|
|
id: 'test-source-id',
|
|
spanNameExpression: 'SpanName',
|
|
durationExpression: 'Duration',
|
|
durationPrecision: 9,
|
|
traceIdExpression: 'TraceId',
|
|
spanIdExpression: 'SpanId',
|
|
parentSpanIdExpression: 'ParentSpanId',
|
|
spanKindExpression: 'SpanKind',
|
|
} as TTraceSource;
|
|
|
|
const result = getEventBody(source);
|
|
|
|
expect(result).toBe('SpanName');
|
|
});
|
|
});
|