Repository navigation
Expand file tree
/
Copy pathinstrumentation.node.js
More file actions
150 lines (147 loc) · 8.69 KB
/
Copy pathinstrumentation.node.js
File metadata and controls
150 lines (147 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
export async function registerMqttNodeInstrumentation({
logger = console,
loadStartup = () => import("./lib/mqtt/startup.mjs"),
} = {}) {
if (typeof loadStartup !== "function") {
throw new Error("MQTT startup loader must be a function");
}
const startup = await loadStartup();
if (typeof startup?.startMqttRuntimeWithRetry !== "function") {
throw new Error("MQTT startup module did not expose startMqttRuntimeWithRetry()");
}
return startup.startMqttRuntimeWithRetry({ logger });
}
export async function registerNodeInstrumentation({
logger = console,
startMqtt = (options) => registerMqttNodeInstrumentation(options),
loadCameraInputStartup = () => import("./lib/camera-inputs/startup.mjs"),
loadVehicleFrameStartup = () => import("./lib/blue-iris-vehicle-frame-startup.mjs"),
loadNotificationStartup = () => import("./lib/notification-operations-startup.mjs"),
loadMaintenanceStartup = () => import("./lib/maintenance-startup.mjs"),
loadStorageMonitorStartup = () => import("./lib/storage-maintenance-monitor-startup.mjs"),
loadVehicleAssetCatalogStartup = () => import("./lib/vehicle-image-asset-catalog-startup.mjs"),
loadVehicleEventShadowStartup = () => import("./lib/vehicle-event-shadow-startup.mjs"),
loadVehicleImageCropStartup = () => import("./lib/vehicle-image-crop-startup.mjs"),
loadVehicleAssetEmbeddingStartup = () => import("./lib/vehicle-asset-embedding-startup.mjs"),
loadVehicleAssetAttributeStartup = () => import("./lib/vehicle-asset-attribute-startup.mjs"),
loadVehicleReidV2LiveStartup = () => import("./lib/vehicle-reid-v2-live-startup.mjs"),
} = {}) {
if (typeof startMqtt !== "function" || typeof loadVehicleFrameStartup !== "function" || typeof loadNotificationStartup !== "function" || typeof loadMaintenanceStartup !== "function" || typeof loadStorageMonitorStartup !== "function" || typeof loadVehicleAssetCatalogStartup !== "function" || typeof loadVehicleEventShadowStartup !== "function" || typeof loadVehicleImageCropStartup !== "function" || typeof loadVehicleAssetEmbeddingStartup !== "function" || typeof loadVehicleAssetAttributeStartup !== "function" || typeof loadVehicleReidV2LiveStartup !== "function") {
throw new Error("Node instrumentation loaders must be functions");
}
const [cameraInputResult, mqttResult, vehicleFrameResult, notificationResult, maintenanceResult, storageMonitorResult, vehicleAssetCatalogResult, vehicleEventShadowResult, vehicleImageCropResult, vehicleAssetEmbeddingResult, vehicleAssetAttributeResult, vehicleReidV2LiveResult] = await Promise.allSettled([
(async () => (await loadCameraInputStartup()).startCameraInputsWithRetry({ logger }))(),
startMqtt({ logger }),
(async () => {
const startup = await loadVehicleFrameStartup();
if (typeof startup?.startBlueIrisVehicleFrameRuntimeWithRetry !== "function") {
throw new Error("Blue Iris vehicle-frame startup module did not expose startBlueIrisVehicleFrameRuntimeWithRetry()");
}
return startup.startBlueIrisVehicleFrameRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadNotificationStartup();
if (typeof startup?.startNotificationOperationsRuntimeWithRetry !== "function") {
throw new Error("Notification operations startup module did not expose startNotificationOperationsRuntimeWithRetry()");
}
return startup.startNotificationOperationsRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadMaintenanceStartup();
if (typeof startup?.startMaintenanceRuntimeWithRetry !== "function") {
throw new Error("Maintenance startup module did not expose startMaintenanceRuntimeWithRetry()");
}
return startup.startMaintenanceRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadStorageMonitorStartup();
if (typeof startup?.startStorageMaintenanceMonitorWithRetry !== "function") {
throw new Error("Storage maintenance monitor startup module did not expose startStorageMaintenanceMonitorWithRetry()");
}
return startup.startStorageMaintenanceMonitorWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleAssetCatalogStartup();
if (typeof startup?.startVehicleImageAssetCatalogRuntimeWithRetry !== "function") {
throw new Error("Canonical Overview catalog startup module did not expose startVehicleImageAssetCatalogRuntimeWithRetry()");
}
return startup.startVehicleImageAssetCatalogRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleEventShadowStartup();
if (typeof startup?.startVehicleEventShadowRuntimeWithRetry !== "function") {
throw new Error("Shadow vehicle event startup module did not expose startVehicleEventShadowRuntimeWithRetry()");
}
return startup.startVehicleEventShadowRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleImageCropStartup();
if (typeof startup?.startVehicleImageCropRuntimeWithRetry !== "function") {
throw new Error("Canonical Overview vehicle crop startup module did not expose startVehicleImageCropRuntimeWithRetry()");
}
return startup.startVehicleImageCropRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleAssetEmbeddingStartup();
if (typeof startup?.startVehicleAssetEmbeddingRuntimeWithRetry !== "function") {
throw new Error("Canonical crop embedding startup module did not expose startVehicleAssetEmbeddingRuntimeWithRetry()");
}
return startup.startVehicleAssetEmbeddingRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleAssetAttributeStartup();
if (typeof startup?.startVehicleAssetAttributeRuntimeWithRetry !== "function") {
throw new Error("Canonical crop attribute startup module did not expose startVehicleAssetAttributeRuntimeWithRetry()");
}
return startup.startVehicleAssetAttributeRuntimeWithRetry({ logger });
})(),
(async () => {
const startup = await loadVehicleReidV2LiveStartup();
if (typeof startup?.startVehicleReidV2LiveRuntimeWithRetry !== "function") {
throw new Error("Authoritative ReID startup module did not expose startVehicleReidV2LiveRuntimeWithRetry()");
}
return startup.startVehicleReidV2LiveRuntimeWithRetry({ logger });
})(),
]);
const normalizeResult = (result, name) => {
if (result.status === "fulfilled") return result.value;
const error = {
name: String(result.reason?.name || "Error"),
code: String(result.reason?.code || ""),
message: String(result.reason?.message || result.reason || `${name} startup failed`)
.trim()
.slice(0, 1000),
};
logger?.error?.(`${name} instrumentation startup failed`, { error });
return { status: "error", error };
};
const cameraInputs = normalizeResult(cameraInputResult, "Camera inputs");
const mqtt = normalizeResult(mqttResult, "MQTT");
const vehicleFrames = normalizeResult(vehicleFrameResult, "Blue Iris vehicle frames");
const notificationOperations = normalizeResult(notificationResult, "Notification operations");
const maintenance = normalizeResult(maintenanceResult, "Maintenance");
const storageMonitor = normalizeResult(storageMonitorResult, "Storage maintenance monitor");
const vehicleAssetCatalog = normalizeResult(vehicleAssetCatalogResult, "Canonical Overview catalog");
const vehicleEventShadow = normalizeResult(vehicleEventShadowResult, "Shadow vehicle events");
const vehicleImageCrops = normalizeResult(vehicleImageCropResult, "Canonical Overview vehicle crops");
const vehicleAssetEmbeddings = normalizeResult(vehicleAssetEmbeddingResult, "Canonical crop embeddings");
const vehicleAssetAttributes = normalizeResult(vehicleAssetAttributeResult, "Canonical crop attributes");
const vehicleReid = normalizeResult(vehicleReidV2LiveResult, "Authoritative ReID");
return {
status: cameraInputs.status === "started" && mqtt.status === "started" && vehicleFrames.status === "started" && notificationOperations.status === "started" && maintenance.status === "started" && storageMonitor.status === "started" && vehicleAssetCatalog.status === "started" && vehicleEventShadow.status === "started" && vehicleImageCrops.status === "started" && vehicleAssetEmbeddings.status === "started" && vehicleAssetAttributes.status === "started" && vehicleReid.status === "started"
? "started"
: "partial",
cameraInputs,
mqtt,
vehicleFrames,
notificationOperations,
maintenance,
storageMonitor,
vehicleAssetCatalog,
vehicleEventShadow,
vehicleImageCrops,
vehicleAssetEmbeddings,
vehicleAssetAttributes,
vehicleReid,
};
}