Skip to content

Add DataDog instrumentation to Google Sheets reads. #16363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged
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
29 changes: 24 additions & 5 deletions packages/server/src/integrations/googlesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import fetch from "node-fetch"
import { cache, configs, context, HTTPError } from "@budibase/backend-core"
import { dataFilters, utils } from "@budibase/shared-core"
import { GOOGLE_SHEETS_PRIMARY_KEY } from "../constants"
import tracer from "dd-trace"

export interface GoogleSheetsConfig {
spreadsheetId: string
Expand Down Expand Up @@ -572,12 +573,25 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
sort?: SortJson
paginate?: PaginationJson
}) {
try {
return await tracer.trace("googlesheets.read", async span => {
span.addTags({
sheet: query.sheet,
filters: query.filters,
sort: query.sort,
paginate: query.paginate,
})

await this.connect()
const hasFilters = dataFilters.hasFilters(query.filters)
const limit = query.paginate?.limit || 100
let offset = query.paginate?.offset || 0

span.addTags({
hasFilters,
limit,
offset,
})

let page = query.paginate?.page
if (typeof page === "string") {
page = parseInt(page)
Expand All @@ -587,6 +601,8 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
}

const sheet = this.client.sheetsByTitle[query.sheet]
span.addTags({ rowCount: sheet.rowCount })

let rows: GoogleSpreadsheetRow[] = []
if (query.paginate && !hasFilters) {
rows = await sheet.getRows({
Expand All @@ -597,6 +613,8 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
rows = await sheet.getRows()
}

span.addTags({ totalRowsRead: rows.length })

let response = rows.map(row =>
this.buildRowObject(sheet.headerValues, row.toObject(), row.rowNumber)
)
Expand All @@ -621,11 +639,12 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
)
}

span.addTags({
totalRowsReturned: response.length,
})

return response
} catch (err) {
console.error("Error reading from google sheets", err)
throw err
}
})
}

private async getRowByIndex(sheetTitle: string, rowIndex: number) {
Expand Down
Loading