Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getTracesFacetsResultAtom,
listMetricsResultAtom,
} from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

type StatAggregate = "sum" | "first" | "count" | "avg" | "max" | "min"

Expand Down Expand Up @@ -310,6 +311,7 @@ export function WidgetQueryBuilderPage({
onApply,
onCancel,
}: WidgetQueryBuilderPageProps) {
const orgId = useOrgId()
const [state, setState] = React.useState<QueryBuilderWidgetState>(() => toInitialState(widget))
const [stagedState, setStagedState] = React.useState<QueryBuilderWidgetState>(() =>
cloneWidgetState(toInitialState(widget))
Expand All @@ -318,15 +320,15 @@ export function WidgetQueryBuilderPage({
const [collapsedQueries, setCollapsedQueries] = React.useState<Set<string>>(new Set())

const metricsResult = useAtomValue(
listMetricsResultAtom({ data: { limit: 300 } }),
listMetricsResultAtom({ data: { limit: 300 } }, orgId),
)

const tracesFacetsResult = useAtomValue(
getTracesFacetsResultAtom({ data: {} }),
getTracesFacetsResultAtom({ data: {} }, orgId),
)

const logsFacetsResult = useAtomValue(
getLogsFacetsResultAtom({ data: {} }),
getLogsFacetsResultAtom({ data: {} }, orgId),
)

const metricRows = React.useMemo(
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/dashboard/service-usage-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Card, CardContent, CardHeader, CardTitle } from "@maple/ui/components/ui/card"
import { Skeleton } from "@maple/ui/components/ui/skeleton"
import { getServiceUsageResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

function formatNumber(num: number): string {
if (num >= 1_000_000) {
Expand Down Expand Up @@ -66,8 +67,9 @@ interface ServiceUsageCardsProps {
}

export function ServiceUsageCards({ startTime, endTime }: ServiceUsageCardsProps = {}) {
const orgId = useOrgId()
const responseResult = useAtomValue(
getServiceUsageResultAtom({ data: { startTime, endTime } }),
getServiceUsageResultAtom({ data: { startTime, endTime } }, orgId),
)

return Result.builder(responseResult)
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/components/errors/errors-by-type-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getErrorDetailTracesResultAtom,
getErrorsByTypeResultAtom,
} from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

function formatNumber(num: number): string {
if (num >= 1_000_000) {
Expand All @@ -45,6 +46,7 @@ interface ErrorsByTypeTableProps {
}

function ErrorDetailPanel({ errorRow, filters }: { errorRow: ErrorByType; filters: GetErrorsByTypeInput }) {
const orgId = useOrgId()
const detailResult = useAtomValue(
getErrorDetailTracesResultAtom({
data: {
Expand All @@ -54,7 +56,7 @@ function ErrorDetailPanel({ errorRow, filters }: { errorRow: ErrorByType; filter
services: filters.services,
limit: 5,
},
}),
}, orgId),
)

return (
Expand Down Expand Up @@ -197,9 +199,10 @@ function LoadingState() {
}

export function ErrorsByTypeTable({ filters }: ErrorsByTypeTableProps) {
const orgId = useOrgId()
const [expandedError, setExpandedError] = useState<string | null>(null)

const errorsResult = useAtomValue(getErrorsByTypeResultAtom({ data: filters }))
const errorsResult = useAtomValue(getErrorsByTypeResultAtom({ data: filters }, orgId))

return Result.builder(errorsResult)
.onInitial(() => <LoadingState />)
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/errors/errors-filter-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
FilterSidebarHeader,
FilterSidebarLoading,
} from "@/components/filters/filter-sidebar"
import { useOrgId } from "@/hooks/use-org-id"

function LoadingState() {
return <FilterSidebarLoading sectionCount={3} />
}

export function ErrorsFilterSidebar() {
const orgId = useOrgId()
const navigate = useNavigate({ from: Route.fullPath })
const search = Route.useSearch()
const { startTime: effectiveStartTime, endTime: effectiveEndTime } =
Expand All @@ -31,7 +33,7 @@ export function ErrorsFilterSidebar() {
endTime: effectiveEndTime,
showSpam: search.showSpam,
},
}),
}, orgId),
)

const updateFilter = <K extends keyof typeof search>(
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/errors/errors-summary-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@maple/ui/components/u
import { Skeleton } from "@maple/ui/components/ui/skeleton"
import { type GetErrorsSummaryInput } from "@/api/tinybird/errors"
import { getErrorsSummaryResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

function formatNumber(num: number): string {
if (num >= 1_000_000) {
Expand All @@ -36,7 +37,8 @@ interface ErrorsSummaryCardsProps {
}

export function ErrorsSummaryCards({ filters }: ErrorsSummaryCardsProps) {
const summaryResult = useAtomValue(getErrorsSummaryResultAtom({ data: filters }))
const orgId = useOrgId()
const summaryResult = useAtomValue(getErrorsSummaryResultAtom({ data: filters }, orgId))

return Result.builder(summaryResult)
.onInitial(() => (
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/logs/logs-filter-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FilterSidebarLoading,
} from "@/components/filters/filter-sidebar"
import { SEVERITY_COLORS } from "@/lib/severity"
import { useOrgId } from "@/hooks/use-org-id"

function LoadingState() {
return <FilterSidebarLoading sectionCount={3} sticky />
Expand All @@ -27,6 +28,7 @@ function LoadingState() {
export function LogsFilterSidebar() {
const navigate = useNavigate({ from: Route.fullPath })
const search = Route.useSearch()
const orgId = useOrgId()
const { startTime: effectiveStartTime, endTime: effectiveEndTime } =
useEffectiveTimeRange(search.startTime, search.endTime)

Expand Down Expand Up @@ -54,7 +56,7 @@ export function LogsFilterSidebar() {
startTime: effectiveStartTime,
endTime: effectiveEndTime,
},
}),
}, orgId),
)

const updateFilter = <K extends keyof typeof search>(
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/logs/logs-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { LogsSearchParams } from "@/routes/logs"
import { listLogsResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useTimezonePreference } from "@/hooks/use-timezone-preference"
import { formatTimestampInTimezone } from "@/lib/timezone-format"
import { useOrgId } from "@/hooks/use-org-id"

function truncateBody(body: string, maxLength = 100): string {
if (body.length <= maxLength) return body
Expand Down Expand Up @@ -61,6 +62,7 @@ export function LogsTable({ filters }: LogsTableProps) {
const [selectedLog, setSelectedLog] = useState<Log | null>(null)
const [sheetOpen, setSheetOpen] = useState(false)
const { effectiveTimezone } = useTimezonePreference()
const orgId = useOrgId()

const { startTime: effectiveStartTime, endTime: effectiveEndTime } =
useEffectiveTimeRange(filters?.startTime, filters?.endTime)
Expand All @@ -74,7 +76,7 @@ export function LogsTable({ filters }: LogsTableProps) {
severity: filters?.severities?.[0],
search: filters?.search,
},
}),
}, orgId),
)

const handleRowClick = (log: Log) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/logs/logs-volume-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@/lib/format"
import type { LogsSearchParams } from "@/routes/logs"
import { SEVERITY_COLORS, SEVERITY_ORDER } from "@/lib/severity"
import { useOrgId } from "@/hooks/use-org-id"

/** More bars than the default 40-point target for a denser histogram. */
const HISTOGRAM_TARGET_POINTS = 150
Expand All @@ -41,6 +42,7 @@ interface LogsVolumeChartProps {
}

export function LogsVolumeChart({ filters }: LogsVolumeChartProps) {
const orgId = useOrgId()
const { startTime: effectiveStartTime, endTime: effectiveEndTime } =
useEffectiveTimeRange(filters?.startTime, filters?.endTime)

Expand All @@ -63,7 +65,7 @@ export function LogsVolumeChart({ filters }: LogsVolumeChartProps) {
severity: filters?.severities?.[0],
},
},
}),
}, orgId),
)

return Result.builder(timeSeriesResult)
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/metrics/metrics-summary-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@maple/ui/components/u
import { Skeleton } from "@maple/ui/components/ui/skeleton"
import { type ListMetricsInput } from "@/api/tinybird/metrics"
import { getMetricsSummaryResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

export type MetricType = ListMetricsInput["metricType"]

Expand Down Expand Up @@ -52,7 +53,8 @@ interface MetricsSummaryCardsProps {
}

export function MetricsSummaryCards({ selectedType, onSelectType }: MetricsSummaryCardsProps) {
const summaryResult = useAtomValue(getMetricsSummaryResultAtom({ data: {} }))
const orgId = useOrgId()
const summaryResult = useAtomValue(getMetricsSummaryResultAtom({ data: {} }, orgId))

return Result.builder(summaryResult)
.onInitial(() => (
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/metrics/metrics-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Badge } from "@maple/ui/components/ui/badge"
import { MetricTypeBadge } from "./metric-type-badge"
import { type Metric, type ListMetricsInput } from "@/api/tinybird/metrics"
import { listMetricsResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

function formatNumber(num: number): string {
if (num >= 1_000_000) {
Expand Down Expand Up @@ -81,14 +82,15 @@ export function MetricsTable({
selectedMetric,
onSelectMetric,
}: MetricsTableProps) {
const orgId = useOrgId()
const metricsResult = useAtomValue(
listMetricsResultAtom({
data: {
search: search || undefined,
metricType: metricType || undefined,
limit: 100,
},
}),
}, orgId),
)

return Result.builder(metricsResult)
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/metrics/metrics-volume-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Skeleton } from "@maple/ui/components/ui/skeleton"
import { type GetMetricTimeSeriesInput, type MetricTimeSeriesResponse } from "@/api/tinybird/metrics"
import { disabledResultAtom } from "@/lib/services/atoms/disabled-result-atom"
import { getMetricTimeSeriesResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"

const chartConfig = {
avgValue: {
Expand All @@ -30,6 +31,7 @@ interface MetricsVolumeChartProps {
}

export function MetricsVolumeChart({ metricName, metricType }: MetricsVolumeChartProps) {
const orgId = useOrgId()
const chartResult = useAtomValue(
metricName && metricType
? getMetricTimeSeriesResultAtom({
Expand All @@ -38,7 +40,7 @@ export function MetricsVolumeChart({ metricName, metricType }: MetricsVolumeChar
metricType,
bucketSeconds: 60,
},
})
}, orgId)
: disabledResultAtom<MetricTimeSeriesResponse>(),
)

Expand Down
19 changes: 11 additions & 8 deletions apps/web/src/components/query-builder/query-builder-lab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react"
import { Result, useAtomValue } from "@effect-atom/atom-react"
import { PulseIcon, XmarkIcon, PlusIcon, MagnifierIcon } from "@/components/icons"
import { useOrgId } from "@/hooks/use-org-id"

import { Badge } from "@maple/ui/components/ui/badge"
import { Button } from "@maple/ui/components/ui/button"
Expand Down Expand Up @@ -331,8 +332,9 @@ function QueryBuilderAtomResults({
}: {
input: QueryBuilderTimeseriesInput
}) {
const orgId = useOrgId()
const result = useAtomValue(
getQueryBuilderTimeseriesResultAtom({ data: input }),
getQueryBuilderTimeseriesResultAtom({ data: input }, orgId),
)

return (
Expand Down Expand Up @@ -421,6 +423,7 @@ export function QueryBuilderLab({
startTime,
endTime,
}: QueryBuilderLabProps) {
const orgId = useOrgId()
const [queries, setQueries] = React.useState<QueryDraft[]>([
createQuery(0),
createQuery(1),
Expand All @@ -442,7 +445,7 @@ export function QueryBuilderLab({
data: {
limit: 300,
},
}),
}, orgId),
)

const tracesFacetsResult = useAtomValue(
Expand All @@ -451,7 +454,7 @@ export function QueryBuilderLab({
startTime,
endTime,
},
}),
}, orgId),
)

const logsFacetsResult = useAtomValue(
Expand All @@ -460,7 +463,7 @@ export function QueryBuilderLab({
startTime,
endTime,
},
}),
}, orgId),
)

const spanAttributeKeysResult = useAtomValue(
Expand All @@ -469,7 +472,7 @@ export function QueryBuilderLab({
startTime,
endTime,
},
}),
}, orgId),
)

const [activeAttributeKey, setActiveAttributeKey] = React.useState<string | null>(null)
Expand All @@ -482,7 +485,7 @@ export function QueryBuilderLab({
endTime,
attributeKey: activeAttributeKey ?? "",
},
}),
}, orgId),
)

const resourceAttributeKeysResult = useAtomValue(
Expand All @@ -491,7 +494,7 @@ export function QueryBuilderLab({
startTime,
endTime,
},
}),
}, orgId),
)

const resourceAttributeValuesResult = useAtomValue(
Expand All @@ -501,7 +504,7 @@ export function QueryBuilderLab({
endTime,
attributeKey: activeResourceAttributeKey ?? "",
},
}),
}, orgId),
)

const attributeKeys = React.useMemo(
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/service-map/service-map-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Result, useAtomValue } from "@effect-atom/atom-react"

import { getServiceLegendColor } from "@maple/ui/colors"
import { getServiceMapResultAtom, getServiceOverviewResultAtom } from "@/lib/services/atoms/tinybird-query-atoms"
import { useOrgId } from "@/hooks/use-org-id"
import type { GetServiceMapInput, ServiceEdge } from "@/api/tinybird/service-map"
import type { GetServiceOverviewInput, ServiceOverview } from "@/api/tinybird/services"
import { ServiceMapNode } from "./service-map-node"
Expand Down Expand Up @@ -169,6 +170,7 @@ function ServiceMapCanvas({
}

export function ServiceMapView({ startTime, endTime }: ServiceMapViewProps) {
const orgId = useOrgId()
const durationSeconds = useMemo(() => {
const ms = new Date(endTime).getTime() - new Date(startTime).getTime()
return Math.max(1, ms / 1000)
Expand All @@ -184,8 +186,8 @@ export function ServiceMapView({ startTime, endTime }: ServiceMapViewProps) {
[startTime, endTime],
)

const mapResult = useAtomValue(getServiceMapResultAtom(mapInput))
const overviewResult = useAtomValue(getServiceOverviewResultAtom(overviewInput))
const mapResult = useAtomValue(getServiceMapResultAtom(mapInput, orgId))
const overviewResult = useAtomValue(getServiceOverviewResultAtom(overviewInput, orgId))

// Both need to be loaded for the view
return Result.builder(mapResult)
Expand Down
Loading