h1v3 0.6.0 → 0.6.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h1v3",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "",
@@ -19,8 +19,8 @@ export function configureConfigStore(paths, _onValueWritten, _logger) {
19
19
 
20
20
  function decideSeverity(newData) {
21
21
 
22
- if (!newData.severity_text) return "INFO";
23
- return newData.severity_text.toUpperCase();
22
+ const text = newData.severity_text?.toLowerCase();
23
+ return ["trace", "fatal", "info", "debug", "error", "warn"].includes(text) ? text : "info";
24
24
 
25
25
  }
26
26
 
@@ -50,21 +50,42 @@ function handleLogValueWritten(logger, e) {
50
50
  },
51
51
  timestamp
52
52
  };
53
- console.log("Writing log", payload);
54
- logger.write(payload);
53
+ console.log({
54
+
55
+ "logging.googleapis.com/trace": `projects/${process.env.GCLOUD_PROJECT}/traces/${newData.trace_id}`,
56
+ "logging.googleapis.com/spanId": newData.span_id,
57
+ "severity": decideSeverity(newData),
58
+ "jsonPayload": {
59
+ ...newData,
60
+ time_server_ms,
61
+ timestamp
62
+ }
63
+
64
+ });
55
65
  after.ref.update({ time_server_ms });
66
+ // logger.write(payload);
56
67
 
57
68
  }
58
69
 
59
70
  }
60
71
 
61
- export function configureLoggingStore(paths, onValueWritten, logger) {
72
+ export function configureLoggingStore({ paths, onValueWritten, logger, region, instance }) {
73
+
74
+ if (!paths) throw new Error("Missing paths");
75
+ if (!onValueWritten) throw new Error("Missing onValueWritten");
76
+ if (!logger) throw new Error("Missing logger");
77
+ if (!region) throw new Error("Missing region");
78
+ if (!instance) throw new Error("Missing instance");
62
79
 
63
80
  const ref = paths?.logs?.path;
64
81
  if (!ref) throw new Error("Missing: paths.logs.path");
65
82
  const triggerPath = refPathToTriggerPath(ref);
66
83
  return Object.assign(
67
- onValueWritten(triggerPath, handleLogValueWritten.bind(this, logger)),
84
+ onValueWritten({
85
+ ref: triggerPath,
86
+ region,
87
+ instance
88
+ }, handleLogValueWritten.bind(this, logger)),
68
89
  {
69
90
  [RAW_STORE_META]: {
70
91
  raw: true,
@@ -4,7 +4,12 @@ import { refPathToTriggerPath } from "../paths.js";
4
4
 
5
5
  export const EVENT_STORE_META = Symbol("Event store configuration metadata");
6
6
 
7
- export function configureEventStore({ ref, projections, ...rest }, onValueWritten, logger) {
7
+ export function configureEventStore({ ref, projections, ...rest }, { onValueWritten, logger, region, instance }) {
8
+
9
+ if (!onValueWritten) throw new Error("Missing onValueWritten");
10
+ if (!logger) throw new Error("Missing logger");
11
+ if (!region) throw new Error("Missing region");
12
+ if (!instance) throw new Error("Missing instance");
8
13
 
9
14
  // considered the "home" of the event store, under which events and projections will be stored
10
15
  const eventStorePath = refPathToTriggerPath(ref);
@@ -24,16 +29,16 @@ export function configureEventStore({ ref, projections, ...rest }, onValueWritte
24
29
 
25
30
  // tag the trigger with metadata
26
31
  return Object.assign(
27
- onValueWritten(writeRefPath, handler),
32
+ onValueWritten({ ref: writeRefPath, region, instance }, handler),
28
33
  { [EVENT_STORE_META]: metadata }
29
34
  );
30
35
 
31
36
  }
32
37
 
33
- configureEventStore.inject = ({ onValueWritten, logger, paths }) =>
38
+ configureEventStore.inject = ({ onValueWritten, logger, paths, region, instance }) =>
34
39
 
35
40
  (eventStoreFactory, ...args) =>
36
41
 
37
- configureEventStore(eventStoreFactory(paths, ...args), onValueWritten, logger);
42
+ configureEventStore(eventStoreFactory(paths, ...args), { onValueWritten, logger, region, instance });
38
43
 
39
44