Merge pull request #14333 from Budibase/trace-search
Add detailed tracing to searches.
This commit is contained in:
commit
d45bbb94e4
|
@ -13,6 +13,7 @@ import { dataFilters } from "@budibase/shared-core"
|
||||||
import sdk from "../../index"
|
import sdk from "../../index"
|
||||||
import { searchInputMapping } from "./search/utils"
|
import { searchInputMapping } from "./search/utils"
|
||||||
import { db as dbCore } from "@budibase/backend-core"
|
import { db as dbCore } from "@budibase/backend-core"
|
||||||
|
import tracer from "dd-trace"
|
||||||
|
|
||||||
export { isValidFilter } from "../../../integrations/utils"
|
export { isValidFilter } from "../../../integrations/utils"
|
||||||
|
|
||||||
|
@ -32,13 +33,34 @@ function pickApi(tableId: any) {
|
||||||
export async function search(
|
export async function search(
|
||||||
options: RowSearchParams
|
options: RowSearchParams
|
||||||
): Promise<SearchResponse<Row>> {
|
): Promise<SearchResponse<Row>> {
|
||||||
|
return await tracer.trace("search", async span => {
|
||||||
|
span?.addTags({
|
||||||
|
tableId: options.tableId,
|
||||||
|
query: options.query,
|
||||||
|
sort: options.sort,
|
||||||
|
sortOrder: options.sortOrder,
|
||||||
|
sortType: options.sortType,
|
||||||
|
limit: options.limit,
|
||||||
|
bookmark: options.bookmark,
|
||||||
|
paginate: options.paginate,
|
||||||
|
fields: options.fields,
|
||||||
|
countRows: options.countRows,
|
||||||
|
})
|
||||||
|
|
||||||
const isExternalTable = isExternalTableID(options.tableId)
|
const isExternalTable = isExternalTableID(options.tableId)
|
||||||
options.query = dataFilters.cleanupQuery(options.query || {})
|
options.query = dataFilters.cleanupQuery(options.query || {})
|
||||||
options.query = dataFilters.fixupFilterArrays(options.query)
|
options.query = dataFilters.fixupFilterArrays(options.query)
|
||||||
|
|
||||||
|
span?.addTags({
|
||||||
|
cleanedQuery: options.query,
|
||||||
|
isExternalTable,
|
||||||
|
})
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!dataFilters.hasFilters(options.query) &&
|
!dataFilters.hasFilters(options.query) &&
|
||||||
options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
|
options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
|
||||||
) {
|
) {
|
||||||
|
span?.addTags({ emptyQuery: true })
|
||||||
return {
|
return {
|
||||||
rows: [],
|
rows: [],
|
||||||
}
|
}
|
||||||
|
@ -51,13 +73,25 @@ export async function search(
|
||||||
const table = await sdk.tables.getTable(options.tableId)
|
const table = await sdk.tables.getTable(options.tableId)
|
||||||
options = searchInputMapping(table, options)
|
options = searchInputMapping(table, options)
|
||||||
|
|
||||||
|
let result: SearchResponse<Row>
|
||||||
if (isExternalTable) {
|
if (isExternalTable) {
|
||||||
return external.search(options, table)
|
span?.addTags({ searchType: "external" })
|
||||||
|
result = await external.search(options, table)
|
||||||
} else if (dbCore.isSqsEnabledForTenant()) {
|
} else if (dbCore.isSqsEnabledForTenant()) {
|
||||||
return internal.sqs.search(options, table)
|
span?.addTags({ searchType: "sqs" })
|
||||||
|
result = await internal.sqs.search(options, table)
|
||||||
} else {
|
} else {
|
||||||
return internal.lucene.search(options, table)
|
span?.addTags({ searchType: "lucene" })
|
||||||
|
result = await internal.lucene.search(options, table)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span?.addTags({
|
||||||
|
foundRows: result.rows.length,
|
||||||
|
totalRows: result.totalRows,
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function exportRows(
|
export async function exportRows(
|
||||||
|
|
Loading…
Reference in New Issue