Merged in chore/redirect-counter (pull request #3302)

Counter name is now searchable and add counter for redirects

* refactor: createCounter() only takes one argument, the name of the counter. Makes it easier to search for

* feat: add counter when we do a redirect from redirect-service


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-12-08 10:24:05 +00:00
parent edca33c49f
commit 8b94540d19
61 changed files with 146 additions and 236 deletions

View File

@@ -63,9 +63,8 @@ export function sanitize(data: any): Record<string, string | number | boolean> {
*
* See the codebase for reference usage.
*/
export function createCounter(meterName: string, counterName: string) {
const fullName = `${meterName}.${counterName}`
export function createCounter(meterName: string) {
return {
/**
* Initializes the counter event handlers with a set of base attributes.
@@ -82,7 +81,7 @@ export function createCounter(meterName: string, counterName: string) {
* @param attrs - Additional attributes specific to this 'start' event. Defaults to an empty object.
*/
start(attrs: object | undefined = undefined) {
logger.debug(`[${fullName}] start`, attrs)
logger.debug(`[${meterName}] start`, attrs)
},
/**
@@ -93,10 +92,10 @@ export function createCounter(meterName: string, counterName: string) {
success(attrs: object = {}) {
const mergedAttrs = deepmerge.all<object>([baseAttrs, attrs])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "success" },
})
logger.debug(`[${fullName}] success`, mergedAttrs)
logger.debug(`[${meterName}] success`, mergedAttrs)
},
/**
@@ -119,10 +118,10 @@ export function createCounter(meterName: string, counterName: string) {
])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "error" },
})
logger.error(`[${fullName}] dataError: ${errorMsg}`, mergedAttrs)
logger.error(`[${meterName}] dataError: ${errorMsg}`, mergedAttrs)
},
/**
@@ -143,10 +142,10 @@ export function createCounter(meterName: string, counterName: string) {
])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "error" },
})
logger.error(`[${fullName}] noDataError:`, mergedAttrs)
logger.error(`[${meterName}] noDataError:`, mergedAttrs)
},
/**
@@ -165,10 +164,10 @@ export function createCounter(meterName: string, counterName: string) {
])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "error" },
})
logger.error(`[${fullName}] validationError`, mergedAttrs)
logger.error(`[${meterName}] validationError`, mergedAttrs)
},
/**
@@ -196,11 +195,11 @@ export function createCounter(meterName: string, counterName: string) {
])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "error" },
})
logger.error(
`[${fullName}] httpError ${res.status}, ${res.statusText}:`,
`[${meterName}] httpError ${res.status}, ${res.statusText}:`,
mergedAttrs
)
},
@@ -231,10 +230,10 @@ export function createCounter(meterName: string, counterName: string) {
])
const finalAttrs = sanitize(mergedAttrs)
Sentry.metrics.count(fullName, 1, {
Sentry.metrics.count(meterName, 1, {
attributes: { ...finalAttrs, status: "error" },
})
logger.error(`[${fullName}] fail message: ${msg}`, mergedAttrs)
logger.error(`[${meterName}] fail message: ${msg}`, mergedAttrs)
},
}
},

View File

@@ -57,8 +57,7 @@ async function getJwt(scopes: string[]) {
async function fetchServiceToken(scopes: string[]) {
const fetchServiceTokenCounter = createCounter(
"tokenManager",
"fetchServiceToken"
"tokenManager.fetchServiceToken"
)
const metricsFetchServiceToken = fetchServiceTokenCounter.init({
scopes,