feat: harmonize log and metrics
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import {
|
||||
GetAccountPage,
|
||||
GetAccountPageRefs,
|
||||
} from "@/lib/graphql/Query/AccountPage/AccountPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
@@ -26,36 +25,17 @@ import type {
|
||||
GetAccountPageSchema,
|
||||
} from "@/types/trpc/routers/contentstack/accountPage"
|
||||
|
||||
const meter = metrics.getMeter("trpc.accountPage")
|
||||
|
||||
// OpenTelemetry metrics
|
||||
const getAccountPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get"
|
||||
)
|
||||
const getAccountPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get-success"
|
||||
)
|
||||
const getAccountPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get-fail"
|
||||
)
|
||||
const getAccountPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get"
|
||||
)
|
||||
const getAccountPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get-success"
|
||||
)
|
||||
const getAccountPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.accountPage.get-fail"
|
||||
)
|
||||
|
||||
export const accountPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
getAccountPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage.refs start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
|
||||
const getAccountPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"accountPage.get.refs"
|
||||
)
|
||||
const metricsRefs = getAccountPageRefsCounter.init({ lang, uid })
|
||||
metricsRefs.start()
|
||||
|
||||
const refsResponse = await request<GetAccountPageRefsSchema>(
|
||||
GetAccountPageRefs,
|
||||
{
|
||||
@@ -70,19 +50,7 @@ export const accountPageQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getAccountPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.accountPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -90,19 +58,7 @@ export const accountPageQueryRouter = router({
|
||||
refsResponse.data
|
||||
)
|
||||
if (!validatedAccountPageRefs.success) {
|
||||
getAccountPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedAccountPageRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.accountPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPageRefs.error,
|
||||
})
|
||||
)
|
||||
metricsRefs.validationError(validatedAccountPageRefs.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -112,12 +68,16 @@ export const accountPageQueryRouter = router({
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
||||
].flat()
|
||||
getAccountPageRefsSuccessCounter.add(1, { lang, uid, tags })
|
||||
getAccountPageCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
|
||||
metricsRefs.success()
|
||||
|
||||
const getAccountPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"accountPage.get"
|
||||
)
|
||||
const metrics = getAccountPageCounter.init({ lang, uid })
|
||||
metrics.start()
|
||||
|
||||
const response = await request<GetAccountPageSchema>(
|
||||
GetAccountPage,
|
||||
{
|
||||
@@ -132,45 +92,18 @@ export const accountPageQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getAccountPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.accountPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metrics.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedAccountPage = accountPageSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedAccountPage.success) {
|
||||
getAccountPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedAccountPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.accountPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPage.error,
|
||||
})
|
||||
)
|
||||
metrics.validationError(validatedAccountPage.error)
|
||||
return null
|
||||
}
|
||||
getAccountPageSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
|
||||
metrics.success()
|
||||
|
||||
const parsedtitle = response.data.account_page.title
|
||||
.replaceAll(" ", "")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.base")
|
||||
// OpenTelemetry metrics: ContactConfig
|
||||
export const getContactConfigCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get"
|
||||
)
|
||||
export const getContactConfigSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get-success"
|
||||
)
|
||||
export const getContactConfigFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get-fail"
|
||||
)
|
||||
// OpenTelemetry metrics: CurrentHeader
|
||||
export const getCurrentHeaderRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.ref.get"
|
||||
)
|
||||
export const getCurrentHeaderRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.ref.get-success"
|
||||
)
|
||||
export const getCurrentHeaderRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.ref.get-fail"
|
||||
)
|
||||
export const getCurrentHeaderCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.get"
|
||||
)
|
||||
export const getCurrentHeaderSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.get-success"
|
||||
)
|
||||
export const getCurrentHeaderFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentHeader.get-fail"
|
||||
)
|
||||
|
||||
// OpenTelemetry metrics: Header
|
||||
export const getHeaderRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get"
|
||||
)
|
||||
export const getHeaderRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get-success"
|
||||
)
|
||||
export const getHeaderRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get-fail"
|
||||
)
|
||||
export const getHeaderCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.get"
|
||||
)
|
||||
export const getHeaderSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.get-success"
|
||||
)
|
||||
export const getHeaderFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.get-fail"
|
||||
)
|
||||
|
||||
// OpenTelemetry metrics: CurrentFooter
|
||||
export const getCurrentFooterRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.ref.get"
|
||||
)
|
||||
export const getCurrentFooterRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.ref.get-success"
|
||||
)
|
||||
export const getCurrentFooterRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.ref.get-fail"
|
||||
)
|
||||
export const getCurrentFooterCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.get"
|
||||
)
|
||||
export const getCurrentFooterSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.get-success"
|
||||
)
|
||||
export const getCurrentFooterFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.currentFooter.get-fail"
|
||||
)
|
||||
|
||||
// OpenTelemetry metrics: Footer
|
||||
export const getFooterRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get"
|
||||
)
|
||||
export const getFooterRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get-success"
|
||||
)
|
||||
export const getFooterRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get-fail"
|
||||
)
|
||||
export const getFooterCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.get"
|
||||
)
|
||||
export const getFooterSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.get-success"
|
||||
)
|
||||
export const getFooterFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.get-fail"
|
||||
)
|
||||
|
||||
// OpenTelemetry metrics: SiteConfig
|
||||
export const getSiteConfigRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.ref.get"
|
||||
)
|
||||
export const getSiteConfigRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.ref.get-success"
|
||||
)
|
||||
export const getSiteConfigRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.ref.get-fail"
|
||||
)
|
||||
export const getSiteConfigCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.get"
|
||||
)
|
||||
export const getSiteConfigSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.get-success"
|
||||
)
|
||||
export const getSiteConfigFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.SiteConfig.get-fail"
|
||||
)
|
||||
@@ -1,4 +1,3 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
import { cache } from "react"
|
||||
|
||||
import {
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
} from "@/lib/graphql/Query/Breadcrumbs/LoyaltyPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { generateRefsResponseTag } from "@/utils/generateTag"
|
||||
@@ -49,28 +49,6 @@ import type {
|
||||
} from "@/types/trpc/routers/contentstack/breadcrumbs"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.breadcrumbs")
|
||||
|
||||
// OpenTelemetry metrics
|
||||
const getBreadcrumbsRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.refs.get"
|
||||
)
|
||||
const getBreadcrumbsRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.refs.get-success"
|
||||
)
|
||||
const getBreadcrumbsRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.refs.get-fail"
|
||||
)
|
||||
const getBreadcrumbsCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.get"
|
||||
)
|
||||
const getBreadcrumbsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.get-success"
|
||||
)
|
||||
const getBreadcrumbsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.breadcrumbs.get-fail"
|
||||
)
|
||||
|
||||
interface BreadcrumbsPageData<T> {
|
||||
dataKey: keyof T
|
||||
refQuery: string
|
||||
@@ -81,11 +59,17 @@ const getBreadcrumbs = cache(async function fetchMemoizedBreadcrumbs<T>(
|
||||
{ dataKey, refQuery, query }: BreadcrumbsPageData<T>,
|
||||
{ uid, lang }: { uid: string; lang: Lang }
|
||||
) {
|
||||
getBreadcrumbsRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.breadcrumbs refs get start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
const getBreadcrumbsRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"breadcrumbs.get.refs"
|
||||
)
|
||||
const metricsGetBreadcrumbsRefs = getBreadcrumbsRefsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetBreadcrumbsRefs.start()
|
||||
|
||||
const refsResponse = await request<{ [K in keyof T]: BreadcrumbsRefsSchema }>(
|
||||
refQuery,
|
||||
{ locale: lang, uid },
|
||||
@@ -100,32 +84,25 @@ const getBreadcrumbs = cache(async function fetchMemoizedBreadcrumbs<T>(
|
||||
)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
getBreadcrumbsRefsFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.breadcrumbs refs validation error",
|
||||
JSON.stringify({
|
||||
error: validatedRefsData.error,
|
||||
})
|
||||
)
|
||||
metricsGetBreadcrumbsRefs.validationError(validatedRefsData.error)
|
||||
return []
|
||||
}
|
||||
|
||||
getBreadcrumbsRefsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.breadcrumbs refs get success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
metricsGetBreadcrumbsRefs.success()
|
||||
|
||||
const tags = getTags(validatedRefsData.data, lang)
|
||||
|
||||
getBreadcrumbsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.breadcrumbs get start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
const getBreadcrumbsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"breadcrumbs.get"
|
||||
)
|
||||
const metricsGetBreadcrumbs = getBreadcrumbsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetBreadcrumbs.start()
|
||||
|
||||
const response = await request<T>(
|
||||
query,
|
||||
{ locale: lang, uid },
|
||||
@@ -137,19 +114,7 @@ const getBreadcrumbs = cache(async function fetchMemoizedBreadcrumbs<T>(
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getBreadcrumbsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.breadcrumbs get not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetBreadcrumbs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -158,24 +123,11 @@ const getBreadcrumbs = cache(async function fetchMemoizedBreadcrumbs<T>(
|
||||
)
|
||||
|
||||
if (!validatedBreadcrumbs.success) {
|
||||
getBreadcrumbsFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedBreadcrumbs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.breadcrumbs validation error",
|
||||
JSON.stringify({
|
||||
error: validatedBreadcrumbs.error,
|
||||
})
|
||||
)
|
||||
metricsGetBreadcrumbs.validationError(validatedBreadcrumbs.error)
|
||||
return []
|
||||
}
|
||||
|
||||
getBreadcrumbsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.breadcrumbs get success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
metricsGetBreadcrumbs.success()
|
||||
|
||||
return validatedBreadcrumbs.data
|
||||
})
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
cardsGridSchema,
|
||||
} from "../schemas/blocks/cardsGrid"
|
||||
import {
|
||||
dynamicContentSchema as blockDynamicContentSchema,
|
||||
dynamicContentRefsSchema,
|
||||
dynamicContentSchema as blockDynamicContentSchema,
|
||||
} from "../schemas/blocks/dynamicContent"
|
||||
import {
|
||||
shortcutsRefsSchema,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { GetCollectionPage } from "@/lib/graphql/Query/CollectionPage/CollectionPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { collectionPageSchema } from "./output"
|
||||
import {
|
||||
fetchCollectionPageRefs,
|
||||
generatePageTags,
|
||||
getCollectionPageCounter,
|
||||
validateCollectionPageRefs,
|
||||
} from "./utils"
|
||||
|
||||
@@ -32,13 +32,16 @@ export const collectionPageQueryRouter = router({
|
||||
}
|
||||
const tags = generatePageTags(collectionPageRefs, lang)
|
||||
|
||||
getCollectionPageCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.collectionPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getCollectionPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"collectionPage.get"
|
||||
)
|
||||
const metricsGetCollectionPage = getCollectionPageCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetCollectionPage.start()
|
||||
|
||||
const response = await request<GetCollectionPageSchema>(
|
||||
GetCollectionPage,
|
||||
@@ -51,13 +54,12 @@ export const collectionPageQueryRouter = router({
|
||||
|
||||
const collectionPage = collectionPageSchema.safeParse(response.data)
|
||||
if (!collectionPage.success) {
|
||||
console.error(
|
||||
`Failed to validate CollectionPage Data - (lang: ${lang}, uid: ${uid})`
|
||||
)
|
||||
console.error(collectionPage.error?.format())
|
||||
metricsGetCollectionPage.validationError(collectionPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetCollectionPage.success()
|
||||
|
||||
const tracking: TrackingSDKPageData = {
|
||||
pageId: collectionPage.data.collection_page.system.uid,
|
||||
domainLanguage: lang,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { GetCollectionPageRefs } from "@/lib/graphql/Query/CollectionPage/CollectionPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import { getCacheClient } from "@/services/dataCache"
|
||||
import {
|
||||
@@ -21,31 +20,17 @@ import type {
|
||||
} from "@/types/trpc/routers/contentstack/collectionPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.collectionPage")
|
||||
// OpenTelemetry metrics: CollectionPage
|
||||
|
||||
export const getCollectionPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.collectionPage.get"
|
||||
)
|
||||
|
||||
const getCollectionPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.collectionPage.get"
|
||||
)
|
||||
const getCollectionPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.collectionPage.get-fail"
|
||||
)
|
||||
const getCollectionPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.collectionPage.get-success"
|
||||
)
|
||||
|
||||
export async function fetchCollectionPageRefs(lang: Lang, uid: string) {
|
||||
getCollectionPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.collectionPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getCollectionPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"collectionPage.get.refs"
|
||||
)
|
||||
const metricsGetCollectionPageRefs = getCollectionPageRefsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetCollectionPageRefs.start()
|
||||
|
||||
const cacheClient = await getCacheClient()
|
||||
const cacheKey = generateRefsResponseTag(lang, uid)
|
||||
@@ -61,24 +46,7 @@ export async function fetchCollectionPageRefs(lang: Lang, uid: string) {
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getCollectionPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
code: notFoundError.code,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.collectionPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
uid,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetCollectionPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -90,30 +58,22 @@ export function validateCollectionPageRefs(
|
||||
lang: Lang,
|
||||
uid: string
|
||||
) {
|
||||
const getCollectionPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"collectionPage.get.refs"
|
||||
)
|
||||
const metricsGetCollectionPageRefs = getCollectionPageRefsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
const validatedData = collectionPageRefsSchema.safeParse(data)
|
||||
if (!validatedData.success) {
|
||||
getCollectionPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.collectionPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedData.error,
|
||||
})
|
||||
)
|
||||
metricsGetCollectionPageRefs.validationError(validatedData.error)
|
||||
return null
|
||||
}
|
||||
getCollectionPageRefsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.collectionPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetCollectionPageRefs.success()
|
||||
|
||||
return validatedData.data
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
GetContentPageBlocksBatch1,
|
||||
GetContentPageBlocksBatch2,
|
||||
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { contentPageSchema } from "./output"
|
||||
@@ -12,7 +13,6 @@ import {
|
||||
createPageType,
|
||||
fetchContentPageRefs,
|
||||
generatePageTags,
|
||||
getContentPageCounter,
|
||||
} from "./utils"
|
||||
|
||||
import type { TrackingSDKPageData } from "@/types/components/tracking"
|
||||
@@ -30,13 +30,16 @@ export const contentPageQueryRouter = router({
|
||||
|
||||
const tags = generatePageTags(contentPageRefs, lang)
|
||||
|
||||
getContentPageCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.contentPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getContentPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"contentPage.get"
|
||||
)
|
||||
const metricsGetContentPage = getContentPageCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetContentPage.start()
|
||||
|
||||
const contentPageRequest = await batchRequest<GetContentPageSchema>([
|
||||
{
|
||||
@@ -69,13 +72,12 @@ export const contentPageQueryRouter = router({
|
||||
|
||||
const contentPage = contentPageSchema.safeParse(contentPageRequest.data)
|
||||
if (!contentPage.success) {
|
||||
console.error(
|
||||
`Failed to validate Contentpage Data - (lang: ${lang}, uid: ${uid})`
|
||||
)
|
||||
console.error(contentPage.error?.format())
|
||||
metricsGetContentPage.validationError(contentPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetContentPage.success()
|
||||
|
||||
const tracking: TrackingSDKPageData = {
|
||||
pageId: contentPage.data.content_page.system.uid,
|
||||
domainLanguage: lang,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { batchRequest } from "@/lib/graphql/batchRequest"
|
||||
import {
|
||||
GetContentPageBlocksRefs,
|
||||
GetContentPageRefs,
|
||||
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
@@ -18,37 +17,24 @@ import { contentPageRefsSchema } from "./output"
|
||||
import { TrackingChannelEnum } from "@/types/components/tracking"
|
||||
import { ContentPageEnum } from "@/types/enums/contentPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
import type {
|
||||
ContentPageRefs,
|
||||
GetContentPageRefsSchema,
|
||||
import {
|
||||
type ContentPageRefs,
|
||||
type GetContentPageRefsSchema,
|
||||
} from "@/types/trpc/routers/contentstack/contentPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentPage")
|
||||
// OpenTelemetry metrics: ContentPage
|
||||
|
||||
export const getContentPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.contentPage.get"
|
||||
)
|
||||
|
||||
const getContentPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.contentPage.get"
|
||||
)
|
||||
const getContentPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.contentPage.get-fail"
|
||||
)
|
||||
const getContentPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.contentPage.get-success"
|
||||
)
|
||||
|
||||
export async function fetchContentPageRefs(lang: Lang, uid: string) {
|
||||
getContentPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.contentPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getContentPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"contentPage.get.refs"
|
||||
)
|
||||
const metricsGetContentPageRefs = getContentPageRefsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetContentPageRefs.start()
|
||||
|
||||
const res = await batchRequest<GetContentPageRefsSchema>([
|
||||
{
|
||||
document: GetContentPageRefs,
|
||||
@@ -69,50 +55,17 @@ export async function fetchContentPageRefs(lang: Lang, uid: string) {
|
||||
])
|
||||
if (!res.data) {
|
||||
const notFoundError = notFound(res)
|
||||
getContentPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
code: notFoundError.code,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.contentPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
uid,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetContentPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedData = contentPageRefsSchema.safeParse(res.data)
|
||||
if (!validatedData.success) {
|
||||
getContentPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.contentPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedData.error,
|
||||
})
|
||||
)
|
||||
metricsGetContentPageRefs.validationError(validatedData.error)
|
||||
return null
|
||||
}
|
||||
getContentPageRefsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.contentPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetContentPageRefs.success()
|
||||
|
||||
return validatedData.data
|
||||
}
|
||||
@@ -142,8 +95,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
case ContentPageEnum.ContentStack.blocks.Content:
|
||||
{
|
||||
if (block.content.length) {
|
||||
// TS has trouble infering the filtered types
|
||||
// @ts-ignore
|
||||
// @ts-expect-error: TS has trouble infering the filtered types
|
||||
connections.push(...block.content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentStackUidWithServiceProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { generateRefsResponseTag } from "@/utils/generateTag"
|
||||
@@ -13,14 +14,6 @@ import {
|
||||
destinationCityPageRefsSchema,
|
||||
destinationCityPageSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getDestinationCityPageCounter,
|
||||
getDestinationCityPageFailCounter,
|
||||
getDestinationCityPageRefsCounter,
|
||||
getDestinationCityPageRefsFailCounter,
|
||||
getDestinationCityPageRefsSuccessCounter,
|
||||
getDestinationCityPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
import { generatePageTags } from "./utils"
|
||||
|
||||
import {
|
||||
@@ -36,11 +29,14 @@ export const destinationCityPageQueryRouter = router({
|
||||
get: contentStackUidWithServiceProcedure.query(async ({ ctx }) => {
|
||||
const { lang, uid, serviceToken } = ctx
|
||||
|
||||
getDestinationCityPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.destinationCityPage.refs start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
const getDestinationCityPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationCityPage.get.refs"
|
||||
)
|
||||
const metricsGetDestinationCityPageRefs =
|
||||
getDestinationCityPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationCityPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetDestinationCityPageRefsSchema>(
|
||||
GetDestinationCityPageRefs,
|
||||
@@ -53,19 +49,7 @@ export const destinationCityPageQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getDestinationCityPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCityPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCityPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -73,33 +57,25 @@ export const destinationCityPageQueryRouter = router({
|
||||
refsResponse.data
|
||||
)
|
||||
if (!validatedRefsData.success) {
|
||||
getDestinationCityPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCityPage.refs validation error",
|
||||
JSON.stringify({ query: { lang, uid }, error: validatedRefsData.error })
|
||||
)
|
||||
metricsGetDestinationCityPageRefs.validationError(validatedRefsData.error)
|
||||
return null
|
||||
}
|
||||
getDestinationCityPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCityPage.refs success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
|
||||
metricsGetDestinationCityPageRefs.success()
|
||||
|
||||
const tags = generatePageTags(validatedRefsData.data, lang)
|
||||
|
||||
getDestinationCityPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCityPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getDestinationCityPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationCityPage.get"
|
||||
)
|
||||
const metricsGetDestinationCityPage = getDestinationCityPageCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetDestinationCityPage.start()
|
||||
|
||||
const response = await request<GetDestinationCityPageData>(
|
||||
GetDestinationCityPage,
|
||||
{
|
||||
@@ -113,40 +89,17 @@ export const destinationCityPageQueryRouter = router({
|
||||
)
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getDestinationCityPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCityPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCityPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedResponse = destinationCityPageSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getDestinationCityPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCityPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCityPage.validationError(validatedResponse.error)
|
||||
return null
|
||||
}
|
||||
|
||||
const destinationCityPage = validatedResponse.data.destination_city_page
|
||||
const cityIdentifier = destinationCityPage.destination_settings.city
|
||||
if (!cityIdentifier) {
|
||||
@@ -160,30 +113,16 @@ export const destinationCityPageQueryRouter = router({
|
||||
})
|
||||
|
||||
if (!city) {
|
||||
getDestinationCityPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: `Couldn't find city with cityIdentifier: ${cityIdentifier}`,
|
||||
})
|
||||
|
||||
console.error(
|
||||
"contentstack.destinationCityPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: `Couldn't find city with cityIdentifier: ${cityIdentifier}`,
|
||||
})
|
||||
metricsGetDestinationCityPage.dataError(
|
||||
`Failed to get city data for ${cityIdentifier}`,
|
||||
{
|
||||
cityIdentifier,
|
||||
}
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getDestinationCityPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCityPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCityPage.success()
|
||||
|
||||
const system = destinationCityPage.system
|
||||
const pageName = `destinations|${city.country}|${city.name}`
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.destinationCityPage")
|
||||
|
||||
export const getDestinationCityPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get"
|
||||
)
|
||||
export const getDestinationCityPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get-fail"
|
||||
)
|
||||
export const getDestinationCityPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get-success"
|
||||
)
|
||||
|
||||
export const getDestinationCityPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get"
|
||||
)
|
||||
export const getDestinationCityPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get-success"
|
||||
)
|
||||
export const getDestinationCityPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get-fail"
|
||||
)
|
||||
|
||||
export const getCityPageCountCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageCount.get"
|
||||
)
|
||||
export const getCityPageCountSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageCount.get-success"
|
||||
)
|
||||
export const getCityPageCountFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageCount.get-fail"
|
||||
)
|
||||
|
||||
export const getCityPageUrlsCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get"
|
||||
)
|
||||
export const getCityPageUrlsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get-success"
|
||||
)
|
||||
export const getCityPageUrlsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get-fail"
|
||||
)
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from "@/lib/graphql/Query/DestinationCountryPage/DestinationCountryPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import {
|
||||
contentStackBaseWithServiceProcedure,
|
||||
contentstackExtendedProcedureUID,
|
||||
@@ -17,14 +18,6 @@ import {
|
||||
destinationCountryPageRefsSchema,
|
||||
destinationCountryPageSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getDestinationCountryPageCounter,
|
||||
getDestinationCountryPageFailCounter,
|
||||
getDestinationCountryPageRefsCounter,
|
||||
getDestinationCountryPageRefsFailCounter,
|
||||
getDestinationCountryPageRefsSuccessCounter,
|
||||
getDestinationCountryPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
import { generatePageTags, getCityPages } from "./utils"
|
||||
|
||||
import {
|
||||
@@ -41,11 +34,14 @@ export const destinationCountryPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
getDestinationCountryPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.destinationCountryPage.refs start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
const getDestinationCountryPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationCountryPage.get.refs"
|
||||
)
|
||||
const metricsGetDestinationCountryPageRefs =
|
||||
getDestinationCountryPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationCountryPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetDestinationCountryPageRefsSchema>(
|
||||
GetDestinationCountryPageRefs,
|
||||
@@ -58,19 +54,7 @@ export const destinationCountryPageQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getDestinationCountryPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCountryPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCountryPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -78,33 +62,25 @@ export const destinationCountryPageQueryRouter = router({
|
||||
refsResponse.data
|
||||
)
|
||||
if (!validatedRefsData.success) {
|
||||
getDestinationCountryPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCountryPage.refs validation error",
|
||||
JSON.stringify({ query: { lang, uid }, error: validatedRefsData.error })
|
||||
metricsGetDestinationCountryPageRefs.validationError(
|
||||
validatedRefsData.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
getDestinationCountryPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCountryPage.refs success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
|
||||
metricsGetDestinationCountryPageRefs.success()
|
||||
|
||||
const tags = generatePageTags(validatedRefsData.data, lang)
|
||||
|
||||
getDestinationCountryPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCountryPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getDestinationCountryPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationCountryPage.get"
|
||||
)
|
||||
const metricsGetDestinationCountryPage =
|
||||
getDestinationCountryPageCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationCountryPage.start()
|
||||
|
||||
const response = await request<GetDestinationCountryPageData>(
|
||||
GetDestinationCountryPage,
|
||||
{
|
||||
@@ -118,19 +94,7 @@ export const destinationCountryPageQueryRouter = router({
|
||||
)
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getDestinationCountryPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCountryPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCountryPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -139,32 +103,15 @@ export const destinationCountryPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getDestinationCountryPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationCountryPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCountryPage.validationError(validatedResponse.error)
|
||||
return null
|
||||
}
|
||||
|
||||
const destinationCountryPage =
|
||||
validatedResponse.data.destination_country_page
|
||||
const country = destinationCountryPage.destination_settings.country
|
||||
|
||||
getDestinationCountryPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationCountryPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationCountryPage.success()
|
||||
|
||||
const system = destinationCountryPage.system
|
||||
const pageName = `destinations|${country}`
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.destinationCountryPage")
|
||||
|
||||
export const getDestinationCountryPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get"
|
||||
)
|
||||
export const getDestinationCountryPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get-fail"
|
||||
)
|
||||
export const getDestinationCountryPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get-success"
|
||||
)
|
||||
|
||||
export const getDestinationCountryPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get"
|
||||
)
|
||||
export const getDestinationCountryPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get-success"
|
||||
)
|
||||
export const getDestinationCountryPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCountryPage.get-fail"
|
||||
)
|
||||
|
||||
export const getCityListDataCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityListData.get"
|
||||
)
|
||||
export const getCityListDataSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityListData.get-success"
|
||||
)
|
||||
export const getCityListDataFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityListData.get-fail"
|
||||
)
|
||||
|
||||
export const getCountryPageUrlsCounter = meter.createCounter(
|
||||
"trpc.contentstack.getCountryPageUrls"
|
||||
)
|
||||
|
||||
export const getCountryPageUrlsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.getCountryPageUrls-success"
|
||||
)
|
||||
|
||||
export const getCountryPageUrlsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.getCountryPageUrls-fail"
|
||||
)
|
||||
@@ -1,20 +1,13 @@
|
||||
import { GetDestinationCityListData } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityListData.graphql"
|
||||
import { GetCountryPageUrls } from "@/lib/graphql/Query/DestinationCountryPage/DestinationCountryPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
||||
|
||||
import { getCitiesByCountry } from "../../hotels/utils"
|
||||
import { destinationCityListDataSchema } from "../destinationCityPage/output"
|
||||
import { countryPageUrlsSchema } from "./output"
|
||||
import {
|
||||
getCityListDataCounter,
|
||||
getCityListDataFailCounter,
|
||||
getCityListDataSuccessCounter,
|
||||
getCountryPageUrlsCounter,
|
||||
getCountryPageUrlsFailCounter,
|
||||
getCountryPageUrlsSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { ApiCountry, type Country } from "@/types/enums/country"
|
||||
import { DestinationCountryPageEnum } from "@/types/enums/destinationCountryPage"
|
||||
@@ -77,11 +70,16 @@ export async function getCityListDataByCityIdentifier(
|
||||
lang: Lang,
|
||||
cityIdentifier: string
|
||||
) {
|
||||
getCityListDataCounter.add(1, { lang, cityIdentifier })
|
||||
console.info(
|
||||
"contentstack.cityListData start",
|
||||
JSON.stringify({ query: { lang, cityIdentifier } })
|
||||
const getCityListDataCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"cityListData.get"
|
||||
)
|
||||
const metricsGetCityListData = getCityListDataCounter.init({
|
||||
lang,
|
||||
cityIdentifier,
|
||||
})
|
||||
|
||||
metricsGetCityListData.start()
|
||||
|
||||
const response = await request<GetDestinationCityListDataResponse>(
|
||||
GetDestinationCityListData,
|
||||
@@ -96,15 +94,8 @@ export async function getCityListDataByCityIdentifier(
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getCityListDataFailCounter.add(1, {
|
||||
lang,
|
||||
cityIdentifier,
|
||||
error_type: "not_found",
|
||||
error: `Destination city page not found for cityIdentifier: ${cityIdentifier}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityListData not found error",
|
||||
JSON.stringify({ query: { lang, cityIdentifier } })
|
||||
metricsGetCityListData.dataError(
|
||||
`Failed to get destination city page for cityIdentifier: ${cityIdentifier}`
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -114,26 +105,11 @@ export async function getCityListDataByCityIdentifier(
|
||||
)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getCityListDataFailCounter.add(1, {
|
||||
lang,
|
||||
cityIdentifier,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityListData validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, cityIdentifier },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetCityListData.validationError(validatedResponse.error)
|
||||
return null
|
||||
}
|
||||
getCityListDataSuccessCounter.add(1, { lang, cityIdentifier })
|
||||
console.info(
|
||||
"contentstack.cityListData success",
|
||||
JSON.stringify({ query: { lang, cityIdentifier } })
|
||||
)
|
||||
|
||||
metricsGetCityListData.success()
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
@@ -172,11 +148,13 @@ export async function getCityPages(
|
||||
}
|
||||
|
||||
export async function getCountryPageUrls(lang: Lang) {
|
||||
getCountryPageUrlsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.countryPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getCountryPageUrlsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"getCountryPageUrls"
|
||||
)
|
||||
const metricsGetCountryPageUrls = getCountryPageUrlsCounter.init({ lang })
|
||||
|
||||
metricsGetCountryPageUrls.start()
|
||||
|
||||
const tag = `${lang}:country_page_urls`
|
||||
const response = await request<GetCountryPageUrlsData>(
|
||||
@@ -191,14 +169,8 @@ export async function getCountryPageUrls(lang: Lang) {
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getCountryPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: `Country pages not found for lang: ${lang}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.countryPageUrls not found error",
|
||||
JSON.stringify({ query: { lang } })
|
||||
metricsGetCountryPageUrls.dataError(
|
||||
`Failed to get country pages for lang: ${lang}`
|
||||
)
|
||||
return []
|
||||
}
|
||||
@@ -208,26 +180,11 @@ export async function getCountryPageUrls(lang: Lang) {
|
||||
)
|
||||
|
||||
if (!validatedCountryPageUrls.success) {
|
||||
getCountryPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedCountryPageUrls.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.countryPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedCountryPageUrls.error,
|
||||
})
|
||||
)
|
||||
metricsGetCountryPageUrls.validationError(validatedCountryPageUrls.error)
|
||||
return []
|
||||
}
|
||||
|
||||
getCountryPageUrlsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.countryPageUrls success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetCountryPageUrls.success()
|
||||
|
||||
return validatedCountryPageUrls.data
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from "@/lib/graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import {
|
||||
contentstackExtendedProcedureUID,
|
||||
router,
|
||||
@@ -31,14 +32,6 @@ import {
|
||||
destinationOverviewPageRefsSchema,
|
||||
destinationOverviewPageSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getDestinationOverviewPageCounter,
|
||||
getDestinationOverviewPageFailCounter,
|
||||
getDestinationOverviewPageRefsCounter,
|
||||
getDestinationOverviewPageRefsFailCounter,
|
||||
getDestinationOverviewPageRefsSuccessCounter,
|
||||
getDestinationOverviewPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import type {
|
||||
Cities,
|
||||
@@ -57,13 +50,15 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
getDestinationOverviewPageRefsCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getDestinationOverviewPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationOverviewPage.get.refs"
|
||||
)
|
||||
const metricsGetDestinationOverviewPageRefs =
|
||||
getDestinationOverviewPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationOverviewPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetDestinationOverviewPageRefsSchema>(
|
||||
GetDestinationOverviewPageRefs,
|
||||
{
|
||||
@@ -77,19 +72,7 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getDestinationOverviewPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationOverviewPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -98,37 +81,23 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
getDestinationOverviewPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedRefsData.error,
|
||||
})
|
||||
metricsGetDestinationOverviewPageRefs.validationError(
|
||||
validatedRefsData.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getDestinationOverviewPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationOverviewPageRefs.success()
|
||||
|
||||
getDestinationOverviewPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getDestinationOverviewPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"destinationOverviewPage.get"
|
||||
)
|
||||
const metricsGetDestinationOverviewPage =
|
||||
getDestinationOverviewPageCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationOverviewPage.start()
|
||||
|
||||
const response = await request<GetDestinationOverviewPageData>(
|
||||
GetDestinationOverviewPage,
|
||||
{
|
||||
@@ -142,19 +111,7 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
)
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getDestinationOverviewPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationOverviewPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -163,29 +120,13 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!destinationOverviewPage.success) {
|
||||
getDestinationOverviewPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(destinationOverviewPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: destinationOverviewPage.error,
|
||||
})
|
||||
metricsGetDestinationOverviewPage.validationError(
|
||||
destinationOverviewPage.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getDestinationOverviewPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetDestinationOverviewPage.success()
|
||||
|
||||
const system = destinationOverviewPage.data.destination_overview_page.system
|
||||
const tracking: TrackingSDKPageData = {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.destinationOverviewPage")
|
||||
|
||||
export const getDestinationOverviewPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get"
|
||||
)
|
||||
export const getDestinationOverviewPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-fail"
|
||||
)
|
||||
export const getDestinationOverviewPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-success"
|
||||
)
|
||||
|
||||
export const getDestinationOverviewPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get"
|
||||
)
|
||||
export const getDestinationOverviewPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-success"
|
||||
)
|
||||
export const getDestinationOverviewPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-fail"
|
||||
)
|
||||
@@ -1,29 +1,27 @@
|
||||
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
|
||||
import { hotelPageSchema } from "./output"
|
||||
import {
|
||||
getHotelPageCounter,
|
||||
getHotelPageFailCounter,
|
||||
getHotelPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import type { GetHotelPageData } from "@/types/trpc/routers/contentstack/hotelPage"
|
||||
|
||||
export const hotelPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
getHotelPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.hotelPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
|
||||
const getHotelPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPage.get"
|
||||
)
|
||||
const metricsGetHotelPage = getHotelPageCounter.init({ lang, uid })
|
||||
|
||||
metricsGetHotelPage.start()
|
||||
|
||||
const response = await request<GetHotelPageData>(
|
||||
GetHotelPage,
|
||||
{
|
||||
@@ -37,48 +35,19 @@ export const hotelPageQueryRouter = router({
|
||||
)
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getHotelPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetHotelPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedHotelPage = hotelPageSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedHotelPage.success) {
|
||||
getHotelPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHotelPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedHotelPage.error,
|
||||
})
|
||||
)
|
||||
metricsGetHotelPage.validationError(validatedHotelPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getHotelPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.hotelPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetHotelPage.success()
|
||||
|
||||
return validatedHotelPage.data.hotel_page
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.hotelPage")
|
||||
|
||||
export const getHotelPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get"
|
||||
)
|
||||
export const getHotelPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-fail"
|
||||
)
|
||||
export const getHotelPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-success"
|
||||
)
|
||||
|
||||
export const getHotelPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get"
|
||||
)
|
||||
export const getHotelPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-success"
|
||||
)
|
||||
export const getHotelPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-fail"
|
||||
)
|
||||
|
||||
export const getHotelPageUrlsCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get"
|
||||
)
|
||||
export const getHotelPageUrlsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get-success"
|
||||
)
|
||||
export const getHotelPageUrlsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get-fail"
|
||||
)
|
||||
|
||||
export const getHotelPageCountCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageCount.get"
|
||||
)
|
||||
export const getHotelPageCountSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageCount.get-success"
|
||||
)
|
||||
export const getHotelPageCountFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageCount.get-fail"
|
||||
)
|
||||
@@ -3,6 +3,7 @@ import { GetHotelPageCount } from "@/lib/graphql/Query/HotelPage/HotelPageCount.
|
||||
import { GetHotelPageUrls } from "@/lib/graphql/Query/HotelPage/HotelPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
@@ -15,17 +16,6 @@ import {
|
||||
hotelPageCountSchema,
|
||||
hotelPageRefsSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getHotelPageCountCounter,
|
||||
getHotelPageCountFailCounter,
|
||||
getHotelPageCountSuccessCounter,
|
||||
getHotelPageRefsCounter,
|
||||
getHotelPageRefsFailCounter,
|
||||
getHotelPageRefsSuccessCounter,
|
||||
getHotelPageUrlsCounter,
|
||||
getHotelPageUrlsFailCounter,
|
||||
getHotelPageUrlsSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
@@ -38,13 +28,13 @@ import type {
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export async function fetchHotelPageRefs(lang: Lang, uid: string) {
|
||||
getHotelPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.hotelPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getHotelPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPage.get.refs"
|
||||
)
|
||||
const metricsGetHotelPageRefs = getHotelPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetHotelPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetHotelPageRefsSchema>(
|
||||
GetHotelPageRefs,
|
||||
@@ -56,26 +46,10 @@ export async function fetchHotelPageRefs(lang: Lang, uid: string) {
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getHotelPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
code: notFoundError.code,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
uid,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetHotelPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
return refsResponse.data
|
||||
}
|
||||
|
||||
@@ -84,30 +58,20 @@ export function validateHotelPageRefs(
|
||||
lang: Lang,
|
||||
uid: string
|
||||
) {
|
||||
const getHotelPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPage.get.refs"
|
||||
)
|
||||
const metricsGetHotelPageRefs = getHotelPageRefsCounter.init({ lang, uid })
|
||||
|
||||
const validatedData = hotelPageRefsSchema.safeParse(data)
|
||||
|
||||
if (!validatedData.success) {
|
||||
getHotelPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedData.error,
|
||||
})
|
||||
)
|
||||
metricsGetHotelPageRefs.validationError(validatedData.error)
|
||||
return null
|
||||
}
|
||||
getHotelPageRefsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.hotelPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetHotelPageRefs.success()
|
||||
|
||||
return validatedData.data
|
||||
}
|
||||
@@ -144,11 +108,14 @@ export function getConnections({ hotel_page }: HotelPageRefs) {
|
||||
}
|
||||
|
||||
export async function getHotelPageCount(lang: Lang) {
|
||||
getHotelPageCountCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageCount start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getHotelPageCountCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPageCount.get"
|
||||
)
|
||||
const metricsGetHotelPageCount = getHotelPageCountCounter.init({ lang })
|
||||
|
||||
metricsGetHotelPageCount.start()
|
||||
|
||||
const response = await request<GetHotelPageCountData>(
|
||||
GetHotelPageCount,
|
||||
{
|
||||
@@ -161,50 +128,31 @@ export async function getHotelPageCount(lang: Lang) {
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getHotelPageCountFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: `Hotel pages count not found for lang: ${lang}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageCount not found error",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
metricsGetHotelPageCount.noDataError()
|
||||
return 0
|
||||
}
|
||||
|
||||
const validatedResponse = hotelPageCountSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getHotelPageCountFailCounter.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,
|
||||
})
|
||||
)
|
||||
metricsGetHotelPageCount.validationError(validatedResponse.error)
|
||||
return 0
|
||||
}
|
||||
getHotelPageCountSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageCount success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetHotelPageCount.success()
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
export async function getHotelPageUrls(lang: Lang) {
|
||||
getHotelPageUrlsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
const getHotelPageUrlsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPageUrls.get"
|
||||
)
|
||||
const metricsGetHotelPageUrls = getHotelPageUrlsCounter.init({ lang })
|
||||
|
||||
metricsGetHotelPageUrls.start()
|
||||
|
||||
const count = await getHotelPageCount(lang)
|
||||
|
||||
if (count === 0) {
|
||||
@@ -236,25 +184,11 @@ export async function getHotelPageUrls(lang: Lang) {
|
||||
batchedHotelPageUrlsSchema.safeParse(batchedResponse)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getHotelPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
metricsGetHotelPageUrls.validationError(validatedResponse.error)
|
||||
return []
|
||||
}
|
||||
getHotelPageUrlsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageUrl success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
metricsGetHotelPageUrls.success()
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.languageSwitcher")
|
||||
export const getLanguageSwitcherCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get"
|
||||
)
|
||||
export const getLanguageSwitcherSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get-success"
|
||||
)
|
||||
export const getLanguageSwitcherFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get-fail"
|
||||
)
|
||||
@@ -41,16 +41,12 @@ import {
|
||||
GetFiNoSvUrlsStartPage,
|
||||
} from "@/lib/graphql/Query/StartPage/StartPage.graphql"
|
||||
import { internalServerError } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
import { removeTrailingSlash } from "@/utils/url"
|
||||
|
||||
import { validateLanguageSwitcherData } from "./output"
|
||||
import {
|
||||
getLanguageSwitcherCounter,
|
||||
getLanguageSwitcherFailCounter,
|
||||
getLanguageSwitcherSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { PageContentTypeEnum } from "@/types/requests/contentType"
|
||||
import type {
|
||||
@@ -65,21 +61,17 @@ export async function getUrlsOfAllLanguages(
|
||||
uid: string,
|
||||
contentType: string
|
||||
) {
|
||||
getLanguageSwitcherCounter.add(1, {
|
||||
uid,
|
||||
const getLanguageSwitcherCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"languageSwitcher.get"
|
||||
)
|
||||
const metricsGetLanguageSwitcher = getLanguageSwitcherCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
contentType,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.languageSwitcher start",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid,
|
||||
lang,
|
||||
contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetLanguageSwitcher.start()
|
||||
|
||||
const variables = { uid }
|
||||
const tagsDaDeEn = [
|
||||
@@ -184,42 +176,13 @@ export async function getUrlsOfAllLanguages(
|
||||
validateLanguageSwitcherData.safeParse(urls)
|
||||
|
||||
if (!validatedLanguageSwitcherData.success) {
|
||||
getLanguageSwitcherFailCounter.add(1, {
|
||||
uid,
|
||||
lang,
|
||||
contentType,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLanguageSwitcherData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.languageSwitcher validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid,
|
||||
lang,
|
||||
contentType,
|
||||
},
|
||||
error: validatedLanguageSwitcherData.error,
|
||||
})
|
||||
metricsGetLanguageSwitcher.validationError(
|
||||
validatedLanguageSwitcherData.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getLanguageSwitcherSuccessCounter.add(1, {
|
||||
uid,
|
||||
lang,
|
||||
contentType,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.languageSwitcher success",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid,
|
||||
lang,
|
||||
contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
metricsGetLanguageSwitcher.success()
|
||||
|
||||
return urls
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
import { cache } from "react"
|
||||
|
||||
import {
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
} from "@/lib/graphql/Query/LoyaltyLevels.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 { generateLoyaltyConfigTag } from "@/utils/generateTag"
|
||||
@@ -24,32 +24,14 @@ import {
|
||||
|
||||
import type { Context } from "@/server/context"
|
||||
|
||||
const meter = metrics.getMeter("trpc.loyaltyLevel")
|
||||
// OpenTelemetry metrics: Loyalty Level
|
||||
const getAllLoyaltyLevelCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.all"
|
||||
)
|
||||
|
||||
const getAllLoyaltyLevelSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.all-success"
|
||||
)
|
||||
const getAllLoyaltyLevelFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.all-fail"
|
||||
)
|
||||
|
||||
const getByLevelLoyaltyLevelCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.byLevel"
|
||||
)
|
||||
|
||||
const getByLevelLoyaltyLevelSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.byLevel-success"
|
||||
)
|
||||
const getByLevelLoyaltyLevelFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyLevel.byLevel-fail"
|
||||
)
|
||||
|
||||
export const getAllLoyaltyLevels = cache(async (ctx: Context) => {
|
||||
getAllLoyaltyLevelCounter.add(1)
|
||||
const getLoyaltyLevelAllCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"loyaltyLevel.all"
|
||||
)
|
||||
const metricsGetLoyaltyLevelAll = getLoyaltyLevelAllCounter.init()
|
||||
|
||||
metricsGetLoyaltyLevelAll.start()
|
||||
|
||||
// Ideally we should fetch all available tiers from API, but since they
|
||||
// are static, we can just use the enum values. We want to know which
|
||||
@@ -67,17 +49,8 @@ export const getAllLoyaltyLevels = cache(async (ctx: Context) => {
|
||||
)
|
||||
|
||||
if (!loyaltyLevelsConfigResponse.data) {
|
||||
getAllLoyaltyLevelFailCounter.add(1)
|
||||
const notFoundError = notFound(loyaltyLevelsConfigResponse)
|
||||
console.error(
|
||||
"contentstack.loyaltyLevels not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: ctx.lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyLevelAll.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -85,30 +58,28 @@ export const getAllLoyaltyLevels = cache(async (ctx: Context) => {
|
||||
loyaltyLevelsConfigResponse.data
|
||||
)
|
||||
if (!validatedLoyaltyLevels.success) {
|
||||
getAllLoyaltyLevelFailCounter.add(1)
|
||||
console.error(validatedLoyaltyLevels.error)
|
||||
console.error(
|
||||
"contentstack.rewards validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: ctx.lang,
|
||||
},
|
||||
error: validatedLoyaltyLevels.error,
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyLevelAll.validationError(validatedLoyaltyLevels.error)
|
||||
return []
|
||||
}
|
||||
|
||||
getAllLoyaltyLevelSuccessCounter.add(1)
|
||||
metricsGetLoyaltyLevelAll.success()
|
||||
|
||||
return validatedLoyaltyLevels.data
|
||||
})
|
||||
|
||||
export const getLoyaltyLevel = cache(
|
||||
async (ctx: Context, level_id: MembershipLevel) => {
|
||||
getByLevelLoyaltyLevelCounter.add(1, {
|
||||
query: JSON.stringify({ lang: ctx.lang, level_id }),
|
||||
const getLoyaltyLevelCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"loyaltyLevel.get"
|
||||
)
|
||||
const metricsGetLoyaltyLevel = getLoyaltyLevelCounter.init({
|
||||
lang: ctx.lang,
|
||||
level_id,
|
||||
})
|
||||
|
||||
metricsGetLoyaltyLevel.start()
|
||||
|
||||
const loyaltyLevelsConfigResponse = await request<LoyaltyLevelsResponse>(
|
||||
GetLoyaltyLevel,
|
||||
{ lang: ctx.lang, level_id },
|
||||
@@ -121,15 +92,8 @@ export const getLoyaltyLevel = cache(
|
||||
!loyaltyLevelsConfigResponse.data ||
|
||||
!loyaltyLevelsConfigResponse.data.all_loyalty_level.items.length
|
||||
) {
|
||||
getByLevelLoyaltyLevelFailCounter.add(1)
|
||||
const notFoundError = notFound(loyaltyLevelsConfigResponse)
|
||||
console.error(
|
||||
"contentstack.loyaltyLevel not found error",
|
||||
JSON.stringify({
|
||||
query: { lang: ctx.lang, level_id },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyLevel.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -137,19 +101,12 @@ export const getLoyaltyLevel = cache(
|
||||
loyaltyLevelsConfigResponse.data
|
||||
)
|
||||
if (!validatedLoyaltyLevels.success) {
|
||||
getByLevelLoyaltyLevelFailCounter.add(1)
|
||||
console.error(validatedLoyaltyLevels.error)
|
||||
console.error(
|
||||
"contentstack.loyaltyLevel validation error",
|
||||
JSON.stringify({
|
||||
query: { lang: ctx.lang, level_id },
|
||||
error: validatedLoyaltyLevels.error,
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyLevel.validationError(validatedLoyaltyLevels.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getByLevelLoyaltyLevelSuccessCounter.add(1)
|
||||
metricsGetLoyaltyLevel.success()
|
||||
|
||||
const result: LoyaltyLevel = validatedLoyaltyLevels.data[0]
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
GetLoyaltyPageRefs,
|
||||
} from "@/lib/graphql/Query/LoyaltyPage/LoyaltyPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
@@ -26,39 +25,22 @@ import type {
|
||||
GetLoyaltyPageSchema,
|
||||
} from "@/types/trpc/routers/contentstack/loyaltyPage"
|
||||
|
||||
const meter = metrics.getMeter("trpc.loyaltyPage")
|
||||
// OpenTelemetry metrics: LoyaltyPage
|
||||
const getLoyaltyPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get"
|
||||
)
|
||||
const getLoyaltyPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get-success"
|
||||
)
|
||||
const getLoyaltyPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get-fail"
|
||||
)
|
||||
const getLoyaltyPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get"
|
||||
)
|
||||
const getLoyaltyPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get-success"
|
||||
)
|
||||
const getLoyaltyPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.loyaltyPage.get-fail"
|
||||
)
|
||||
|
||||
export const loyaltyPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
const metricsVariables = { lang, uid }
|
||||
const variables = { locale: lang, uid }
|
||||
getLoyaltyPageRefsCounter.add(1, metricsVariables)
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs start",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
})
|
||||
|
||||
const getLoyaltyPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"loyaltyPage.get.refs"
|
||||
)
|
||||
const metricsGetLoyaltyPageRefs = getLoyaltyPageRefsCounter.init({
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
metricsGetLoyaltyPageRefs.start()
|
||||
|
||||
const variables = { locale: lang, uid }
|
||||
const refsResponse = await request<GetLoyaltyPageRefsSchema>(
|
||||
GetLoyaltyPageRefs,
|
||||
variables,
|
||||
@@ -70,20 +52,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getLoyaltyPageRefsFailCounter.add(1, {
|
||||
...metricsVariables,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
code: notFoundError.code,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -91,27 +60,11 @@ export const loyaltyPageQueryRouter = router({
|
||||
refsResponse.data
|
||||
)
|
||||
if (!validatedLoyaltyPageRefs.success) {
|
||||
getLoyaltyPageRefsFailCounter.add(1, {
|
||||
...metricsVariables,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLoyaltyPageRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
error: validatedLoyaltyPageRefs.error,
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyPageRefs.validationError(validatedLoyaltyPageRefs.error)
|
||||
return null
|
||||
}
|
||||
getLoyaltyPageRefsSuccessCounter.add(1, metricsVariables)
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs success",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetLoyaltyPageRefs.success()
|
||||
|
||||
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
||||
|
||||
@@ -119,13 +72,15 @@ export const loyaltyPageQueryRouter = router({
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||
].flat()
|
||||
getLoyaltyPageCounter.add(1, metricsVariables)
|
||||
console.info(
|
||||
"contentstack.loyaltyPage start",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
})
|
||||
|
||||
const getLoyaltyPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"loyaltyPage.get"
|
||||
)
|
||||
const metricsGetLoyaltyPage = getLoyaltyPageCounter.init({ lang, uid })
|
||||
|
||||
metricsGetLoyaltyPage.start()
|
||||
|
||||
const response = await request<GetLoyaltyPageSchema>(
|
||||
GetLoyaltyPage,
|
||||
variables,
|
||||
@@ -137,35 +92,13 @@ export const loyaltyPageQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getLoyaltyPageFailCounter.add(1, {
|
||||
...metricsVariables,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage not found error",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
metricsGetLoyaltyPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedLoyaltyPage = loyaltyPageSchema.safeParse(response.data)
|
||||
if (!validatedLoyaltyPage.success) {
|
||||
getLoyaltyPageFailCounter.add(1, {
|
||||
...metricsVariables,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLoyaltyPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage validation error",
|
||||
JSON.stringify({
|
||||
query: metricsVariables,
|
||||
error: validatedLoyaltyPage.error,
|
||||
})
|
||||
)
|
||||
metricsGetLoyaltyPage.validationError(validatedLoyaltyPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -182,11 +115,8 @@ export const loyaltyPageQueryRouter = router({
|
||||
siteSections: validatedLoyaltyPage.data.trackingProps.url,
|
||||
siteVersion: "new-web",
|
||||
}
|
||||
getLoyaltyPageSuccessCounter.add(1, metricsVariables)
|
||||
console.info(
|
||||
"contentstack.loyaltyPage success",
|
||||
JSON.stringify({ query: metricsVariables })
|
||||
)
|
||||
|
||||
metricsGetLoyaltyPage.success()
|
||||
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
import { cache } from "react"
|
||||
|
||||
import { GetAccountPageMetadata } from "@/lib/graphql/Query/AccountPage/Metadata.graphql"
|
||||
@@ -12,6 +11,7 @@ import { GetLoyaltyPageMetadata } from "@/lib/graphql/Query/LoyaltyPage/Metadata
|
||||
import { GetStartPageMetadata } from "@/lib/graphql/Query/StartPage/Metadata.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentStackUidWithServiceProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
@@ -29,37 +29,15 @@ import type { LanguageSwitcherData } from "@/types/requests/languageSwitcher"
|
||||
import type { RawMetadataSchema } from "@/types/trpc/routers/contentstack/metadata"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.metadata")
|
||||
|
||||
// OpenTelemetry metrics
|
||||
const fetchMetadataCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.get"
|
||||
)
|
||||
const fetchMetadataSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.get-success"
|
||||
)
|
||||
const fetchMetadataFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.get-fail"
|
||||
)
|
||||
const transformMetadataCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.transform"
|
||||
)
|
||||
const transformMetadataSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.transform-success"
|
||||
)
|
||||
const transformMetadataFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.metadata.transform-fail"
|
||||
)
|
||||
|
||||
const fetchMetadata = cache(async function fetchMemoizedMetadata<T>(
|
||||
query: string,
|
||||
{ uid, lang }: { uid: string; lang: Lang }
|
||||
) {
|
||||
fetchMetadataCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.metadata fetch start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
const getMetadataCounter = createCounter("trpc.contentstack", "metadata.get")
|
||||
const metricsGetMetadata = getMetadataCounter.init({ lang, uid })
|
||||
|
||||
metricsGetMetadata.start()
|
||||
|
||||
const response = await request<T>(
|
||||
query,
|
||||
{ locale: lang, uid },
|
||||
@@ -68,54 +46,35 @@ const fetchMetadata = cache(async function fetchMemoizedMetadata<T>(
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
fetchMetadataFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.metadata fetch not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetMetadata.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
fetchMetadataSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.metadata fetch success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
metricsGetMetadata.success()
|
||||
|
||||
return response.data
|
||||
})
|
||||
|
||||
async function getTransformedMetadata(data: unknown) {
|
||||
transformMetadataCounter.add(1)
|
||||
console.info("contentstack.metadata transform start")
|
||||
const transformMetadataCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"metadata.transform"
|
||||
)
|
||||
const metricsTransformMetadata = transformMetadataCounter.init()
|
||||
|
||||
metricsTransformMetadata.start()
|
||||
|
||||
const validatedMetadata = await metadataSchema.safeParseAsync(data)
|
||||
|
||||
if (!validatedMetadata.success) {
|
||||
transformMetadataFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedMetadata.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.metadata validation error",
|
||||
JSON.stringify({
|
||||
error: validatedMetadata.error,
|
||||
})
|
||||
)
|
||||
metricsTransformMetadata.validationError(validatedMetadata.error)
|
||||
return null
|
||||
}
|
||||
|
||||
transformMetadataSuccessCounter.add(1)
|
||||
console.info("contentstack.metadata transform success")
|
||||
metricsTransformMetadata.success()
|
||||
|
||||
return validatedMetadata.data
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
import { cache } from "react"
|
||||
|
||||
import { GetAllSasTierComparison } from "@/lib/graphql/Query/SASTierComparison.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 { validateSasTierComparisonSchema } from "./output"
|
||||
@@ -11,20 +11,16 @@ import { validateSasTierComparisonSchema } from "./output"
|
||||
import type { SasTierComparisonResponse } from "@/types/trpc/routers/contentstack/partner"
|
||||
import type { Context } from "@/server/context"
|
||||
|
||||
const meter = metrics.getMeter("trpc.partner")
|
||||
const getSasTierComparisonCounter = meter.createCounter(
|
||||
"trpc.contentstack.partner.getSasTierComparison"
|
||||
)
|
||||
|
||||
const getSasTierComparisonSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.partner.getSasTierComparison-success"
|
||||
)
|
||||
const getSasTierComparisonFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.partner.getSasTierComparison-fail"
|
||||
)
|
||||
|
||||
export const getSasTierComparison = cache(async (ctx: Context) => {
|
||||
getSasTierComparisonCounter.add(1)
|
||||
const getSasTierComparisonCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"partner.getSasTierComparison"
|
||||
)
|
||||
const metricsGetSasTierComparison = getSasTierComparisonCounter.init({
|
||||
lang: ctx.lang,
|
||||
})
|
||||
|
||||
metricsGetSasTierComparison.start()
|
||||
|
||||
const tag = `${ctx.lang}:sas_tier_comparison`
|
||||
const sasTierComparisonConfigResponse =
|
||||
@@ -38,17 +34,8 @@ export const getSasTierComparison = cache(async (ctx: Context) => {
|
||||
)
|
||||
|
||||
if (!sasTierComparisonConfigResponse.data) {
|
||||
getSasTierComparisonFailCounter.add(1)
|
||||
const notFoundError = notFound(sasTierComparisonConfigResponse)
|
||||
console.error(
|
||||
"contentstack.sas not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: ctx.lang,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetSasTierComparison.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -57,21 +44,14 @@ export const getSasTierComparison = cache(async (ctx: Context) => {
|
||||
)
|
||||
|
||||
if (!validatedSasTierComparison.success) {
|
||||
getSasTierComparisonFailCounter.add(1)
|
||||
console.error(validatedSasTierComparison.error)
|
||||
console.error(
|
||||
"contentstack.sas validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang: ctx.lang,
|
||||
},
|
||||
error: validatedSasTierComparison.error,
|
||||
})
|
||||
metricsGetSasTierComparison.validationError(
|
||||
validatedSasTierComparison.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getSasTierComparisonSuccessCounter.add(1)
|
||||
metricsGetSasTierComparison.success()
|
||||
|
||||
return validatedSasTierComparison.data
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as api from "@/lib/api"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import {
|
||||
contentStackBaseWithProtectedProcedure,
|
||||
contentStackBaseWithServiceProcedure,
|
||||
@@ -22,24 +23,9 @@ import {
|
||||
} from "./input"
|
||||
import { validateCategorizedRewardsSchema } from "./output"
|
||||
import {
|
||||
getAllRewardCounter,
|
||||
getAllRewardFailCounter,
|
||||
getAllRewardSuccessCounter,
|
||||
getByLevelRewardCounter,
|
||||
getByLevelRewardFailCounter,
|
||||
getByLevelRewardSuccessCounter,
|
||||
getCachedAllTierRewards,
|
||||
getCmsRewards,
|
||||
getCurrentRewardCounter,
|
||||
getCurrentRewardFailCounter,
|
||||
getCurrentRewardSuccessCounter,
|
||||
getRedeemCounter,
|
||||
getRedeemFailCounter,
|
||||
getRedeemSuccessCounter,
|
||||
getUniqueRewardIds,
|
||||
getUnwrapSurpriseCounter,
|
||||
getUnwrapSurpriseFailCounter,
|
||||
getUnwrapSurpriseSuccessCounter,
|
||||
} from "./utils"
|
||||
|
||||
import type { BaseReward, Surprise } from "@/types/components/myPages/rewards"
|
||||
@@ -50,7 +36,14 @@ export const rewardQueryRouter = router({
|
||||
all: contentStackBaseWithServiceProcedure
|
||||
.input(rewardsAllInput)
|
||||
.query(async function ({ input, ctx }) {
|
||||
getAllRewardCounter.add(1)
|
||||
const getContentstackRewardAllCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.all"
|
||||
)
|
||||
const metricsGetContentstackRewardAll =
|
||||
getContentstackRewardAllCounter.init()
|
||||
|
||||
metricsGetContentstackRewardAll.start()
|
||||
|
||||
const allApiRewards = await getCachedAllTierRewards(ctx.serviceToken)
|
||||
|
||||
@@ -75,16 +68,23 @@ export const rewardQueryRouter = router({
|
||||
const levelsWithRewards = Object.entries(allApiRewards).map(
|
||||
([level, rewards]) => {
|
||||
const combinedRewards = rewards
|
||||
.filter((r) => (input.unique ? r?.rewardTierLevel === level : true))
|
||||
.filter((reward) =>
|
||||
input.unique ? reward.rewardTierLevel === level : true
|
||||
)
|
||||
.map((reward) => {
|
||||
const contentStackReward = contentStackRewards.find((r) => {
|
||||
return r.reward_id === reward?.rewardId
|
||||
return r.reward_id === reward.rewardId
|
||||
})
|
||||
|
||||
if (contentStackReward) {
|
||||
return contentStackReward
|
||||
} else {
|
||||
console.error("No contentStackReward found", reward?.rewardId)
|
||||
metricsGetContentstackRewardAll.dataError(
|
||||
`Failed to find reward in CMS for reward ${reward.rewardId} `,
|
||||
{
|
||||
rewardId: reward.rewardId,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.filter((reward): reward is CMSReward => Boolean(reward))
|
||||
@@ -94,9 +94,9 @@ export const rewardQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!levelConfig) {
|
||||
getAllRewardFailCounter.add(1)
|
||||
|
||||
console.error("contentstack.loyaltyLevels level not found")
|
||||
metricsGetContentstackRewardAll.dataError(
|
||||
`Failed to matched loyalty level between API and CMS for level ${level}`
|
||||
)
|
||||
throw notFound()
|
||||
}
|
||||
const result: LevelWithRewards = {
|
||||
@@ -107,21 +107,31 @@ export const rewardQueryRouter = router({
|
||||
}
|
||||
)
|
||||
|
||||
getAllRewardSuccessCounter.add(1)
|
||||
metricsGetContentstackRewardAll.success()
|
||||
|
||||
return levelsWithRewards
|
||||
}),
|
||||
byLevel: contentStackBaseWithServiceProcedure
|
||||
.input(rewardsByLevelInput)
|
||||
.query(async function ({ input, ctx }) {
|
||||
getByLevelRewardCounter.add(1)
|
||||
const { level_id } = input
|
||||
|
||||
const getRewardByLevelCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.byLevel"
|
||||
)
|
||||
const metricsGetRewardByLevel = getRewardByLevelCounter.init({
|
||||
level_id,
|
||||
})
|
||||
|
||||
metricsGetRewardByLevel.start()
|
||||
|
||||
const allUpcomingApiRewards = await getCachedAllTierRewards(
|
||||
ctx.serviceToken
|
||||
)
|
||||
|
||||
if (!allUpcomingApiRewards || !allUpcomingApiRewards[level_id]) {
|
||||
getByLevelRewardFailCounter.add(1)
|
||||
metricsGetRewardByLevel.noDataError()
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -150,24 +160,36 @@ export const rewardQueryRouter = router({
|
||||
const levelsWithRewards = apiRewards
|
||||
.map((reward) => {
|
||||
const contentStackReward = contentStackRewards.find((r) => {
|
||||
return r.reward_id === reward?.rewardId
|
||||
return r.reward_id === reward.rewardId
|
||||
})
|
||||
|
||||
if (contentStackReward) {
|
||||
return contentStackReward
|
||||
} else {
|
||||
console.info("No contentStackReward found", reward?.rewardId)
|
||||
metricsGetRewardByLevel.dataError(
|
||||
`Failed to find reward in Contentstack with rewardId: ${reward.rewardId}`,
|
||||
{
|
||||
rewardId: reward.rewardId,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.filter((reward): reward is CMSReward => Boolean(reward))
|
||||
|
||||
getByLevelRewardSuccessCounter.add(1)
|
||||
metricsGetRewardByLevel.success()
|
||||
|
||||
return { level: loyaltyLevelsConfig, rewards: levelsWithRewards }
|
||||
}),
|
||||
current: contentStackBaseWithProtectedProcedure
|
||||
.input(langInput.optional()) // lang is required for client, but not for server
|
||||
.query(async function ({ ctx }) {
|
||||
getCurrentRewardCounter.add(1)
|
||||
const getCurrentRewardCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.current"
|
||||
)
|
||||
const metricsGetCurrentReward = getCurrentRewardCounter.init()
|
||||
|
||||
metricsGetCurrentReward.start()
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.Profile.Reward.reward,
|
||||
@@ -179,25 +201,7 @@ export const rewardQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
getCurrentRewardFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.reward error ",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
await metricsGetCurrentReward.httpError(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -207,19 +211,7 @@ export const rewardQueryRouter = router({
|
||||
validateCategorizedRewardsSchema.safeParse(data)
|
||||
|
||||
if (!validatedApiRewards.success) {
|
||||
getCurrentRewardFailCounter.add(1, {
|
||||
locale: ctx.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedApiRewards.error),
|
||||
})
|
||||
console.error(validatedApiRewards.error)
|
||||
console.error(
|
||||
"contentstack.rewards validation error",
|
||||
JSON.stringify({
|
||||
query: { locale: ctx.lang },
|
||||
error: validatedApiRewards.error,
|
||||
})
|
||||
)
|
||||
metricsGetCurrentReward.validationError(validatedApiRewards.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -243,14 +235,20 @@ export const rewardQueryRouter = router({
|
||||
}
|
||||
})
|
||||
|
||||
getCurrentRewardSuccessCounter.add(1)
|
||||
metricsGetCurrentReward.success()
|
||||
|
||||
return { rewards }
|
||||
}),
|
||||
surprises: contentStackBaseWithProtectedProcedure
|
||||
.input(langInput.optional()) // lang is required for client, but not for server
|
||||
.query(async ({ ctx }) => {
|
||||
getCurrentRewardCounter.add(1)
|
||||
const getSurprisesCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"surprises"
|
||||
)
|
||||
const metricsGetSurprises = getSurprisesCounter.init()
|
||||
|
||||
metricsGetSurprises.start()
|
||||
|
||||
const endpoint = api.endpoints.v1.Profile.Reward.reward
|
||||
|
||||
@@ -262,25 +260,7 @@ export const rewardQueryRouter = router({
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
getCurrentRewardFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.reward error ",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
await metricsGetSurprises.httpError(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -289,19 +269,7 @@ export const rewardQueryRouter = router({
|
||||
validateCategorizedRewardsSchema.safeParse(data)
|
||||
|
||||
if (!validatedApiRewards.success) {
|
||||
getCurrentRewardFailCounter.add(1, {
|
||||
locale: ctx.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedApiRewards.error),
|
||||
})
|
||||
console.error(validatedApiRewards.error)
|
||||
console.error(
|
||||
"contentstack.surprises validation error",
|
||||
JSON.stringify({
|
||||
query: { locale: ctx.lang },
|
||||
error: validatedApiRewards.error,
|
||||
})
|
||||
)
|
||||
metricsGetSurprises.validationError(validatedApiRewards.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -316,8 +284,6 @@ export const rewardQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
getCurrentRewardSuccessCounter.add(1)
|
||||
|
||||
const surprises: Surprise[] = cmsRewards
|
||||
.map((cmsReward) => {
|
||||
// Non-null assertion is used here because we know our reward exist
|
||||
@@ -336,73 +302,80 @@ export const rewardQueryRouter = router({
|
||||
})
|
||||
.flatMap((surprises) => (surprises ? [surprises] : []))
|
||||
|
||||
metricsGetSurprises.success()
|
||||
|
||||
return surprises
|
||||
}),
|
||||
unwrap: protectedProcedure
|
||||
.input(rewardsUpdateInput)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
getUnwrapSurpriseCounter.add(1)
|
||||
const results = await Promise.allSettled(
|
||||
// Execute each unwrap individually
|
||||
input.map(({ rewardId, couponCode }) => {
|
||||
async function handleUnwrap() {
|
||||
const getUnwrapSurpriseCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.unwrap"
|
||||
)
|
||||
|
||||
const promises = input.map(({ rewardId, couponCode }) => {
|
||||
return api.post(api.endpoints.v1.Profile.Reward.unwrap, {
|
||||
body: {
|
||||
rewardId,
|
||||
couponCode,
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
const responses = await Promise.all(promises)
|
||||
|
||||
const errors = await Promise.all(
|
||||
responses.map(async (apiResponse) => {
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
|
||||
getUnwrapSurpriseFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
const metricsGetUnwrapSurprise = getUnwrapSurpriseCounter.init({
|
||||
rewardId,
|
||||
couponCode,
|
||||
})
|
||||
|
||||
console.error(
|
||||
"contentstack.unwrap API error",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
metricsGetUnwrapSurprise.start()
|
||||
|
||||
const apiResponse = await api.post(
|
||||
api.endpoints.v1.Profile.Reward.unwrap,
|
||||
{
|
||||
body: {
|
||||
rewardId,
|
||||
couponCode,
|
||||
},
|
||||
query: {},
|
||||
})
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
return false
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
metricsGetUnwrapSurprise.httpError(apiResponse)
|
||||
return false
|
||||
}
|
||||
|
||||
metricsGetUnwrapSurprise.success()
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
|
||||
return handleUnwrap()
|
||||
})
|
||||
)
|
||||
|
||||
if (errors.filter((ok) => !ok).length > 0) {
|
||||
if (
|
||||
results.some(
|
||||
(result) => result.status === "rejected" || result.value === false
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
getUnwrapSurpriseSuccessCounter.add(1)
|
||||
|
||||
return true
|
||||
}),
|
||||
redeem: protectedProcedure
|
||||
.input(rewardsRedeemInput)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
getRedeemCounter.add(1)
|
||||
|
||||
const { rewardId, couponCode } = input
|
||||
|
||||
const getRedeemCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.redeem"
|
||||
)
|
||||
|
||||
const metricGetRedeem = getRedeemCounter.init({ rewardId, couponCode })
|
||||
|
||||
metricGetRedeem.start()
|
||||
|
||||
const apiResponse = await api.post(
|
||||
api.endpoints.v1.Profile.Reward.redeem,
|
||||
{
|
||||
@@ -417,29 +390,11 @@ export const rewardQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
getRedeemFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.redeem error ",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
metricGetRedeem.httpError(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
getRedeemSuccessCounter.add(1)
|
||||
metricGetRedeem.success()
|
||||
|
||||
return true
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import * as api from "@/lib/api"
|
||||
import {
|
||||
GetRewards as GetRewards,
|
||||
@@ -7,6 +5,7 @@ import {
|
||||
} from "@/lib/graphql/Query/RewardsWithRedeem.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import { getCacheClient } from "@/services/dataCache"
|
||||
import {
|
||||
@@ -26,63 +25,6 @@ import type {
|
||||
} from "@/types/trpc/routers/contentstack/reward"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.reward")
|
||||
export const getAllRewardCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all"
|
||||
)
|
||||
export const getAllRewardFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all-fail"
|
||||
)
|
||||
export const getAllRewardSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all-success"
|
||||
)
|
||||
export const getCurrentRewardCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.current"
|
||||
)
|
||||
export const getCurrentRewardFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.current-fail"
|
||||
)
|
||||
export const getCurrentRewardSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.current-success"
|
||||
)
|
||||
export const getByLevelRewardCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.byLevel"
|
||||
)
|
||||
export const getByLevelRewardFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.byLevel-fail"
|
||||
)
|
||||
export const getByLevelRewardSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.byLevel-success"
|
||||
)
|
||||
export const getUnwrapSurpriseCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.unwrap"
|
||||
)
|
||||
export const getUnwrapSurpriseFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.unwrap-fail"
|
||||
)
|
||||
export const getUnwrapSurpriseSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.unwrap-success"
|
||||
)
|
||||
export const getRedeemCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.redeem"
|
||||
)
|
||||
export const getRedeemFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.redeem-fail"
|
||||
)
|
||||
export const getRedeemSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.redeem-success"
|
||||
)
|
||||
|
||||
export const getAllCMSRewardRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all"
|
||||
)
|
||||
export const getAllCMSRewardRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all-fail"
|
||||
)
|
||||
export const getAllCMSRewardRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.reward.all-success"
|
||||
)
|
||||
|
||||
export function getUniqueRewardIds(rewardIds: string[]) {
|
||||
const uniqueRewardIds = new Set(rewardIds)
|
||||
return Array.from(uniqueRewardIds)
|
||||
@@ -97,6 +39,14 @@ export async function getCachedAllTierRewards(token: string) {
|
||||
return await cacheClient.cacheOrGet(
|
||||
"getAllTierRewards",
|
||||
async () => {
|
||||
const getApiRewardAllTiersCounter = createCounter(
|
||||
"trpc.api",
|
||||
"reward.allTiers"
|
||||
)
|
||||
const metricsGetApiRewardAllTiers = getApiRewardAllTiersCounter.init()
|
||||
|
||||
metricsGetApiRewardAllTiers.start()
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.Profile.Reward.allTiers,
|
||||
{
|
||||
@@ -107,26 +57,7 @@ export async function getCachedAllTierRewards(token: string) {
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
getAllRewardFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.rewards.allTiers error ",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
metricsGetApiRewardAllTiers.httpError(apiResponse)
|
||||
throw apiResponse
|
||||
}
|
||||
|
||||
@@ -135,20 +66,14 @@ export async function getCachedAllTierRewards(token: string) {
|
||||
validateApiAllTiersSchema.safeParse(data)
|
||||
|
||||
if (!validatedApiAllTierRewards.success) {
|
||||
getAllRewardFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedApiAllTierRewards.error),
|
||||
})
|
||||
console.error(validatedApiAllTierRewards.error)
|
||||
console.error(
|
||||
"api.rewards validation error",
|
||||
JSON.stringify({
|
||||
error: validatedApiAllTierRewards.error,
|
||||
})
|
||||
metricsGetApiRewardAllTiers.validationError(
|
||||
validatedApiAllTierRewards.error
|
||||
)
|
||||
throw validatedApiAllTierRewards.error
|
||||
}
|
||||
|
||||
metricsGetApiRewardAllTiers.success()
|
||||
|
||||
return validatedApiAllTierRewards.data
|
||||
},
|
||||
"1h"
|
||||
@@ -164,13 +89,15 @@ export async function getCmsRewards(lang: Lang, rewardIds: string[]) {
|
||||
generateLoyaltyConfigTag(lang, "reward", id)
|
||||
)
|
||||
|
||||
getAllCMSRewardRefsCounter.add(1, { lang, rewardIds })
|
||||
console.info(
|
||||
"contentstack.reward.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, rewardIds },
|
||||
})
|
||||
const getContentstackRewardAllRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.all.refs"
|
||||
)
|
||||
const metricsGetContentstackRewardAllRefs =
|
||||
getContentstackRewardAllRefsCounter.init({ lang, rewardIds })
|
||||
|
||||
metricsGetContentstackRewardAllRefs.start()
|
||||
|
||||
const refsResponse = await request<GetRewardRefsSchema>(
|
||||
GetRewardsRef,
|
||||
{
|
||||
@@ -182,50 +109,30 @@ export async function getCmsRewards(lang: Lang, rewardIds: string[]) {
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getAllCMSRewardRefsFailCounter.add(1, {
|
||||
lang,
|
||||
rewardIds,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.reward.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, rewardIds },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetContentstackRewardAllRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedRefsData = rewardRefsSchema.safeParse(refsResponse)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
getAllCMSRewardRefsFailCounter.add(1, {
|
||||
lang,
|
||||
rewardIds,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.reward.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, rewardIds },
|
||||
error: validatedRefsData.error,
|
||||
})
|
||||
)
|
||||
metricsGetContentstackRewardAllRefs.validationError(validatedRefsData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getAllCMSRewardRefsSuccessCounter.add(1, { lang, rewardIds })
|
||||
console.info(
|
||||
"contentstack.startPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, rewardIds },
|
||||
})
|
||||
metricsGetContentstackRewardAllRefs.success()
|
||||
|
||||
const getContentstackRewardAllCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"reward.all"
|
||||
)
|
||||
const metricsGetContentstackRewardAll = getContentstackRewardAllCounter.init({
|
||||
lang,
|
||||
rewardIds,
|
||||
})
|
||||
|
||||
const cmsRewardsResponse = await request<CMSRewardsResponse>(
|
||||
GetRewards,
|
||||
@@ -240,22 +147,8 @@ export async function getCmsRewards(lang: Lang, rewardIds: string[]) {
|
||||
)
|
||||
|
||||
if (!cmsRewardsResponse.data) {
|
||||
getAllRewardFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(cmsRewardsResponse.data),
|
||||
})
|
||||
const notFoundError = notFound(cmsRewardsResponse)
|
||||
console.error(
|
||||
"contentstack.rewards not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
locale: lang,
|
||||
rewardIds,
|
||||
},
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetContentstackRewardAll.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -263,22 +156,11 @@ export async function getCmsRewards(lang: Lang, rewardIds: string[]) {
|
||||
validateCmsRewardsSchema.safeParse(cmsRewardsResponse)
|
||||
|
||||
if (!validatedCmsRewards.success) {
|
||||
getAllRewardFailCounter.add(1, {
|
||||
locale: lang,
|
||||
rewardIds,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedCmsRewards.error),
|
||||
})
|
||||
console.error(validatedCmsRewards.error)
|
||||
console.error(
|
||||
"contentstack.rewards validation error",
|
||||
JSON.stringify({
|
||||
query: { locale: lang, rewardIds },
|
||||
error: validatedCmsRewards.error,
|
||||
})
|
||||
)
|
||||
metricsGetContentstackRewardAll.validationError(validatedCmsRewards.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetContentstackRewardAll.success()
|
||||
|
||||
return validatedCmsRewards.data
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from "@/lib/graphql/Query/StartPage/StartPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
@@ -13,14 +14,6 @@ import {
|
||||
} from "@/utils/generateTag"
|
||||
|
||||
import { startPageRefsSchema, startPageSchema } from "./output"
|
||||
import {
|
||||
getStartPageCounter,
|
||||
getStartPageFailCounter,
|
||||
getStartPageRefsCounter,
|
||||
getStartPageRefsFailCounter,
|
||||
getStartPageRefsSuccessCounter,
|
||||
getStartPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
import { getConnections } from "./utils"
|
||||
|
||||
import {
|
||||
@@ -36,13 +29,14 @@ export const startPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
getStartPageRefsCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.startPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getStartPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"startPage.get.refs"
|
||||
)
|
||||
const metricsGetStartPageRefs = getStartPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetStartPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetStartPageRefsSchema>(
|
||||
GetStartPageRefs,
|
||||
{
|
||||
@@ -56,56 +50,26 @@ export const startPageQueryRouter = router({
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getStartPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.startPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetStartPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedRefsData = startPageRefsSchema.safeParse(refsResponse.data)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
getStartPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.startPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedRefsData.error,
|
||||
})
|
||||
)
|
||||
metricsGetStartPageRefs.validationError(validatedRefsData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getStartPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.startPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetStartPageRefs.success()
|
||||
|
||||
getStartPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.startPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
const getStartPageCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"startPage.get"
|
||||
)
|
||||
const metricsGetStartPage = getStartPageCounter.init({ lang, uid })
|
||||
|
||||
metricsGetStartPage.start()
|
||||
|
||||
const connections = getConnections(validatedRefsData.data)
|
||||
|
||||
@@ -113,6 +77,7 @@ export const startPageQueryRouter = router({
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTag(lang, validatedRefsData.data.start_page.system.uid),
|
||||
].flat()
|
||||
|
||||
const response = await request<GetStartPageData>(
|
||||
GetStartPage,
|
||||
{
|
||||
@@ -127,48 +92,18 @@ export const startPageQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getStartPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.startPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
metricsGetStartPage.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const startPage = startPageSchema.safeParse(response.data)
|
||||
|
||||
if (!startPage.success) {
|
||||
getStartPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(startPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.startPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: startPage.error,
|
||||
})
|
||||
)
|
||||
metricsGetStartPage.validationError(startPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
getStartPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.startPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
metricsGetStartPage.success()
|
||||
|
||||
const system = startPage.data.start_page.system
|
||||
const tracking: TrackingSDKPageData = {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.startPage")
|
||||
|
||||
export const getStartPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get"
|
||||
)
|
||||
export const getStartPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get-fail"
|
||||
)
|
||||
export const getStartPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get-success"
|
||||
)
|
||||
|
||||
export const getStartPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get"
|
||||
)
|
||||
export const getStartPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get-success"
|
||||
)
|
||||
export const getStartPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.startPage.get-fail"
|
||||
)
|
||||
Reference in New Issue
Block a user