feat(logs): add traceId and spanId filters to logs and update related components

This commit is contained in:
Nawaz Dhandala
2026-03-07 17:59:41 +00:00
parent 0188c01115
commit 72cea8148d
5 changed files with 69 additions and 1 deletions

View File

@@ -289,6 +289,20 @@ const DashboardLogsViewer: FunctionComponent<ComponentProps> = (
(requestData as any)["serviceIds"] = Array.from(serviceFilterValues);
}
const traceFilterValues: Set<string> | undefined =
appliedFacetFilters.get("traceId");
if (traceFilterValues && traceFilterValues.size > 0) {
(requestData as any)["traceIds"] = Array.from(traceFilterValues);
}
const spanFilterValues: Set<string> | undefined =
appliedFacetFilters.get("spanId");
if (spanFilterValues && spanFilterValues.size > 0) {
(requestData as any)["spanIds"] = Array.from(spanFilterValues);
}
const response: HTTPResponse<JSONObject> = await postApi(
"/telemetry/logs/histogram",
requestData,
@@ -716,6 +730,8 @@ const DashboardLogsViewer: FunctionComponent<ComponentProps> = (
severity: "severityText",
level: "severityText",
service: "serviceId",
trace: "traceId",
span: "spanId",
};
const resolvedKey: string = fieldAliases[fieldKey] || fieldKey;

View File

@@ -144,6 +144,14 @@ router.post(
? (body["bodySearchText"] as string)
: undefined;
const traceIds: Array<string> | undefined = body["traceIds"]
? (body["traceIds"] as Array<string>)
: undefined;
const spanIds: Array<string> | undefined = body["spanIds"]
? (body["spanIds"] as Array<string>)
: undefined;
const request: HistogramRequest = {
projectId: databaseProps.tenantId,
startTime,
@@ -152,6 +160,8 @@ router.post(
serviceIds,
severityTexts,
bodySearchText,
traceIds,
spanIds,
};
const buckets: Array<HistogramBucket> =
@@ -218,6 +228,14 @@ router.post(
? (body["bodySearchText"] as string)
: undefined;
const traceIds: Array<string> | undefined = body["traceIds"]
? (body["traceIds"] as Array<string>)
: undefined;
const spanIds: Array<string> | undefined = body["spanIds"]
? (body["spanIds"] as Array<string>)
: undefined;
const facets: Record<string, Array<FacetValue>> = {};
for (const facetKey of facetKeys) {
@@ -230,6 +248,8 @@ router.post(
serviceIds,
severityTexts,
bodySearchText,
traceIds,
spanIds,
};
facets[facetKey] = await LogAggregationService.getFacetValues(request);

View File

@@ -20,6 +20,8 @@ export interface HistogramRequest {
serviceIds?: Array<ObjectID> | undefined;
severityTexts?: Array<string> | undefined;
bodySearchText?: string | undefined;
traceIds?: Array<string> | undefined;
spanIds?: Array<string> | undefined;
}
export interface FacetValue {
@@ -36,6 +38,8 @@ export interface FacetRequest {
serviceIds?: Array<ObjectID> | undefined;
severityTexts?: Array<string> | undefined;
bodySearchText?: string | undefined;
traceIds?: Array<string> | undefined;
spanIds?: Array<string> | undefined;
}
export class LogAggregationService {
@@ -179,7 +183,7 @@ export class LogAggregationService {
statement: Statement,
request: Pick<
HistogramRequest,
"serviceIds" | "severityTexts" | "bodySearchText"
"serviceIds" | "severityTexts" | "bodySearchText" | "traceIds" | "spanIds"
>,
): void {
if (request.serviceIds && request.serviceIds.length > 0) {
@@ -197,6 +201,22 @@ export class LogAggregationService {
statement.append(` AND severityText IN (${sevStrings.join(",")})`);
}
if (request.traceIds && request.traceIds.length > 0) {
const traceStrings: Array<string> = request.traceIds.map(
(s: string): string =>
`'${LogAggregationService.escapeSingleQuotes(s)}'`,
);
statement.append(` AND traceId IN (${traceStrings.join(",")})`);
}
if (request.spanIds && request.spanIds.length > 0) {
const spanStrings: Array<string> = request.spanIds.map(
(s: string): string =>
`'${LogAggregationService.escapeSingleQuotes(s)}'`,
);
statement.append(` AND spanId IN (${spanStrings.join(",")})`);
}
if (request.bodySearchText && request.bodySearchText.trim().length > 0) {
statement.append(` AND body ILIKE ${{
type: TableColumnType.Text,

View File

@@ -328,6 +328,8 @@ const FIELD_ALIAS_MAP: Record<string, string> = {
severity: "severityText",
level: "severityText",
service: "serviceId",
trace: "traceId",
span: "spanId",
};
function getValueSuggestions(

View File

@@ -31,6 +31,16 @@ const HELP_ROWS: Array<HelpRow> = [
description: "Filter by service",
example: "service:api",
},
{
syntax: "trace:<id>",
description: "Filter by trace ID",
example: "trace:abc123def456",
},
{
syntax: "span:<id>",
description: "Filter by span ID",
example: "span:e1f7f671fe78",
},
{
syntax: "@<attr>:<value>",
description: "Filter by attribute",