From db009a169f64d41c5dc94de3f6b86b32985ae823 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 28 Jul 2024 14:13:51 +0200 Subject: [PATCH 1/4] feat: added loki transport for pino --- api/package.json | 1 + api/pnpm-lock.yaml | 152 +++++++++++++++++++++++++++++++++++++++++++-- api/src/logger.ts | 43 ++++++++++--- 3 files changed, 182 insertions(+), 14 deletions(-) diff --git a/api/package.json b/api/package.json index c6546993..a4893457 100644 --- a/api/package.json +++ b/api/package.json @@ -48,6 +48,7 @@ "nexus-validation-plugin": "^0.2.0", "pino": "^8.20.0", "pino-http": "^8.6.1", + "pino-loki": "^2.3.0", "pino-pretty": "^10.3.1", "pino-sentry-transport": "^1.1.0", "prisma": "^5.14.0", diff --git a/api/pnpm-lock.yaml b/api/pnpm-lock.yaml index b30f9018..bcf92827 100644 --- a/api/pnpm-lock.yaml +++ b/api/pnpm-lock.yaml @@ -92,6 +92,9 @@ dependencies: pino-http: specifier: ^8.6.1 version: 8.6.1 + pino-loki: + specifier: ^2.3.0 + version: 2.3.0 pino-pretty: specifier: ^10.3.1 version: 10.3.1 @@ -4067,7 +4070,6 @@ packages: /@sindresorhus/is@4.6.0: resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==} engines: {node: '>=10'} - dev: true /@sindresorhus/merge-streams@2.3.0: resolution: {integrity: sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==} @@ -4208,6 +4210,13 @@ packages: tslib: 2.6.3 dev: false + /@szmarczak/http-timer@4.0.6: + resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==} + engines: {node: '>=10'} + dependencies: + defer-to-connect: 2.0.1 + dev: false + /@testing-library/dom@9.3.4: resolution: {integrity: sha512-FlS4ZWlp97iiNWig0Muq8p+3rVDjRiYE+YKGbAqXOu9nwJFFOdL00kFpz42M+4huzYi86vAK1sOOfyOG45muIQ==} engines: {node: '>=14'} @@ -4286,6 +4295,15 @@ packages: '@types/connect': 3.4.38 '@types/node': 20.14.9 + /@types/cacheable-request@6.0.3: + resolution: {integrity: sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==} + dependencies: + '@types/http-cache-semantics': 4.0.4 + '@types/keyv': 3.1.4 + '@types/node': 20.14.9 + '@types/responselike': 1.0.3 + dev: false + /@types/chai-subset@1.3.5: resolution: {integrity: sha512-c2mPnw+xHtXDoHmdtcCXGwyLMiauiAyxWMzhGpqHC4nqI/Y5G2XhTampslK2rb59kpcuHon03UH8W6iYUzw88A==} dependencies: @@ -4339,6 +4357,10 @@ packages: '@types/qs': 6.9.15 '@types/serve-static': 1.15.7 + /@types/http-cache-semantics@4.0.4: + resolution: {integrity: sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==} + dev: false + /@types/http-errors@2.0.4: resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==} @@ -4356,6 +4378,12 @@ packages: '@types/node': 20.14.9 dev: true + /@types/keyv@3.1.4: + resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} + dependencies: + '@types/node': 20.14.9 + dev: false + /@types/long@4.0.2: resolution: {integrity: sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==} dev: false @@ -4388,6 +4416,12 @@ packages: /@types/range-parser@1.2.7: resolution: {integrity: sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==} + /@types/responselike@1.0.3: + resolution: {integrity: sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==} + dependencies: + '@types/node': 20.14.9 + dev: false + /@types/semver@7.5.8: resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} dev: true @@ -5152,6 +5186,24 @@ packages: dev: false optional: true + /cacheable-lookup@5.0.4: + resolution: {integrity: sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==} + engines: {node: '>=10.6.0'} + dev: false + + /cacheable-request@7.0.4: + resolution: {integrity: sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg==} + engines: {node: '>=8'} + dependencies: + clone-response: 1.0.3 + get-stream: 5.2.0 + http-cache-semantics: 4.1.1 + keyv: 4.5.4 + lowercase-keys: 2.0.0 + normalize-url: 6.1.0 + responselike: 2.0.1 + dev: false + /call-bind@1.0.7: resolution: {integrity: sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==} engines: {node: '>= 0.4'} @@ -5355,6 +5407,12 @@ packages: wrap-ansi: 7.0.0 dev: true + /clone-response@1.0.3: + resolution: {integrity: sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==} + dependencies: + mimic-response: 1.0.1 + dev: false + /clsx@2.1.1: resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==} engines: {node: '>=6'} @@ -5397,6 +5455,11 @@ packages: dependencies: delayed-stream: 1.0.0 + /commander@12.1.0: + resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} + engines: {node: '>=18'} + dev: false + /commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} dev: false @@ -5692,7 +5755,6 @@ packages: dependencies: mimic-response: 3.1.0 dev: false - optional: true /deep-eql@4.1.4: resolution: {integrity: sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==} @@ -5737,6 +5799,11 @@ packages: resolution: {integrity: sha512-Rn+RuwkmkDwCi2/oXOFS9Gsr5lJZu/yTGpK7wAaAIE75CC+LCGEZHpY6VQJa/RoJcrmaA/docWJZvYohlNkWPA==} dev: false + /defer-to-connect@2.0.1: + resolution: {integrity: sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==} + engines: {node: '>=10'} + dev: false + /define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -6908,6 +6975,13 @@ packages: has-symbols: 1.0.3 hasown: 2.0.2 + /get-stream@5.2.0: + resolution: {integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==} + engines: {node: '>=8'} + dependencies: + pump: 3.0.0 + dev: false + /get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} @@ -7030,6 +7104,23 @@ packages: dependencies: get-intrinsic: 1.2.4 + /got@11.8.6: + resolution: {integrity: sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==} + engines: {node: '>=10.19.0'} + dependencies: + '@sindresorhus/is': 4.6.0 + '@szmarczak/http-timer': 4.0.6 + '@types/cacheable-request': 6.0.3 + '@types/responselike': 1.0.3 + cacheable-lookup: 5.0.4 + cacheable-request: 7.0.4 + decompress-response: 6.0.0 + http2-wrapper: 1.0.3 + lowercase-keys: 2.0.0 + p-cancelable: 2.1.1 + responselike: 2.0.1 + dev: false + /gql-query-builder@3.8.0: resolution: {integrity: sha512-q0PncZTrLDeyiH4R7YH1ISM+XGB4NvQ8eTm/Wr/sHSuquFZvqvDpGyMhbgoCZDc8kNAK8GOdfh3nI2GCLREFvw==} dev: true @@ -7247,7 +7338,6 @@ packages: resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==} requiresBuild: true dev: false - optional: true /http-errors@2.0.0: resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} @@ -7287,6 +7377,14 @@ packages: - supports-color dev: true + /http2-wrapper@1.0.3: + resolution: {integrity: sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==} + engines: {node: '>=10.19.0'} + dependencies: + quick-lru: 5.1.1 + resolve-alpn: 1.2.1 + dev: false + /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -7842,7 +7940,6 @@ packages: /json-buffer@3.0.1: resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==} - dev: true /json-parse-better-errors@1.0.2: resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==} @@ -7932,7 +8029,6 @@ packages: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: json-buffer: 3.0.1 - dev: true /levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} @@ -8115,6 +8211,11 @@ packages: tslib: 2.6.3 dev: false + /lowercase-keys@2.0.0: + resolution: {integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==} + engines: {node: '>=8'} + dev: false + /lru-cache@10.2.2: resolution: {integrity: sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==} engines: {node: 14 || >=16.14} @@ -8306,12 +8407,16 @@ packages: engines: {node: '>=12'} dev: true + /mimic-response@1.0.1: + resolution: {integrity: sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==} + engines: {node: '>=4'} + dev: false + /mimic-response@3.1.0: resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==} engines: {node: '>=10'} requiresBuild: true dev: false - optional: true /min-indent@1.0.1: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} @@ -8632,6 +8737,11 @@ packages: validate-npm-package-license: 3.0.4 dev: true + /normalize-url@6.1.0: + resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==} + engines: {node: '>=10'} + dev: false + /normalize-url@8.0.1: resolution: {integrity: sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==} engines: {node: '>=14.16'} @@ -8857,6 +8967,11 @@ packages: word-wrap: 1.2.5 dev: true + /p-cancelable@2.1.1: + resolution: {integrity: sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==} + engines: {node: '>=8'} + dev: false + /p-each-series@3.0.0: resolution: {integrity: sha512-lastgtAdoH9YaLyDa5i5z64q+kzOcQHsQ5SsZJD3q0VEyI8mq872S3geuNbRUQLVAE9siMfgKrpj7MloKFHruw==} engines: {node: '>=12'} @@ -9141,6 +9256,16 @@ packages: process-warning: 3.0.0 dev: false + /pino-loki@2.3.0: + resolution: {integrity: sha512-fJeZwNPMNWTf09qz/xbCvk86MAMr9E/NkbDi8GHU3lWeVkf5+jh1Wyf/Y5R8ffD61UGk0WOHhpD7ceN4xOYMmA==} + hasBin: true + dependencies: + commander: 12.1.0 + got: 11.8.6 + pino-abstract-transport: 1.2.0 + pump: 3.0.0 + dev: false + /pino-pretty@10.3.1: resolution: {integrity: sha512-az8JbIYeN/1iLj2t0jR9DV48/LQ3RC6hZPpapKPkb84Q+yTidMCpgWxIT3N0flnBDilyBQ1luWNpOeJptjdp/g==} hasBin: true @@ -9375,6 +9500,11 @@ packages: resolution: {integrity: sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==} dev: false + /quick-lru@5.1.1: + resolution: {integrity: sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==} + engines: {node: '>=10'} + dev: false + /ramda@0.29.0: resolution: {integrity: sha512-BBea6L67bYLtdbOqfp8f58fPMqEwx0doL+pAi8TZyp2YWz8R9G8z9x75CZI8W+ftqhFHCpEX2cRnUUXK130iKA==} dev: false @@ -9667,6 +9797,10 @@ packages: resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} dev: false + /resolve-alpn@1.2.1: + resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==} + dev: false + /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} @@ -9686,6 +9820,12 @@ packages: supports-preserve-symlinks-flag: 1.0.0 dev: true + /responselike@2.0.1: + resolution: {integrity: sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==} + dependencies: + lowercase-keys: 2.0.0 + dev: false + /retimer@3.0.0: resolution: {integrity: sha512-WKE0j11Pa0ZJI5YIk0nflGI7SQsfl2ljihVy7ogh7DeQSeYAUi0ubZ/yEueGtDfUPk6GH5LRw1hBdLq4IwUBWA==} dev: true diff --git a/api/src/logger.ts b/api/src/logger.ts index d9736435..eb1d5568 100644 --- a/api/src/logger.ts +++ b/api/src/logger.ts @@ -3,9 +3,10 @@ import pino from 'pino'; import pinoHttp from 'pino-http'; import * as Sentry from '@sentry/node'; import { loggerConfig } from '../logger.config'; -import { isDevelopment } from './env'; -const { moduleFilter, prefixFilter, logLevel, httpLogLevel } = loggerConfig; +const { + moduleFilter, prefixFilter, logLevel, httpLogLevel, +} = loggerConfig; export const dirname = (() => { if (typeof __dirname !== 'undefined') { @@ -60,11 +61,11 @@ const doesPassFilters = (config: { const transportTargets: pino.TransportTargetOptions[] = []; -if (isDevelopment) { - transportTargets.push({ - target: 'pino-pretty', - }); -} + + +transportTargets.push({ + target: 'pino-pretty', +}); if (process.env.SENTRY_DSN) { transportTargets.push({ @@ -89,6 +90,32 @@ if (process.env.SENTRY_DSN) { }, }); } + +const { LOKI_URL, LOKI_USERNAME, LOKI_PASSWORD } = process.env; +if (LOKI_URL && LOKI_USERNAME && LOKI_PASSWORD) { + const basePath = process.env.BASE_PATH || '/'; + const baseElements = basePath.split('/'); + + const labels = { team: 'powerhouse', application: 'switchboard', env: 'develop' }; + labels.env = baseElements[1] ?? 'develop'; + labels.team = baseElements[2] ?? 'powerhouse'; + labels.application = baseElements[3] ?? 'switchboard'; + + transportTargets.push({ + target: 'pino-loki', + options: { + batching: true, + interval: 5, + labels, + host: LOKI_URL, + basicAuth: { + username: LOKI_USERNAME, + password: LOKI_PASSWORD, + }, + }, + }); +} + export const expressLogger = pinoHttp({ level: httpLogLevel, msgPrefix: formatPrefix('express'), @@ -106,7 +133,7 @@ const logger = pino({ export const getChildLogger = ( options?: pino.ChildLoggerOptions, - bindings?: pino.Bindings + bindings?: pino.Bindings, ) => { // get caller module of this function const caller = Error().stack?.split('at ').at(2)?.trim().split(':')[0] || ''; From dd0541959f83b48eb00b2ef4a34f47b0a64fd7ca Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 29 Jul 2024 15:35:17 +0200 Subject: [PATCH 2/4] chore: introduced loki_env --- api/src/logger.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/src/logger.ts b/api/src/logger.ts index eb1d5568..116644a8 100644 --- a/api/src/logger.ts +++ b/api/src/logger.ts @@ -61,11 +61,11 @@ const doesPassFilters = (config: { const transportTargets: pino.TransportTargetOptions[] = []; - - -transportTargets.push({ - target: 'pino-pretty', -}); +if (process.env.NOD_ENV !== 'production') { + transportTargets.push({ + target: 'pino-pretty', + }); +} if (process.env.SENTRY_DSN) { transportTargets.push({ @@ -91,12 +91,16 @@ if (process.env.SENTRY_DSN) { }); } -const { LOKI_URL, LOKI_USERNAME, LOKI_PASSWORD } = process.env; +const { LOKI_URL, LOKI_USERNAME, LOKI_PASSWORD, LOKI_ENV } = process.env; if (LOKI_URL && LOKI_USERNAME && LOKI_PASSWORD) { const basePath = process.env.BASE_PATH || '/'; const baseElements = basePath.split('/'); - const labels = { team: 'powerhouse', application: 'switchboard', env: 'develop' }; + const labels = { + team: 'powerhouse', + application: 'switchboard', + env: LOKI_ENV ?? 'develop', + }; labels.env = baseElements[1] ?? 'develop'; labels.team = baseElements[2] ?? 'powerhouse'; labels.application = baseElements[3] ?? 'switchboard'; From 14a27741c8420889c10608c943e2d34bab89ce2c Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 29 Jul 2024 15:36:05 +0200 Subject: [PATCH 3/4] chore: pino pretty only on dev --- api/src/logger.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/logger.ts b/api/src/logger.ts index 116644a8..05775b43 100644 --- a/api/src/logger.ts +++ b/api/src/logger.ts @@ -3,6 +3,7 @@ import pino from 'pino'; import pinoHttp from 'pino-http'; import * as Sentry from '@sentry/node'; import { loggerConfig } from '../logger.config'; +import { isDevelopment } from './env'; const { moduleFilter, prefixFilter, logLevel, httpLogLevel, @@ -61,7 +62,7 @@ const doesPassFilters = (config: { const transportTargets: pino.TransportTargetOptions[] = []; -if (process.env.NOD_ENV !== 'production') { +if (isDevelopment) { transportTargets.push({ target: 'pino-pretty', }); From a0a79ad8f7f7127dd0a0337435959fd2b3309b52 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 29 Jul 2024 15:38:52 +0200 Subject: [PATCH 4/4] fix: labels --- api/src/logger.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/api/src/logger.ts b/api/src/logger.ts index 05775b43..ab1c9dd9 100644 --- a/api/src/logger.ts +++ b/api/src/logger.ts @@ -98,13 +98,10 @@ if (LOKI_URL && LOKI_USERNAME && LOKI_PASSWORD) { const baseElements = basePath.split('/'); const labels = { - team: 'powerhouse', - application: 'switchboard', - env: LOKI_ENV ?? 'develop', + team: baseElements[2] ?? 'powerhouse', + application: baseElements[3] ?? 'switchboard', + env: LOKI_ENV ?? baseElements[1] ?? 'develop', }; - labels.env = baseElements[1] ?? 'develop'; - labels.team = baseElements[2] ?? 'powerhouse'; - labels.application = baseElements[3] ?? 'switchboard'; transportTargets.push({ target: 'pino-loki',