Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: added fix for passing activeLogId in query range in log context view (#9180)

Abhi kumard595dcc22260
diff --git a/frontend/src/container/LogsExplorerViews/index.tsx b/frontend/src/container/LogsExplorerViews/index.tsx
index aaff83ab3d..8063bc62b6 100644
--- a/frontend/src/container/LogsExplorerViews/index.tsx
+++ b/frontend/src/container/LogsExplorerViews/index.tsx
@@ -59,6 +59,7 @@ import {
Query,
TagFilter,
} from 'types/api/queryBuilder/queryBuilderData';
+import { Filter } from 'types/api/v5/queryRange';
import { QueryDataV3 } from 'types/api/widgets/getQuery';
import { DataSource, LogsAggregatorOperator } from 'types/common/queryBuilder';
import { GlobalReducer } from 'types/reducer/globalTime';
@@ -171,6 +172,11 @@ function LogsExplorerViewsContainer({
return;
}
+ let updatedFilterExpression = listQuery.filter?.expression || '';
+ if (activeLogId) {
+ updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim();
+ }
+
const modifiedQueryData: IBuilderQuery = {
...listQuery,
aggregateOperator: LogsAggregatorOperator.COUNT,
@@ -183,6 +189,10 @@ function LogsExplorerViewsContainer({
},
],
legend: '{{severity_text}}',
+ filter: {
+ ...listQuery?.filter,
+ expression: updatedFilterExpression || '',
+ },
...(activeLogId && {
filters: {
...listQuery?.filters,
@@ -286,6 +296,7 @@ function LogsExplorerViewsContainer({
page: number;
pageSize: number;
filters: TagFilter;
+ filter: Filter;
},
): Query | null => {
if (!query) return null;
@@ -297,6 +308,7 @@ function LogsExplorerViewsContainer({
// Add filter for activeLogId if present
let updatedFilters = params.filters;
+ let updatedFilterExpression = params.filter?.expression || '';
if (activeLogId) {
updatedFilters = {
...params.filters,
@@ -315,6 +327,7 @@ function LogsExplorerViewsContainer({
],
op: 'AND',
};
+ updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim();
}
// Create orderBy array based on orderDirection
@@ -336,6 +349,9 @@ function LogsExplorerViewsContainer({
...(listQuery || initialQueryBuilderFormValues),
...paginateData,
...(updatedFilters ? { filters: updatedFilters } : {}),
+ filter: {
+ expression: updatedFilterExpression || '',
+ },
...(selectedView === ExplorerViews.LIST
? { order: newOrderBy, orderBy: newOrderBy }
: { order: [] }),
@@ -368,7 +384,7 @@ function LogsExplorerViewsContainer({
if (isLimit) return;
if (logs.length < pageSize) return;
- const { limit, filters } = listQuery;
+ const { limit, filters, filter } = listQuery;
const nextLogsLength = logs.length + pageSize;
@@ -379,6 +395,7 @@ function LogsExplorerViewsContainer({
const newRequestData = getRequestData(stagedQuery, {
filters: filters || { items: [], op: 'AND' },
+ filter: filter || { expression: '' },
page: page + 1,
pageSize: nextPageSize,
});
@@ -526,6 +543,7 @@ function LogsExplorerViewsContainer({
const newRequestData = getRequestData(stagedQuery, {
filters: listQuery?.filters || initialFilters,
+ filter: listQuery?.filter || { expression: '' },
page: 1,
pageSize,
});
diff --git a/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx b/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx
index bf9690fb76..f5a72e2ce9 100644
--- a/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx
+++ b/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx
@@ -1,3 +1,4 @@
+import { PANEL_TYPES } from 'constants/queryBuilder';
import ROUTES from 'constants/routes';
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
import { useGetExplorerQueryRange } from 'hooks/queryBuilder/useGetExplorerQueryRange';
@@ -261,6 +262,68 @@ describe('LogsExplorerViews -', () => {
// Verify the total number of filters (original + 1 new activeLogId filter)
expect(firstQuery.filters?.items.length).toBe(expectedFiltersLength);
+
+ // Verify the filter expression
+ expect(firstQuery.filter?.expression).toBe(`id <= '${ACTIVE_LOG_ID}'`);
+ }
+ });
+ });
+
+ it('should update filter expression with activeLogId when present with existing filter expression', async () => {
+ // Mock useCopyLogLink to return an activeLogId
+ (useCopyLogLink as jest.Mock).mockReturnValue({
+ activeLogId: ACTIVE_LOG_ID,
+ });
+
+ // Create a custom QueryBuilderContext with an existing filter expression
+ const customContext = {
+ ...mockQueryBuilderContextValue,
+ panelType: PANEL_TYPES.LIST,
+ stagedQuery: {
+ ...mockQueryBuilderContextValue.stagedQuery,
+ builder: {
+ ...mockQueryBuilderContextValue.stagedQuery.builder,
+ queryData: [
+ {
+ ...mockQueryBuilderContextValue.stagedQuery.builder.queryData[0],
+ filter: { expression: "service = 'frontend'" },
+ },
+ ],
+ },
+ },
+ };
+
+ lodsQueryServerRequest();
+
+ render(
+ <QueryBuilderContext.Provider value={customContext as any}>
+ <PreferenceContextProvider>
+ <LogsExplorerViews
+ selectedView={ExplorerViews.LIST}
+ setIsLoadingQueries={(): void => {}}
+ listQueryKeyRef={{ current: {} }}
+ chartQueryKeyRef={{ current: {} }}
+ setWarning={(): void => {}}
+ showLiveLogs={false}
+ />
+ </PreferenceContextProvider>
+ </QueryBuilderContext.Provider>,
+ );
+
+ await waitFor(() => {
+ // Find the call made for LIST panel type (main logs list request)
+ const listCall = (useGetExplorerQueryRange as jest.Mock).mock.calls.find(
+ (call) => call[1] === PANEL_TYPES.LIST && call[0],
+ );
+
+ expect(listCall).toBeDefined();
+ if (listCall) {
+ const queryArg = listCall[0];
+ const firstQuery = queryArg.builder.queryData[0];
+ // It should append the activeLogId condition to existing expression
+ expect(firstQuery.filter?.expression).toBe(
+ "service = 'frontend' id <= 'test-log-id'",
+ );
}
});
});