mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
feat: add session source and SourceKind enum (#595)
<img width="704" alt="Screenshot 2025-02-03 at 5 23 58 PM" src="https://github.com/user-attachments/assets/832dc5e8-dee4-438f-8ff7-a170da0578c4" />
This commit is contained in:
parent
c3b6fef4e0
commit
621bd55faa
7 changed files with 44 additions and 17 deletions
5
.changeset/funny-dolls-explode.md
Normal file
5
.changeset/funny-dolls-explode.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hyperdx/common-utils": patch
|
||||
---
|
||||
|
||||
feat: add session source and SourceKind enum
|
||||
|
|
@ -47,6 +47,7 @@ export const Source = mongoose.model<ISource>(
|
|||
traceIdExpression: String,
|
||||
spanIdExpression: String,
|
||||
traceSourceId: String,
|
||||
sessionSourceId: String,
|
||||
|
||||
durationExpression: String,
|
||||
durationPrecision: Number,
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ describe('checkAlerts', () => {
|
|||
},
|
||||
source: {
|
||||
id: 'fake-source-id' as any,
|
||||
kind: 'log',
|
||||
kind: 'log' as any,
|
||||
team: 'team-123' as any,
|
||||
from: {
|
||||
databaseName: 'default',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { SourceKind } from '@hyperdx/common-utils/dist/types';
|
||||
import { Button, Divider, Modal, Text } from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
|
||||
|
|
@ -100,7 +101,7 @@ export default function OnboardingModal({
|
|||
});
|
||||
const traceSource = await createSourceMutation.mutateAsync({
|
||||
source: {
|
||||
kind: 'trace',
|
||||
kind: SourceKind.Trace,
|
||||
name: 'Demo Traces',
|
||||
connection: 'local',
|
||||
from: {
|
||||
|
|
@ -128,7 +129,7 @@ export default function OnboardingModal({
|
|||
});
|
||||
await createSourceMutation.mutateAsync({
|
||||
source: {
|
||||
kind: 'log',
|
||||
kind: SourceKind.Log,
|
||||
name: 'Demo Logs',
|
||||
connection: 'local',
|
||||
from: {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
UseFormSetValue,
|
||||
UseFormWatch,
|
||||
} from 'react-hook-form';
|
||||
import { TSource } from '@hyperdx/common-utils/dist/types';
|
||||
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
|
||||
import {
|
||||
Anchor,
|
||||
Box,
|
||||
|
|
@ -27,6 +27,7 @@ import { useDebouncedCallback } from '@mantine/hooks';
|
|||
import { notifications } from '@mantine/notifications';
|
||||
|
||||
import { SourceSelectControlled } from '@/components/SourceSelect';
|
||||
import { IS_SESSIONS_ENABLED } from '@/config';
|
||||
import { useConnections } from '@/connection';
|
||||
import {
|
||||
inferTableSourceConfig,
|
||||
|
|
@ -462,6 +463,12 @@ export function TraceTableModelForm({
|
|||
>
|
||||
<SourceSelectControlled control={control} name="logSourceId" />
|
||||
</FormRow>
|
||||
<FormRow
|
||||
label={'Correlated Session Source'}
|
||||
helpText="HyperDX Source for sessions associated with traces. Optional"
|
||||
>
|
||||
<SourceSelectControlled control={control} name="sessionSourceId" />
|
||||
</FormRow>
|
||||
<FormRow label={'Status Code Expression'}>
|
||||
<SQLInlineEditorControlled
|
||||
connectionId={connectionId}
|
||||
|
|
@ -550,7 +557,7 @@ export function TableSourceForm({
|
|||
const { watch, control, setValue, handleSubmit, resetField, formState } =
|
||||
useForm<TSource>({
|
||||
defaultValues: {
|
||||
kind: 'log',
|
||||
kind: SourceKind.Log,
|
||||
name: defaultName,
|
||||
connection: connections?.[0]?.id,
|
||||
from: {
|
||||
|
|
@ -608,7 +615,7 @@ export function TableSourceForm({
|
|||
resetField('connection', { defaultValue: connections?.[0]?.id });
|
||||
}, [connections, resetField]);
|
||||
|
||||
const kind = watch('kind');
|
||||
const kind: SourceKind = watch('kind');
|
||||
|
||||
const createSource = useCreateSource();
|
||||
const updateSource = useUpdateSource();
|
||||
|
|
@ -724,25 +731,22 @@ export function TableSourceForm({
|
|||
render={({ field: { onChange, value } }) => (
|
||||
<Radio.Group
|
||||
value={value}
|
||||
onChange={v => onChange(v as 'log' | 'trace')}
|
||||
onChange={v => onChange(v)}
|
||||
withAsterisk
|
||||
>
|
||||
<Group>
|
||||
<Radio value="log" label="Log" />
|
||||
<Radio value="trace" label="Trace" />
|
||||
<Radio value={SourceKind.Log} label="Log" />
|
||||
<Radio value={SourceKind.Trace} label="Trace" />
|
||||
{IS_SESSIONS_ENABLED && (
|
||||
<Radio value={SourceKind.Session} label="Session" />
|
||||
)}
|
||||
</Group>
|
||||
</Radio.Group>
|
||||
)}
|
||||
/>
|
||||
</FormRow>
|
||||
</Stack>
|
||||
{kind === 'log' ? (
|
||||
<LogTableModelForm
|
||||
control={control}
|
||||
watch={watch}
|
||||
setValue={setValue}
|
||||
/>
|
||||
) : (
|
||||
{kind === SourceKind.Trace ? (
|
||||
<TraceTableModelForm
|
||||
// @ts-ignore
|
||||
control={control}
|
||||
|
|
@ -751,6 +755,12 @@ export function TableSourceForm({
|
|||
// @ts-ignore
|
||||
setValue={setValue}
|
||||
/>
|
||||
) : (
|
||||
<LogTableModelForm
|
||||
control={control}
|
||||
watch={watch}
|
||||
setValue={setValue}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -27,3 +27,5 @@ export const IS_LOCAL_MODE = //true;
|
|||
|
||||
// Features in development
|
||||
export const IS_MTVIEWS_ENABLED = false;
|
||||
|
||||
export const IS_SESSIONS_ENABLED = false || IS_DEV;
|
||||
|
|
|
|||
|
|
@ -392,6 +392,11 @@ export const ConnectionSchema = z.object({
|
|||
// --------------------------
|
||||
// TABLE SOURCES
|
||||
// --------------------------
|
||||
export enum SourceKind {
|
||||
Log = 'log',
|
||||
Trace = 'trace',
|
||||
Session = 'session',
|
||||
}
|
||||
export const SourceSchema = z.object({
|
||||
from: z.object({
|
||||
databaseName: z.string(),
|
||||
|
|
@ -401,7 +406,7 @@ export const SourceSchema = z.object({
|
|||
connection: z.string(),
|
||||
|
||||
// Common
|
||||
kind: z.enum(['log', 'trace']),
|
||||
kind: z.nativeEnum(SourceKind),
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
displayedTimestampValueExpression: z.string().optional(),
|
||||
|
|
@ -422,6 +427,9 @@ export const SourceSchema = z.object({
|
|||
traceIdExpression: z.string().optional(),
|
||||
spanIdExpression: z.string().optional(),
|
||||
|
||||
// Sessions
|
||||
sessionSourceId: z.string().optional(),
|
||||
|
||||
// Traces
|
||||
durationExpression: z.string().optional(),
|
||||
durationPrecision: z.number().min(0).max(9).optional(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue