feat: harmonize log and metrics
This commit is contained in:
@@ -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"
|
||||
)
|
||||
Reference in New Issue
Block a user