Skip to content
Merged
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
@@ -1,5 +1,6 @@
import { FC, useRef, useState } from "preact/compat";
import { useSearchParams } from "react-router-dom";
import { ACCOUNT_ID_URL_PARAM, PROJECT_ID_URL_PARAM } from "../../../../constants/tenant";
import { useFetchAccountIds } from "./hooks/useFetchAccountIds";
import TenantsSelect from "./TenantsSelect";
import TenantsFields from "./TenantsFields";
Expand All @@ -23,8 +24,8 @@ const Tenants: FC = () => {
const { isMobile } = useDeviceDetect();

const [searchParams, setSearchParams] = useSearchParams();
const accountId = searchParams.get("accountID") || "0";
const projectId = searchParams.get("projectID") || "0";
const accountId = searchParams.get(ACCOUNT_ID_URL_PARAM) || "0";
const projectId = searchParams.get(PROJECT_ID_URL_PARAM) || "0";
const tenantId = `${accountId}:${projectId}`;

const buttonRef = useRef<HTMLDivElement>(null);
Expand All @@ -40,8 +41,8 @@ const Tenants: FC = () => {

const onChange = ({ accountId, projectId }: Partial<TenantType>) => {
if (!isValidTenantId(accountId) || !isValidTenantId(projectId)) return;
if (accountId) searchParams.set("accountID", accountId);
if (projectId) searchParams.set("projectID", projectId);
if (accountId) searchParams.set(ACCOUNT_ID_URL_PARAM, accountId);
if (projectId) searchParams.set(PROJECT_ID_URL_PARAM, projectId);
setSearchParams(searchParams);
handleClosePopup();
};
Expand Down
2 changes: 2 additions & 0 deletions app/vmui/packages/vmui/src/constants/tenant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ACCOUNT_ID_URL_PARAM = "accountID";
export const PROJECT_ID_URL_PARAM = "projectID";
2 changes: 2 additions & 0 deletions app/vmui/packages/vmui/src/constants/trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TRACE_ID_URL_PARAM = "trace_id";
export const SPAN_ID_URL_PARAM = "span_id";
16 changes: 16 additions & 0 deletions app/vmui/packages/vmui/src/hooks/useTenant.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest";
import { buildTraceLocation } from "./useTenant";

describe("buildTraceLocation", () => {
it("keeps the tenant and trace id, drops other params, and adds span_id only when given", () => {
const source = new URLSearchParams("g0.range_input=5m&accountID=193&projectID=20");

expect(buildTraceLocation(source, "abc")).toEqual({
pathname: "/trace",
search: "accountID=193&projectID=20&trace_id=abc",
});
expect(buildTraceLocation(source, "abc", "span1").search).toBe(
"accountID=193&projectID=20&trace_id=abc&span_id=span1"
);
});
});
26 changes: 20 additions & 6 deletions app/vmui/packages/vmui/src/hooks/useTenant.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { useMemo } from "preact/compat";
import { useSearchParams } from "react-router-dom";
import { ACCOUNT_ID_URL_PARAM, PROJECT_ID_URL_PARAM } from "../constants/tenant";
import { SPAN_ID_URL_PARAM, TRACE_ID_URL_PARAM } from "../constants/trace";
import router from "../router";

export const getTenantSearchParams = (source: URLSearchParams): URLSearchParams => {
const params = new URLSearchParams();
const accountID = source.get("accountID");
const projectID = source.get("projectID");
if (accountID) params.set("accountID", accountID);
if (projectID) params.set("projectID", projectID);
const accountID = source.get(ACCOUNT_ID_URL_PARAM);
const projectID = source.get(PROJECT_ID_URL_PARAM);
if (accountID) params.set(ACCOUNT_ID_URL_PARAM, accountID);
if (projectID) params.set(PROJECT_ID_URL_PARAM, projectID);
return params;
Comment thread
mastersans marked this conversation as resolved.
Resolved
};

export const buildTraceLocation = (
source: URLSearchParams,
traceID: string,
spanID?: string,
): { pathname: string, search: string } => {
const params = getTenantSearchParams(source);
params.set(TRACE_ID_URL_PARAM, traceID);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
if (spanID) params.set(SPAN_ID_URL_PARAM, spanID);
return { pathname: router.trace, search: params.toString() };
};
Comment thread
mastersans marked this conversation as resolved.
Resolved

export const useTenant = () => {
const [searchParams] = useSearchParams();

const accountID = searchParams.get("accountID") || "0";
const projectID = searchParams.get("projectID") || "0";
const accountID = searchParams.get(ACCOUNT_ID_URL_PARAM) || "0";
const projectID = searchParams.get(PROJECT_ID_URL_PARAM) || "0";

return useMemo(() => ({
AccountID: accountID,
Expand Down
27 changes: 10 additions & 17 deletions app/vmui/packages/vmui/src/layouts/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, useMemo } from "preact/compat";
import { NavLink, useNavigate } from "react-router-dom";
import { NavLink, To, useSearchParams } from "react-router-dom";
import router from "../../router";
import { getTenantSearchParams } from "../../hooks/useTenant";
import { getAppModeEnable, getAppModeParams } from "../../utils/app-mode";
import { LogoTracesIcon } from "../../components/Main/Icons";
import { getCssVariable } from "../../utils/theme";
Expand All @@ -13,7 +14,7 @@ import HeaderControls from "./HeaderControls";
import useDeviceDetect from "../../hooks/useDeviceDetect";
import useWindowSize from "../../hooks/useWindowSize";

const Logo = () => <NavLink to={router.home}><LogoTracesIcon/></NavLink>;
const Logo = ({ to }: { to: To }) => <NavLink to={to}><LogoTracesIcon/></NavLink>;

const Header: FC = () => {
const { isMobile } = useDeviceDetect();
Expand All @@ -39,17 +40,11 @@ const Header: FC = () => {
return { background, color };
}, [primaryColor, appModeEnable]);

const navigate = useNavigate();

const onClickLogo = (e: MouseEvent) => {
const { ctrlKey, metaKey } = e;
const ctrlMetaKey = ctrlKey || metaKey;
if (ctrlMetaKey) return; // open in new tab

e.preventDefault();
navigate({ pathname: router.home });
window.location.reload();
};
const [searchParams] = useSearchParams();
const homeLocation = useMemo(() => ({
pathname: router.home,
search: getTenantSearchParams(searchParams).toString(),
}), [searchParams]);

return <header
className={classNames({
Expand All @@ -71,10 +66,9 @@ const Header: FC = () => {
{!appModeEnable && (
<div
className="vm-header-logo"
onClick={onClickLogo}
style={{ color }}
>
{<Logo/>}
{<Logo to={homeLocation}/>}
</div>
)}
<HeaderNav
Expand All @@ -89,10 +83,9 @@ const Header: FC = () => {
"vm-header-logo": true,
"vm-header-logo_mobile": true,
})}
onClick={onClickLogo}
style={{ color }}
>
{<Logo/>}
{<Logo to={homeLocation}/>}
</div>
)}
<HeaderControls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import DragResizeHandle from "../../../components/Main/DragResizeHandle";
import ApiErrorAlert from "../components/ApiErrorAlert";
import { SpinnerIcon } from "../../../components/Main/Icons";
import filterSpans, { getSpanIdFromSearchParams } from "../utils";
import { TRACE_ID_URL_PARAM } from "../../../constants/trace";
import { CriticalPathSection, OtelSpan, OtelTrace, ViewRange } from "../types";

import "../style.scss";
import "./style.scss";

const TRACE_ID_URL_PARAM = "trace_id";
const noop = () => {};

// Returns a view of `trace` scoped to `isolatedSpanID` and its descendants — the picked
Expand Down
14 changes: 6 additions & 8 deletions app/vmui/packages/vmui/src/pages/TraceExplorer/TraceExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, useCallback, useEffect, useMemo, useRef, useState } from "preact/compat";
import { useNavigate, useSearchParams } from "react-router-dom";
import { buildTraceLocation } from "../../hooks/useTenant";
import TraceExplorerHeader from "./components/TraceExplorerHeader";
import { TRACE_QUERY_URL_PARAMS, useTraceQueryState } from "./hooks/useTraceQueryState";
import TracesResultsTable from "./components/TracesResultsTable";
Expand Down Expand Up @@ -33,6 +34,9 @@ const TraceExplorer: FC = () => {
const { limit, setLimit } = useLimitController();
const { executeQueryTrigger } = useQueryState();
const navigate = useNavigate();
const openTrace = useCallback((traceID: string) => {
navigate(buildTraceLocation(searchParams, traceID), { state: { autoRun: true } });
}, [navigate, searchParams]);
const { isVisible: isFiltersSidebarVisible, setVisible: setFiltersSidebarVisible } = useFiltersSidebarVisible();

const { query, setQuery } = useTraceQueryState();
Expand Down Expand Up @@ -224,10 +228,7 @@ const TraceExplorer: FC = () => {
results={displayedTraces}
activeTraceID={selectedTraceId}
onClickRow={row => setSelectedTraceId(row.traceID)}
onOpenTrace={row => navigate(
`/trace?trace_id=${encodeURIComponent(row.traceID)}`,
{ state: { autoRun: true } }
)}
onOpenTrace={row => openTrace(row.traceID)}
/>
)}
</div>
Expand All @@ -238,10 +239,7 @@ const TraceExplorer: FC = () => {
periodStart={period.start}
periodEnd={period.end}
onClose={() => setSelectedTraceId("")}
onViewFullTrace={() => navigate(
`/trace?trace_id=${encodeURIComponent(selectedTrace.traceID)}`,
{ state: { autoRun: true } }
)}
onViewFullTrace={() => openTrace(selectedTrace.traceID)}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CSSProperties, RefObject, useMemo, useState } from "preact/compat";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import { buildTraceLocation } from "../../../../hooks/useTenant";

import { useAvailableHeight } from "../../hooks/useAvailableHeight";
import Tabs from "../../../../components/Main/Tabs";
Expand Down Expand Up @@ -38,6 +39,7 @@ const SpanDetailPanel = ({ span, panelRef, width, onClose }: SpanDetailPanelProp
const [showAbsoluteTime, setShowAbsoluteTime] = useState(false);
const [prevSpanID, setPrevSpanID] = useState(span.spanID);
const navigate = useNavigate();
const [searchParams] = useSearchParams();

const { height, top } = useAvailableHeight(panelRef);
const panelStyle: CSSProperties = useMemo(() => {
Expand Down Expand Up @@ -81,10 +83,7 @@ const SpanDetailPanel = ({ span, panelRef, width, onClose }: SpanDetailPanelProp
};

const openLinkedTrace = (link: Link) => {
navigate(
`/trace?trace_id=${encodeURIComponent(link.traceID)}&span_id=${encodeURIComponent(link.spanID)}`,
{ state: { autoRun: true } }
);
navigate(buildTraceLocation(searchParams, link.traceID, link.spanID), { state: { autoRun: true } });
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import ScrollManager, { Accessors } from "./ScrollManager";
import { createScroller } from "./scroll-page";
import colorGenerator from "../../../../utils/color-generator";
import { useAppState } from "../../../../state/common/StateContext";
import { computeRpc, getSpanIdFromSearchParams, SPAN_ID_URL_PARAM } from "../../utils";
import { computeRpc, getSpanIdFromSearchParams } from "../../utils";
import { SPAN_ID_URL_PARAM } from "../../../../constants/trace";
import { ViewRange } from "../../types";
import { CriticalPathSection, OtelSpan, OtelTrace, PEER_SERVICE, TNil } from "../../types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback } from "preact/compat";
import { useSearchParams } from "react-router-dom";
import { TRACE_ID_URL_PARAM } from "../../../constants/trace";

export const TRACE_QUERY_URL_PARAMS = {
QUERY: "logsql_query",
TRACE_ID: "trace_id",
TRACE_ID: TRACE_ID_URL_PARAM,
} as const;

const DEFAULT_QUERY = "*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Trace,
} from "../types";
import colorGenerator from "../../../utils/color-generator";
import { SPAN_ID_URL_PARAM } from "../../../constants/trace";

export const SPAN_KIND_OPTIONS = ["SERVER", "CLIENT", "PRODUCER", "CONSUMER", "INTERNAL"];

Expand Down Expand Up @@ -420,12 +421,6 @@ export function formatApiError(error: ApiError): ApiErrorDetails {
return { title: message, rows };
}

// ============================================================
// span_id URL param
// ============================================================

export const SPAN_ID_URL_PARAM = "span_id";

export function getSpanIdFromSearchParams(searchParams: URLSearchParams): { spanId: string | undefined } {
return { spanId: searchParams.get(SPAN_ID_URL_PARAM) || undefined };
}
Expand Down
2 changes: 2 additions & 0 deletions docs/victoriatraces/changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The following `tip` changes can be tested by building VictoriaTraces components
* FEATURE: [logstorage](https://docs.victoriametrics.com/victorialogs/): upgrade VictoriaLogs dependency from [v1.52.0 to v1.53.0](https://github.com/VictoriaMetrics/VictoriaLogs/compare/v1.52.0...v1.53.0).
* FEATURE: [VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/), and [vtagent](https://docs.victoriametrics.com/victoriatraces/vtagent/): add `-healthcheck` command-line flag, which checks that the running process accepts connections at `-httpListenAddr` and exits with non-zero code if the check fails. This allows setting up Docker `HEALTHCHECK` in images without `curl` or `wget`. See [these docs](https://docs.victoriametrics.com/victoriatraces/quick-start/#starting-victoriatraces-single-node-via-docker) and [VictoriaLogs issue #1565](https://github.com/VictoriaMetrics/VictoriaLogs/issues/1565).

* BUGFIX: [Single-node VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/) and vtselect in [VictoriaTraces cluster](https://docs.victoriametrics.com/victoriatraces/cluster/): keep `accountID` and `projectID` when vmui opens a trace or when the header logo returns to the explorer. Previously "View full trace", the trace-table action, linked traces, and the header logo dropped the selected tenant, so the next page queried tenant `0:0` and showed no data. See [this issue #293](https://github.com/VictoriaMetrics/VictoriaTraces/issues/293). Thanks to @mastersans for [the pull request #303](https://github.com/VictoriaMetrics/VictoriaTraces/pull/303).

## [v0.12.1](https://github.com/VictoriaMetrics/VictoriaTraces/releases/tag/v0.12.1)

Released at 2026-10-23
Expand Down
Loading