feat: add metrics
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetAccountPage,
|
||||
@@ -32,9 +34,32 @@ import { Embeds } from "@/types/requests/embeds"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
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 } })
|
||||
@@ -52,6 +77,12 @@ 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({
|
||||
@@ -67,6 +98,12 @@ export const accountPageQueryRouter = router({
|
||||
const validatedAccountPageRefs =
|
||||
validateAccountPageRefsSchema.safeParse(cleanedData)
|
||||
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({
|
||||
@@ -83,6 +120,8 @@ export const accountPageQueryRouter = router({
|
||||
generateTags(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 } })
|
||||
@@ -98,6 +137,12 @@ 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({
|
||||
@@ -113,6 +158,12 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
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({
|
||||
@@ -122,6 +173,7 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getAccountPageSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
||||
import {
|
||||
GetCurrentFooter,
|
||||
@@ -26,11 +28,58 @@ import {
|
||||
validateHeaderConfigSchema,
|
||||
} from "./output"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.base")
|
||||
// OpenTelemetry metrics: ContactConfig
|
||||
const getContactConfigCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get"
|
||||
)
|
||||
const getContactConfigSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get-success"
|
||||
)
|
||||
const getContactConfigFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.contactConfig.get-fail"
|
||||
)
|
||||
// OpenTelemetry metrics: Header
|
||||
const getHeaderRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get"
|
||||
)
|
||||
const getHeaderRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get-success"
|
||||
)
|
||||
const getHeaderRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.ref.get-fail"
|
||||
)
|
||||
const getHeaderCounter = meter.createCounter("trpc.contentstack.header.get")
|
||||
const getHeaderSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.get-success"
|
||||
)
|
||||
const getHeaderFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.header.get-fail"
|
||||
)
|
||||
// OpenTelemetry metrics: Footer
|
||||
const getFooterRefCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get"
|
||||
)
|
||||
const getFooterRefSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get-success"
|
||||
)
|
||||
const getFooterRefFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.ref.get-fail"
|
||||
)
|
||||
const getFooterCounter = meter.createCounter("trpc.contentstack.footer.get")
|
||||
const getFooterSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.get-success"
|
||||
)
|
||||
const getFooterFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.footer.get-fail"
|
||||
)
|
||||
|
||||
export const baseQueryRouter = router({
|
||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
getContactConfigCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.config start",
|
||||
"contentstack.contactConfig start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const response = await request<ContactConfigData>(GetContactConfig, {
|
||||
@@ -39,10 +88,18 @@ export const baseQueryRouter = router({
|
||||
|
||||
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 } })
|
||||
)
|
||||
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
@@ -51,8 +108,13 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedContactConfigConfig.success) {
|
||||
getContactConfigFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedContactConfigConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.config validation error",
|
||||
"contentstack.contactConfig validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedContactConfigConfig.error,
|
||||
@@ -60,8 +122,9 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getContactConfigSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.config success",
|
||||
"contentstack.contactConfig success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||
@@ -69,6 +132,7 @@ export const baseQueryRouter = router({
|
||||
header: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
getHeaderRefCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.header.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
@@ -76,6 +140,7 @@ export const baseQueryRouter = router({
|
||||
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
getHeaderCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.header start",
|
||||
JSON.stringify({
|
||||
@@ -99,6 +164,11 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getHeaderFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header not found error",
|
||||
JSON.stringify({
|
||||
@@ -116,6 +186,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedHeaderConfig.success) {
|
||||
getHeaderFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHeaderConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.header validation error",
|
||||
JSON.stringify({
|
||||
@@ -127,6 +202,7 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getHeaderSuccessCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.header success",
|
||||
JSON.stringify({
|
||||
@@ -145,6 +221,7 @@ export const baseQueryRouter = router({
|
||||
footer: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
getFooterRefCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
@@ -153,6 +230,7 @@ export const baseQueryRouter = router({
|
||||
locale: input.lang,
|
||||
})
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
getFooterCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer start",
|
||||
JSON.stringify({
|
||||
@@ -178,6 +256,11 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getFooterFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer not found error",
|
||||
JSON.stringify({
|
||||
@@ -195,6 +278,11 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedFooterConfig.success) {
|
||||
getFooterFailCounter.add(1, {
|
||||
lang: input.lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedFooterConfig.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.footer validation error",
|
||||
JSON.stringify({
|
||||
@@ -204,6 +292,7 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getFooterSuccessCounter.add(1, { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer success",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
@@ -5,9 +7,22 @@ import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
||||
|
||||
// OpenTelemetry metrics
|
||||
const meter = metrics.getMeter("trpc.contentstack.hotelPage")
|
||||
const getHotelPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get"
|
||||
)
|
||||
const getHotelPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-success"
|
||||
)
|
||||
const getHotelPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-fail"
|
||||
)
|
||||
|
||||
export const hotelPageQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
getHotelPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.hotelPage start",
|
||||
JSON.stringify({
|
||||
@@ -20,6 +35,12 @@ 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({
|
||||
@@ -33,6 +54,12 @@ export const hotelPageQueryRouter = router({
|
||||
const validatedHotelPage = validateHotelPageSchema.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({
|
||||
@@ -46,6 +73,7 @@ export const hotelPageQueryRouter = router({
|
||||
const hotelPage = {
|
||||
...validatedHotelPage.data.hotel_page,
|
||||
} as HotelPage
|
||||
getHotelPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.hotelPage success",
|
||||
JSON.stringify({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { baseUrls } from "@/constants/routes/baseUrls"
|
||||
import { batchRequest } from "@/lib/graphql/batchRequest"
|
||||
@@ -40,6 +42,17 @@ interface LanguageSwitcherVariables {
|
||||
uid: string
|
||||
}
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.languageSwitcher")
|
||||
const getLanguageSwitcherCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get"
|
||||
)
|
||||
const getLanguageSwitcherSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get-success"
|
||||
)
|
||||
const getLanguageSwitcherFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.languageSwitcher.get-fail"
|
||||
)
|
||||
|
||||
async function getLanguageSwitcher(options: LanguageSwitcherVariables) {
|
||||
const variables = { uid: options.uid }
|
||||
const tagsDaDeEn = [
|
||||
@@ -131,6 +144,11 @@ export const languageSwitcherQueryRouter = router({
|
||||
if (!ctx.uid || !ctx.lang) {
|
||||
return { lang: ctx.lang, urls: baseUrls }
|
||||
}
|
||||
getLanguageSwitcherCounter.add(1, {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.languageSwitcher start",
|
||||
JSON.stringify({
|
||||
@@ -164,6 +182,13 @@ export const languageSwitcherQueryRouter = router({
|
||||
validateLanguageSwitcherData.safeParse(urls)
|
||||
|
||||
if (!validatedLanguageSwitcherData.success) {
|
||||
getLanguageSwitcherFailCounter.add(1, {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLanguageSwitcherData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.languageSwitcher validation error",
|
||||
JSON.stringify({
|
||||
@@ -177,6 +202,11 @@ export const languageSwitcherQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getLanguageSwitcherSuccessCounter.add(1, {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.languageSwitcher success",
|
||||
JSON.stringify({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
@@ -33,9 +35,31 @@ import {
|
||||
TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
|
||||
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
|
||||
getLoyaltyPageRefsCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs start",
|
||||
JSON.stringify({
|
||||
@@ -55,6 +79,14 @@ export const loyaltyPageQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getLoyaltyPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
code: notFoundError.code,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs not found error",
|
||||
JSON.stringify({
|
||||
@@ -73,6 +105,12 @@ export const loyaltyPageQueryRouter = router({
|
||||
const validatedLoyaltyPageRefs =
|
||||
validateLoyaltyPageRefsSchema.safeParse(cleanedData)
|
||||
if (!validatedLoyaltyPageRefs.success) {
|
||||
getLoyaltyPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLoyaltyPageRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs validation error",
|
||||
JSON.stringify({
|
||||
@@ -82,6 +120,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getLoyaltyPageRefsSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs success",
|
||||
JSON.stringify({
|
||||
@@ -94,6 +133,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||
].flat()
|
||||
getLoyaltyPageCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage start",
|
||||
JSON.stringify({
|
||||
@@ -111,7 +151,12 @@ export const loyaltyPageQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
|
||||
getLoyaltyPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage not found error",
|
||||
JSON.stringify({
|
||||
@@ -227,6 +272,12 @@ export const loyaltyPageQueryRouter = router({
|
||||
const validatedLoyaltyPage =
|
||||
validateLoyaltyPageSchema.safeParse(loyaltyPage)
|
||||
if (!validatedLoyaltyPage.success) {
|
||||
getLoyaltyPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedLoyaltyPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage validation error",
|
||||
JSON.stringify({
|
||||
@@ -245,6 +296,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
pageType: "loyaltycontentpage",
|
||||
}
|
||||
getLoyaltyPageSuccessCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import {
|
||||
GetNavigationMyPages,
|
||||
GetNavigationMyPagesRefs,
|
||||
@@ -25,6 +27,26 @@ import { getConnections } from "./utils"
|
||||
|
||||
import { PageLinkEnum } from "@/types/requests/pageLinks"
|
||||
|
||||
const meter = metrics.getMeter("trpc.navigationMyPages")
|
||||
const getNavigationMyPagesRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.refs.get"
|
||||
)
|
||||
const getNavigationMyPagesRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.refs.get-success"
|
||||
)
|
||||
const getNavigationMyPagesRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.refs.get-fail"
|
||||
)
|
||||
const getNavigationMyPagesCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.get"
|
||||
)
|
||||
const getNavigationMyPagesSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.get-success"
|
||||
)
|
||||
const getNavigationMyPagesFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.navigationMyPages.get-fail"
|
||||
)
|
||||
|
||||
export function mapMenuItems(menuItems: MenuItems) {
|
||||
return menuItems.map((menuItem) => {
|
||||
return {
|
||||
@@ -61,6 +83,7 @@ export function mapMenuItems(menuItems: MenuItems) {
|
||||
export const navigationQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
||||
const { lang } = ctx
|
||||
getNavigationMyPagesRefsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
@@ -75,6 +98,11 @@ export const navigationQueryRouter = router({
|
||||
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getNavigationMyPagesRefsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs not found error",
|
||||
JSON.stringify({
|
||||
@@ -90,6 +118,11 @@ export const navigationQueryRouter = router({
|
||||
const validatedMyPagesNavigationRefs =
|
||||
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
||||
if (!validatedMyPagesNavigationRefs.success) {
|
||||
getNavigationMyPagesRefsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedMyPagesNavigationRefs.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs validation error",
|
||||
JSON.stringify({
|
||||
@@ -101,6 +134,7 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
return null
|
||||
}
|
||||
getNavigationMyPagesRefsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
@@ -115,6 +149,7 @@ export const navigationQueryRouter = router({
|
||||
.system.uid
|
||||
),
|
||||
].flat()
|
||||
getNavigationMyPagesCounter.add(1)
|
||||
console.info(
|
||||
"contentstack.myPages.navigation start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
@@ -127,6 +162,11 @@ export const navigationQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getNavigationMyPagesFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error("contentstack.myPages.navigation not found error", {
|
||||
query: {
|
||||
lang,
|
||||
@@ -140,6 +180,11 @@ export const navigationQueryRouter = router({
|
||||
response.data
|
||||
)
|
||||
if (!validatedMyPagesNavigation.success) {
|
||||
getNavigationMyPagesFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedMyPagesNavigation.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.payload validation error",
|
||||
JSON.stringify({
|
||||
@@ -160,6 +205,11 @@ export const navigationQueryRouter = router({
|
||||
|
||||
const validatedNav = getNavigationSchema.safeParse(nav)
|
||||
if (!validatedNav.success) {
|
||||
getNavigationMyPagesFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedNav.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation validation error",
|
||||
JSON.stringify({
|
||||
@@ -171,6 +221,7 @@ export const navigationQueryRouter = router({
|
||||
console.error(validatedNav.error)
|
||||
return null
|
||||
}
|
||||
getNavigationMyPagesSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
|
||||
Reference in New Issue
Block a user