feat: add metrics
This commit is contained in:
@@ -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