@mereb/shared-packages 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AA+BxB,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CAkDtD"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAsCxB,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CA4DtD"}
package/dist/logger.js CHANGED
@@ -6,10 +6,20 @@ function resolveSplunkConfig(name) {
6
6
  if (!token)
7
7
  return null;
8
8
  const env = process.env.NODE_ENV ?? 'development';
9
- const defaultIndex = process.env.SPLUNK_HEC_INDEX ??
10
- (env === 'production' ? 'logs-prd' : env === 'staging' ? 'logs-stg' : 'logs-dev');
9
+ let defaultIndex = process.env.SPLUNK_HEC_INDEX;
10
+ if (!defaultIndex) {
11
+ if (env === 'production') {
12
+ defaultIndex = 'logs-prd';
13
+ }
14
+ else if (env === 'staging') {
15
+ defaultIndex = 'logs-stg';
16
+ }
17
+ else {
18
+ defaultIndex = 'logs-dev';
19
+ }
20
+ }
11
21
  const url = process.env.SPLUNK_HEC_URL ??
12
- 'http://splunk-prd.platform-prd.svc.cluster.local:8088/services/collector/event';
22
+ 'https://splunk-hec.mereb.app/services/collector/event';
13
23
  return {
14
24
  url,
15
25
  token,
@@ -22,6 +32,9 @@ export function createLogger(name) {
22
32
  const splunkConfig = resolveSplunkConfig(name);
23
33
  const baseLevel = process.env.LOG_LEVEL ?? 'info';
24
34
  const isProd = process.env.NODE_ENV === 'production';
35
+ if (!splunkConfig && process.env.SPLUNK_HEC_URL) {
36
+ console.warn('Splunk token missing; HEC logging disabled');
37
+ }
25
38
  if (isProd) {
26
39
  transports.push({ stream: process.stdout });
27
40
  }
@@ -34,6 +47,11 @@ export function createLogger(name) {
34
47
  }
35
48
  if (splunkConfig) {
36
49
  const transportPath = join(dirname(fileURLToPath(import.meta.url)), 'transports', 'splunk-transport.js');
50
+ console.info('Splunk logging enabled', {
51
+ url: splunkConfig.url,
52
+ index: splunkConfig.index,
53
+ source: splunkConfig.source
54
+ });
37
55
  const splunkStream = pino.transport({
38
56
  target: transportPath,
39
57
  level: 'info',
@@ -1 +1 @@
1
- {"version":3,"file":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAE5C,KAAK,sBAAsB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAA8B,eAAe,CAAE,IAAI,EAAE,sBAAsB,yDAyC1E"}
1
+ {"version":3,"file":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAE5C,KAAK,sBAAsB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAA8B,eAAe,CAAE,IAAI,EAAE,sBAAsB,yDAsD1E"}
@@ -19,7 +19,7 @@ export default async function splunkTransport(opts) {
19
19
  continue;
20
20
  }
21
21
  const controller = AbortSignal.timeout(timeoutMs);
22
- fetch(url, {
22
+ const response = await fetch(url, {
23
23
  method: 'POST',
24
24
  headers: {
25
25
  Authorization: `Splunk ${token}`,
@@ -35,6 +35,17 @@ export default async function splunkTransport(opts) {
35
35
  }).catch((err) => {
36
36
  console.error('Failed to send log to Splunk HEC', err);
37
37
  });
38
+ if (response == null) {
39
+ continue;
40
+ }
41
+ if (!response.ok) {
42
+ const body = await response.text().catch(() => '');
43
+ console.error('Splunk HEC responded with error', {
44
+ status: response.status,
45
+ statusText: response.statusText,
46
+ body
47
+ });
48
+ }
38
49
  }
39
50
  });
40
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mereb/shared-packages",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",