feat: harmonize log and metrics
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
} from "@/lib/graphql/Query/SiteConfig.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||
import { langInput } from "@/server/utils"
|
||||
|
||||
@@ -43,37 +44,6 @@ import {
|
||||
validateFooterConfigSchema,
|
||||
validateFooterRefConfigSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getContactConfigCounter,
|
||||
getContactConfigFailCounter,
|
||||
getContactConfigSuccessCounter,
|
||||
getCurrentFooterCounter,
|
||||
getCurrentFooterFailCounter,
|
||||
getCurrentFooterRefCounter,
|
||||
getCurrentFooterSuccessCounter,
|
||||
getCurrentHeaderCounter,
|
||||
getCurrentHeaderFailCounter,
|
||||
getCurrentHeaderRefCounter,
|
||||
getCurrentHeaderSuccessCounter,
|
||||
getFooterCounter,
|
||||
getFooterFailCounter,
|
||||
getFooterRefCounter,
|
||||
getFooterRefFailCounter,
|
||||
getFooterRefSuccessCounter,
|
||||
getFooterSuccessCounter,
|
||||
getHeaderCounter,
|
||||
getHeaderFailCounter,
|
||||
getHeaderRefsCounter,
|
||||
getHeaderRefsFailCounter,
|
||||
getHeaderRefsSuccessCounter,
|
||||
getHeaderSuccessCounter,
|
||||
getSiteConfigCounter,
|
||||
getSiteConfigFailCounter,
|
||||
getSiteConfigRefCounter,
|
||||
getSiteConfigRefFailCounter,
|
||||
getSiteConfigRefSuccessCounter,
|
||||
getSiteConfigSuccessCounter,
|
||||
} from "./telemetry"
|
||||
import {
|
||||
getAlertPhoneContactData,
|
||||
getConnections,
|
||||
@@ -96,11 +66,14 @@ import type {
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const getContactConfig = cache(async (lang: Lang) => {
|
||||
getContactConfigCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.contactConfig start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getContactConfigCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"contactConfig.get"
|
||||
)
|
||||
const metricsGetContactConfig = getContactConfigCounter.init({ lang })
|
||||
|
||||
metricsGetContactConfig.start()
|
||||
|
||||
const response = await request<ContactConfigData>(
|
||||
GetContactConfig,
|
||||
{
|
||||
@@ -114,46 +87,20 @@ const getContactConfig = cache(async (lang: Lang) => {
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
|
||||
getContactConfigFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
|
||||
console.error(
|
||||
"contentstack.config not found error",
|
||||
JSON.stringify({ query: { lang }, error: { code: notFoundError.code } })
|
||||
)
|
||||
|
||||
metricsGetContactConfig.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedContactConfigConfig = validateContactConfigSchema.safeParse(
|
||||
response.data
|
||||
)
|
||||
const verifiedData = validateContactConfigSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedContactConfigConfig.success) {
|
||||
getContactConfigFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedContactConfigConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.contactConfig validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedContactConfigConfig.error,
|
||||
})
|
||||
)
|
||||
if (!verifiedData.success) {
|
||||
metricsGetContactConfig.validationError(verifiedData.error)
|
||||
return null
|
||||
}
|
||||
getContactConfigSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.contactConfig success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||
|
||||
metricsGetContactConfig.success()
|
||||
|
||||
return verifiedData.data.all_contact_config.items[0]
|
||||
})
|
||||
|
||||
export const baseQueryRouter = router({
|
||||
@@ -162,11 +109,14 @@ export const baseQueryRouter = router({
|
||||
}),
|
||||
header: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
getHeaderRefsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.header.refs start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
|
||||
const getHeaderRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"header.get.refs"
|
||||
)
|
||||
const metricsGetHeaderRefs = getHeaderRefsCounter.init({ lang })
|
||||
|
||||
metricsGetHeaderRefs.start()
|
||||
|
||||
const responseRef = await request<GetHeaderRefs>(
|
||||
GetHeaderRef,
|
||||
@@ -181,56 +131,25 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
getHeaderRefsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetHeaderRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedHeaderRefs = headerRefsSchema.safeParse(responseRef.data)
|
||||
|
||||
if (!validatedHeaderRefs.success) {
|
||||
getHeaderRefsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHeaderRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header.refs validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: validatedHeaderRefs.error,
|
||||
})
|
||||
)
|
||||
metricsGetHeaderRefs.validationError(validatedHeaderRefs.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getHeaderRefsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.header.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetHeaderRefs.success()
|
||||
|
||||
const connections = getConnections(validatedHeaderRefs.data)
|
||||
|
||||
getHeaderCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.header start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const getHeaderCounter = createCounter("trpc.contentstack", "header.get")
|
||||
const metricsGetHeader = getHeaderCounter.init({ lang })
|
||||
|
||||
metricsGetHeader.start()
|
||||
|
||||
const tags = [
|
||||
generateTagsFromSystem(lang, connections),
|
||||
@@ -245,43 +164,18 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getHeaderFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header not found error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetHeader.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedHeaderConfig = headerSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedHeaderConfig.success) {
|
||||
getHeaderFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHeaderConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedHeaderConfig.error,
|
||||
})
|
||||
)
|
||||
metricsGetHeader.validationError(validatedHeaderConfig.error)
|
||||
return null
|
||||
}
|
||||
getHeaderSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.header success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetHeader.success()
|
||||
|
||||
return {
|
||||
data: validatedHeaderConfig.data.header,
|
||||
@@ -290,11 +184,16 @@ export const baseQueryRouter = router({
|
||||
currentHeader: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
getCurrentHeaderRefCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentHeader.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
const getCurrentHeaderRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"currentHeader.get.refs"
|
||||
)
|
||||
const metricsGetCurrentHeaderRefs = getCurrentHeaderRefsCounter.init({
|
||||
lang: input.lang,
|
||||
})
|
||||
|
||||
metricsGetCurrentHeaderRefs.start()
|
||||
|
||||
const responseRef = await request<CurrentHeaderRefDataRaw>(
|
||||
GetCurrentHeaderRef,
|
||||
{
|
||||
@@ -305,13 +204,16 @@ export const baseQueryRouter = router({
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
getCurrentHeaderCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentHeader start",
|
||||
JSON.stringify({
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
|
||||
const getCurrentHeaderCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"currentHeader.get"
|
||||
)
|
||||
const metricsGetCurrentHeader = getCurrentHeaderCounter.init({
|
||||
lang: input.lang,
|
||||
})
|
||||
|
||||
metricsGetCurrentHeader.start()
|
||||
|
||||
const currentHeaderUID =
|
||||
responseRef.data.all_current_header.items[0].system.uid
|
||||
@@ -327,20 +229,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getCurrentHeaderFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.currentHeader not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetCurrentHeader.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -349,40 +238,27 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedHeaderConfig.success) {
|
||||
getCurrentHeaderFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHeaderConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.currentHeader validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: validatedHeaderConfig.error,
|
||||
})
|
||||
)
|
||||
metricsGetCurrentHeader.validationError(validatedHeaderConfig.error)
|
||||
return null
|
||||
}
|
||||
getCurrentHeaderSuccessCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentHeader success",
|
||||
JSON.stringify({
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetCurrentHeader.success()
|
||||
|
||||
return validatedHeaderConfig.data
|
||||
}),
|
||||
currentFooter: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
getCurrentFooterRefCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentFooter.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
const getCurrentFooterRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"currentFooter.get.refs"
|
||||
)
|
||||
const metricsGetCurrentFooterRefs = getCurrentFooterRefsCounter.init({
|
||||
lang: input.lang,
|
||||
})
|
||||
|
||||
metricsGetCurrentFooterRefs.start()
|
||||
|
||||
const responseRef = await request<CurrentFooterRefDataRaw>(
|
||||
GetCurrentFooterRef,
|
||||
{
|
||||
@@ -393,16 +269,17 @@ export const baseQueryRouter = router({
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
getCurrentFooterCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentFooter start",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
})
|
||||
|
||||
const getCurrentFooterCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"currentFooter.get"
|
||||
)
|
||||
const metricsGetCurrentFooter = getCurrentFooterCounter.init({
|
||||
lang: input.lang,
|
||||
})
|
||||
|
||||
metricsGetCurrentFooter.start()
|
||||
|
||||
const currentFooterUID =
|
||||
responseRef.data.all_current_footer.items[0].system.uid
|
||||
|
||||
@@ -419,20 +296,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getCurrentFooterFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.currentFooter not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetCurrentFooter.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -440,34 +304,27 @@ export const baseQueryRouter = router({
|
||||
validateCurrentFooterConfigSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedCurrentFooterConfig.success) {
|
||||
getFooterFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedCurrentFooterConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.currentFooter validation error",
|
||||
JSON.stringify({
|
||||
query: { lang: input.lang },
|
||||
error: validatedCurrentFooterConfig.error,
|
||||
})
|
||||
metricsGetCurrentFooter.validationError(
|
||||
validatedCurrentFooterConfig.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
getCurrentFooterSuccessCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.currentFooter success",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
|
||||
metricsGetCurrentFooter.success()
|
||||
|
||||
return validatedCurrentFooterConfig.data.all_current_footer.items[0]
|
||||
}),
|
||||
footer: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
getFooterRefCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.footer.ref start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
|
||||
const getFooterRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"footer.get.refs"
|
||||
)
|
||||
const metricsGetFooterRefs = getFooterRefsCounter.init({ lang })
|
||||
|
||||
metricsGetFooterRefs.start()
|
||||
|
||||
const responseRef = await request<FooterRefDataRaw>(
|
||||
GetFooterRef,
|
||||
{
|
||||
@@ -481,20 +338,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
getFooterRefFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetFooterRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -503,41 +347,20 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedFooterRefs.success) {
|
||||
getFooterRefFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedFooterRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer.refs validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: validatedFooterRefs.error,
|
||||
})
|
||||
)
|
||||
metricsGetFooterRefs.validationError(validatedFooterRefs.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getFooterRefSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.footer.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetFooterRefs.success()
|
||||
|
||||
const connections = getFooterConnections(validatedFooterRefs.data)
|
||||
const footerUID = responseRef.data.all_footer.items[0].system.uid
|
||||
|
||||
getFooterCounter.add(1, { lang: lang })
|
||||
console.info(
|
||||
"contentstack.footer start",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
})
|
||||
)
|
||||
const getFooterCounter = createCounter("trpc.contentstack", "footer.get")
|
||||
const metricsGetFooter = getFooterCounter.init({ lang })
|
||||
|
||||
metricsGetFooter.start()
|
||||
|
||||
const tags = [
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, footerUID),
|
||||
@@ -556,20 +379,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getFooterFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetFooter.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -578,25 +388,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedFooterConfig.success) {
|
||||
getFooterFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedFooterConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer validation error",
|
||||
JSON.stringify({
|
||||
query: { lang: lang },
|
||||
error: validatedFooterConfig.error,
|
||||
})
|
||||
)
|
||||
metricsGetFooter.validationError(validatedFooterConfig.error)
|
||||
return null
|
||||
}
|
||||
getFooterSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.footer success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetFooter.success()
|
||||
|
||||
return validatedFooterConfig.data
|
||||
}),
|
||||
@@ -605,11 +401,14 @@ export const baseQueryRouter = router({
|
||||
.query(async ({ input, ctx }) => {
|
||||
const lang = input.lang ?? ctx.lang
|
||||
|
||||
getSiteConfigRefCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.siteConfig.ref start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getSiteConfigRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"siteConfig.get.refs"
|
||||
)
|
||||
const metricsGetSiteConfigRefs = getSiteConfigRefsCounter.init({ lang })
|
||||
|
||||
metricsGetSiteConfigRefs.start()
|
||||
|
||||
const responseRef = await request<GetSiteConfigRefData>(
|
||||
GetSiteConfigRef,
|
||||
{
|
||||
@@ -623,20 +422,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!responseRef.data) {
|
||||
const notFoundError = notFound(responseRef)
|
||||
getSiteConfigRefFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.siteConfig.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetSiteConfigRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -645,20 +431,7 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedSiteConfigRef.success) {
|
||||
getSiteConfigRefFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedSiteConfigRef.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.siteConfig.refs validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: validatedSiteConfigRef.error,
|
||||
})
|
||||
)
|
||||
metricsGetSiteConfigRefs.validationError(validatedSiteConfigRef.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -670,17 +443,16 @@ export const baseQueryRouter = router({
|
||||
generateTag(lang, siteConfigUid),
|
||||
].flat()
|
||||
|
||||
getSiteConfigRefSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.siteConfig.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetSiteConfigRefs.success()
|
||||
|
||||
getSiteConfigCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.siteConfig start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getSiteConfigCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"siteConfig.get"
|
||||
)
|
||||
const metricsGetSiteConfig = getSiteConfigCounter.init({ lang })
|
||||
|
||||
metricsGetSiteConfig.start()
|
||||
|
||||
const [siteConfigResponse, contactConfig] = await Promise.all([
|
||||
request<GetSiteConfigData>(
|
||||
GetSiteConfig,
|
||||
@@ -697,21 +469,7 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!siteConfigResponse.data) {
|
||||
const notFoundError = notFound(siteConfigResponse)
|
||||
|
||||
getSiteConfigFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
|
||||
console.error(
|
||||
"contentstack.siteConfig not found error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetSiteConfig.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -720,26 +478,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedSiteConfig.success) {
|
||||
getSiteConfigFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedSiteConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.siteConfig validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedSiteConfig.error,
|
||||
})
|
||||
)
|
||||
metricsGetSiteConfig.validationError(validatedSiteConfig.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getSiteConfigSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.siteConfig success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetSiteConfig.success()
|
||||
|
||||
const { sitewideAlert } = validatedSiteConfig.data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user