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 } })
|
||||
|
||||
Reference in New Issue
Block a user