feat: harmonize log and metrics
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
import { GetCityPageCount } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPageCount.graphql"
|
||||
import { GetCityPageUrls } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
||||
|
||||
import { batchedCityPageUrlsSchema, cityPageCountSchema } from "./output"
|
||||
import {
|
||||
getCityPageCountCounter,
|
||||
getCityPageCountFailCounter,
|
||||
getCityPageCountSuccessCounter,
|
||||
getCityPageUrlsCounter,
|
||||
getCityPageUrlsFailCounter,
|
||||
getCityPageUrlsSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { DestinationCityPageEnum } from "@/types/enums/destinationCityPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
@@ -76,11 +69,13 @@ export function getConnections({
|
||||
}
|
||||
|
||||
export async function getCityPageCount(lang: Lang) {
|
||||
getCityPageCountCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageCount start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getCityPageCountCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"cityPageCount.get"
|
||||
)
|
||||
const metricsGetCityPageCount = getCityPageCountCounter.init({ lang })
|
||||
|
||||
metricsGetCityPageCount.start()
|
||||
|
||||
const response = await request<GetCityPageCountData>(
|
||||
GetCityPageCount,
|
||||
@@ -92,15 +87,10 @@ export async function getCityPageCount(lang: Lang) {
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getCityPageCountFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: `City pages count not found for lang: ${lang}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityPageCount not found error",
|
||||
JSON.stringify({ query: { lang } })
|
||||
metricsGetCityPageCount.dataError(
|
||||
`Failed to get city pages count for ${lang}`
|
||||
)
|
||||
return 0
|
||||
}
|
||||
@@ -108,35 +98,24 @@ export async function getCityPageCount(lang: Lang) {
|
||||
const validatedResponse = cityPageCountSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getCityPageCountFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageCount validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetCityPageCount.validationError(validatedResponse.error)
|
||||
return 0
|
||||
}
|
||||
getCityPageCountSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageCount success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetCityPageCount.success()
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
export async function getCityPageUrls(lang: Lang) {
|
||||
getCityPageUrlsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getCityPageUrlsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"cityPageUrls.get"
|
||||
)
|
||||
const metricsGetCityPageUrls = getCityPageUrlsCounter.init({ lang })
|
||||
|
||||
metricsGetCityPageUrls.start()
|
||||
|
||||
const count = await getCityPageCount(lang)
|
||||
|
||||
if (count === 0) {
|
||||
@@ -162,25 +141,11 @@ export async function getCityPageUrls(lang: Lang) {
|
||||
const validatedResponse = batchedCityPageUrlsSchema.safeParse(batchedResponse)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getCityPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetCityPageUrls.validationError(validatedResponse.error)
|
||||
return []
|
||||
}
|
||||
getCityPageUrlsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageUrls success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetCityPageUrls.success()
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user