@blokjs/runner 0.2.0
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/dist/Blok.d.ts +19 -0
- package/dist/Blok.js +184 -0
- package/dist/Blok.js.map +1 -0
- package/dist/BlokResponse.d.ts +16 -0
- package/dist/BlokResponse.js +28 -0
- package/dist/BlokResponse.js.map +1 -0
- package/dist/Configuration.d.ts +37 -0
- package/dist/Configuration.js +248 -0
- package/dist/Configuration.js.map +1 -0
- package/dist/ConfigurationResolver.d.ts +7 -0
- package/dist/ConfigurationResolver.js +15 -0
- package/dist/ConfigurationResolver.js.map +1 -0
- package/dist/DefaultLogger.d.ts +65 -0
- package/dist/DefaultLogger.js +101 -0
- package/dist/DefaultLogger.js.map +1 -0
- package/dist/LocalStorage.d.ts +7 -0
- package/dist/LocalStorage.js +56 -0
- package/dist/LocalStorage.js.map +1 -0
- package/dist/MemoryUsage.d.ts +22 -0
- package/dist/MemoryUsage.js +83 -0
- package/dist/MemoryUsage.js.map +1 -0
- package/dist/NodeMap.d.ts +7 -0
- package/dist/NodeMap.js +13 -0
- package/dist/NodeMap.js.map +1 -0
- package/dist/ResolverBase.d.ts +8 -0
- package/dist/ResolverBase.js +18 -0
- package/dist/ResolverBase.js.map +1 -0
- package/dist/Runner.d.ts +25 -0
- package/dist/Runner.js +32 -0
- package/dist/Runner.js.map +1 -0
- package/dist/RunnerNode.d.ts +9 -0
- package/dist/RunnerNode.js +8 -0
- package/dist/RunnerNode.js.map +1 -0
- package/dist/RunnerNodeBase.d.ts +4 -0
- package/dist/RunnerNodeBase.js +3 -0
- package/dist/RunnerNodeBase.js.map +1 -0
- package/dist/RunnerSteps.d.ts +14 -0
- package/dist/RunnerSteps.js +110 -0
- package/dist/RunnerSteps.js.map +1 -0
- package/dist/RuntimeAdapterNode.d.ts +19 -0
- package/dist/RuntimeAdapterNode.js +87 -0
- package/dist/RuntimeAdapterNode.js.map +1 -0
- package/dist/RuntimeRegistry.d.ts +61 -0
- package/dist/RuntimeRegistry.js +87 -0
- package/dist/RuntimeRegistry.js.map +1 -0
- package/dist/TriggerBase.d.ts +119 -0
- package/dist/TriggerBase.js +413 -0
- package/dist/TriggerBase.js.map +1 -0
- package/dist/adapters/BunRuntimeAdapter.d.ts +38 -0
- package/dist/adapters/BunRuntimeAdapter.js +169 -0
- package/dist/adapters/BunRuntimeAdapter.js.map +1 -0
- package/dist/adapters/DockerRuntimeAdapter.d.ts +85 -0
- package/dist/adapters/DockerRuntimeAdapter.js +298 -0
- package/dist/adapters/DockerRuntimeAdapter.js.map +1 -0
- package/dist/adapters/HttpRuntimeAdapter.d.ts +58 -0
- package/dist/adapters/HttpRuntimeAdapter.js +152 -0
- package/dist/adapters/HttpRuntimeAdapter.js.map +1 -0
- package/dist/adapters/NodeJsRuntimeAdapter.d.ts +23 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js +67 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js.map +1 -0
- package/dist/adapters/RuntimeAdapter.d.ts +42 -0
- package/dist/adapters/RuntimeAdapter.js +2 -0
- package/dist/adapters/RuntimeAdapter.js.map +1 -0
- package/dist/adapters/WasmRuntimeAdapter.d.ts +69 -0
- package/dist/adapters/WasmRuntimeAdapter.js +279 -0
- package/dist/adapters/WasmRuntimeAdapter.js.map +1 -0
- package/dist/cache/NodeResultCache.d.ts +286 -0
- package/dist/cache/NodeResultCache.js +499 -0
- package/dist/cache/NodeResultCache.js.map +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cost/CostEstimator.d.ts +57 -0
- package/dist/cost/CostEstimator.js +171 -0
- package/dist/cost/CostEstimator.js.map +1 -0
- package/dist/cost/index.d.ts +4 -0
- package/dist/cost/index.js +3 -0
- package/dist/cost/index.js.map +1 -0
- package/dist/cost/pricing.d.ts +24 -0
- package/dist/cost/pricing.js +169 -0
- package/dist/cost/pricing.js.map +1 -0
- package/dist/defineNode.d.ts +155 -0
- package/dist/defineNode.js +191 -0
- package/dist/defineNode.js.map +1 -0
- package/dist/graphql/GraphQLSchemaGenerator.d.ts +129 -0
- package/dist/graphql/GraphQLSchemaGenerator.js +425 -0
- package/dist/graphql/GraphQLSchemaGenerator.js.map +1 -0
- package/dist/hmr/FileWatcher.d.ts +62 -0
- package/dist/hmr/FileWatcher.js +185 -0
- package/dist/hmr/FileWatcher.js.map +1 -0
- package/dist/hmr/HmrDevConsole.d.ts +13 -0
- package/dist/hmr/HmrDevConsole.js +46 -0
- package/dist/hmr/HmrDevConsole.js.map +1 -0
- package/dist/hmr/HotReloadManager.d.ts +84 -0
- package/dist/hmr/HotReloadManager.js +195 -0
- package/dist/hmr/HotReloadManager.js.map +1 -0
- package/dist/hmr/index.d.ts +39 -0
- package/dist/hmr/index.js +38 -0
- package/dist/hmr/index.js.map +1 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/APMIntegration.d.ts +141 -0
- package/dist/integrations/APMIntegration.js +212 -0
- package/dist/integrations/APMIntegration.js.map +1 -0
- package/dist/integrations/AzureMonitorIntegration.d.ts +118 -0
- package/dist/integrations/AzureMonitorIntegration.js +254 -0
- package/dist/integrations/AzureMonitorIntegration.js.map +1 -0
- package/dist/integrations/CloudWatchIntegration.d.ts +135 -0
- package/dist/integrations/CloudWatchIntegration.js +293 -0
- package/dist/integrations/CloudWatchIntegration.js.map +1 -0
- package/dist/integrations/SentryIntegration.d.ts +153 -0
- package/dist/integrations/SentryIntegration.js +200 -0
- package/dist/integrations/SentryIntegration.js.map +1 -0
- package/dist/integrations/index.d.ts +19 -0
- package/dist/integrations/index.js +16 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/marketplace/RuntimeAutoScaler.d.ts +148 -0
- package/dist/marketplace/RuntimeAutoScaler.js +366 -0
- package/dist/marketplace/RuntimeAutoScaler.js.map +1 -0
- package/dist/marketplace/RuntimeCatalog.d.ts +174 -0
- package/dist/marketplace/RuntimeCatalog.js +339 -0
- package/dist/marketplace/RuntimeCatalog.js.map +1 -0
- package/dist/marketplace/RuntimeDiscovery.d.ts +86 -0
- package/dist/marketplace/RuntimeDiscovery.js +219 -0
- package/dist/marketplace/RuntimeDiscovery.js.map +1 -0
- package/dist/marketplace/RuntimeHealthMonitor.d.ts +100 -0
- package/dist/marketplace/RuntimeHealthMonitor.js +241 -0
- package/dist/marketplace/RuntimeHealthMonitor.js.map +1 -0
- package/dist/marketplace/RuntimeMetricsDashboard.d.ts +113 -0
- package/dist/marketplace/RuntimeMetricsDashboard.js +293 -0
- package/dist/marketplace/RuntimeMetricsDashboard.js.map +1 -0
- package/dist/monitoring/CircuitBreaker.d.ts +107 -0
- package/dist/monitoring/CircuitBreaker.js +238 -0
- package/dist/monitoring/CircuitBreaker.js.map +1 -0
- package/dist/monitoring/DistributedTracer.d.ts +125 -0
- package/dist/monitoring/DistributedTracer.js +230 -0
- package/dist/monitoring/DistributedTracer.js.map +1 -0
- package/dist/monitoring/HealthCheck.d.ts +54 -0
- package/dist/monitoring/HealthCheck.js +102 -0
- package/dist/monitoring/HealthCheck.js.map +1 -0
- package/dist/monitoring/PerformanceProfiler.d.ts +63 -0
- package/dist/monitoring/PerformanceProfiler.js +229 -0
- package/dist/monitoring/PerformanceProfiler.js.map +1 -0
- package/dist/monitoring/PrometheusBootstrap.d.ts +30 -0
- package/dist/monitoring/PrometheusBootstrap.js +71 -0
- package/dist/monitoring/PrometheusBootstrap.js.map +1 -0
- package/dist/monitoring/PrometheusMetricsBridge.d.ts +60 -0
- package/dist/monitoring/PrometheusMetricsBridge.js +216 -0
- package/dist/monitoring/PrometheusMetricsBridge.js.map +1 -0
- package/dist/monitoring/RateLimiter.d.ts +58 -0
- package/dist/monitoring/RateLimiter.js +128 -0
- package/dist/monitoring/RateLimiter.js.map +1 -0
- package/dist/monitoring/StructuredLogger.d.ts +131 -0
- package/dist/monitoring/StructuredLogger.js +207 -0
- package/dist/monitoring/StructuredLogger.js.map +1 -0
- package/dist/monitoring/TracingBootstrap.d.ts +69 -0
- package/dist/monitoring/TracingBootstrap.js +129 -0
- package/dist/monitoring/TracingBootstrap.js.map +1 -0
- package/dist/monitoring/TriggerMetricsCollector.d.ts +94 -0
- package/dist/monitoring/TriggerMetricsCollector.js +174 -0
- package/dist/monitoring/TriggerMetricsCollector.js.map +1 -0
- package/dist/monitoring/index.d.ts +9 -0
- package/dist/monitoring/index.js +10 -0
- package/dist/monitoring/index.js.map +1 -0
- package/dist/openapi/OpenAPIGenerator.d.ts +192 -0
- package/dist/openapi/OpenAPIGenerator.js +373 -0
- package/dist/openapi/OpenAPIGenerator.js.map +1 -0
- package/dist/openapi/index.d.ts +20 -0
- package/dist/openapi/index.js +20 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/security/ABAC.d.ts +224 -0
- package/dist/security/ABAC.js +380 -0
- package/dist/security/ABAC.js.map +1 -0
- package/dist/security/AuditLogger.d.ts +242 -0
- package/dist/security/AuditLogger.js +317 -0
- package/dist/security/AuditLogger.js.map +1 -0
- package/dist/security/AuthMiddleware.d.ts +163 -0
- package/dist/security/AuthMiddleware.js +274 -0
- package/dist/security/AuthMiddleware.js.map +1 -0
- package/dist/security/EncryptionAtRest.d.ts +206 -0
- package/dist/security/EncryptionAtRest.js +236 -0
- package/dist/security/EncryptionAtRest.js.map +1 -0
- package/dist/security/OAuthProvider.d.ts +334 -0
- package/dist/security/OAuthProvider.js +719 -0
- package/dist/security/OAuthProvider.js.map +1 -0
- package/dist/security/PIIDetector.d.ts +233 -0
- package/dist/security/PIIDetector.js +354 -0
- package/dist/security/PIIDetector.js.map +1 -0
- package/dist/security/RBAC.d.ts +143 -0
- package/dist/security/RBAC.js +285 -0
- package/dist/security/RBAC.js.map +1 -0
- package/dist/security/SecretManager.d.ts +652 -0
- package/dist/security/SecretManager.js +1146 -0
- package/dist/security/SecretManager.js.map +1 -0
- package/dist/security/TLSConfig.d.ts +305 -0
- package/dist/security/TLSConfig.js +550 -0
- package/dist/security/TLSConfig.js.map +1 -0
- package/dist/security/index.d.ts +79 -0
- package/dist/security/index.js +80 -0
- package/dist/security/index.js.map +1 -0
- package/dist/testing/TestHarness.d.ts +189 -0
- package/dist/testing/TestHarness.js +272 -0
- package/dist/testing/TestHarness.js.map +1 -0
- package/dist/testing/TestLogger.d.ts +103 -0
- package/dist/testing/TestLogger.js +153 -0
- package/dist/testing/TestLogger.js.map +1 -0
- package/dist/testing/WorkflowTestRunner.d.ts +172 -0
- package/dist/testing/WorkflowTestRunner.js +355 -0
- package/dist/testing/WorkflowTestRunner.js.map +1 -0
- package/dist/testing/index.d.ts +21 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tracing/InMemoryRunStore.d.ts +44 -0
- package/dist/tracing/InMemoryRunStore.js +341 -0
- package/dist/tracing/InMemoryRunStore.js.map +1 -0
- package/dist/tracing/PostgresRunStore.d.ts +82 -0
- package/dist/tracing/PostgresRunStore.js +640 -0
- package/dist/tracing/PostgresRunStore.js.map +1 -0
- package/dist/tracing/RunStore.d.ts +38 -0
- package/dist/tracing/RunStore.js +2 -0
- package/dist/tracing/RunStore.js.map +1 -0
- package/dist/tracing/RunTracker.d.ts +75 -0
- package/dist/tracing/RunTracker.js +374 -0
- package/dist/tracing/RunTracker.js.map +1 -0
- package/dist/tracing/SqliteRunStore.d.ts +53 -0
- package/dist/tracing/SqliteRunStore.js +703 -0
- package/dist/tracing/SqliteRunStore.js.map +1 -0
- package/dist/tracing/TraceRouter.d.ts +47 -0
- package/dist/tracing/TraceRouter.js +904 -0
- package/dist/tracing/TraceRouter.js.map +1 -0
- package/dist/tracing/TracingLogger.d.ts +21 -0
- package/dist/tracing/TracingLogger.js +62 -0
- package/dist/tracing/TracingLogger.js.map +1 -0
- package/dist/tracing/createStore.d.ts +30 -0
- package/dist/tracing/createStore.js +75 -0
- package/dist/tracing/createStore.js.map +1 -0
- package/dist/tracing/index.d.ts +13 -0
- package/dist/tracing/index.js +9 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/sanitize.d.ts +7 -0
- package/dist/tracing/sanitize.js +95 -0
- package/dist/tracing/sanitize.js.map +1 -0
- package/dist/tracing/types.d.ts +178 -0
- package/dist/tracing/types.js +3 -0
- package/dist/tracing/types.js.map +1 -0
- package/dist/types/Average.d.ts +11 -0
- package/dist/types/Average.js +2 -0
- package/dist/types/Average.js.map +1 -0
- package/dist/types/Condition.d.ts +8 -0
- package/dist/types/Condition.js +2 -0
- package/dist/types/Condition.js.map +1 -0
- package/dist/types/Conditions.d.ts +5 -0
- package/dist/types/Conditions.js +2 -0
- package/dist/types/Conditions.js.map +1 -0
- package/dist/types/Config.d.ts +12 -0
- package/dist/types/Config.js +2 -0
- package/dist/types/Config.js.map +1 -0
- package/dist/types/Flow.d.ts +5 -0
- package/dist/types/Flow.js +2 -0
- package/dist/types/Flow.js.map +1 -0
- package/dist/types/GlobalOptions.d.ts +11 -0
- package/dist/types/GlobalOptions.js +2 -0
- package/dist/types/GlobalOptions.js.map +1 -0
- package/dist/types/Inputs.d.ts +5 -0
- package/dist/types/Inputs.js +2 -0
- package/dist/types/Inputs.js.map +1 -0
- package/dist/types/JsonLikeObject.d.ts +3 -0
- package/dist/types/JsonLikeObject.js +2 -0
- package/dist/types/JsonLikeObject.js.map +1 -0
- package/dist/types/Mapper.d.ts +5 -0
- package/dist/types/Mapper.js +2 -0
- package/dist/types/Mapper.js.map +1 -0
- package/dist/types/Node.d.ts +10 -0
- package/dist/types/Node.js +2 -0
- package/dist/types/Node.js.map +1 -0
- package/dist/types/ParamsDictionary.d.ts +3 -0
- package/dist/types/ParamsDictionary.js +2 -0
- package/dist/types/ParamsDictionary.js.map +1 -0
- package/dist/types/Properties.d.ts +5 -0
- package/dist/types/Properties.js +2 -0
- package/dist/types/Properties.js.map +1 -0
- package/dist/types/Targets.d.ts +5 -0
- package/dist/types/Targets.js +2 -0
- package/dist/types/Targets.js.map +1 -0
- package/dist/types/Trigger.d.ts +5 -0
- package/dist/types/Trigger.js +2 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/types/TriggerHttp.d.ts +7 -0
- package/dist/types/TriggerHttp.js +2 -0
- package/dist/types/TriggerHttp.js.map +1 -0
- package/dist/types/TriggerResponse.d.ts +6 -0
- package/dist/types/TriggerResponse.js +2 -0
- package/dist/types/TriggerResponse.js.map +1 -0
- package/dist/types/Triggers.d.ts +5 -0
- package/dist/types/Triggers.js +2 -0
- package/dist/types/Triggers.js.map +1 -0
- package/dist/types/TryCatch.d.ts +6 -0
- package/dist/types/TryCatch.js +2 -0
- package/dist/types/TryCatch.js.map +1 -0
- package/dist/visualization/NodeDependencyGraph.d.ts +76 -0
- package/dist/visualization/NodeDependencyGraph.js +418 -0
- package/dist/visualization/NodeDependencyGraph.js.map +1 -0
- package/dist/visualization/WorkflowVisualizer.d.ts +144 -0
- package/dist/visualization/WorkflowVisualizer.js +446 -0
- package/dist/visualization/WorkflowVisualizer.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure Monitor Integration for Blok
|
|
3
|
+
*
|
|
4
|
+
* Exports traces, metrics, and logs to Azure Application Insights via the
|
|
5
|
+
* Azure Monitor OpenTelemetry Exporter or the Application Insights SDK.
|
|
6
|
+
*
|
|
7
|
+
* Supports two modes:
|
|
8
|
+
* 1. **OTLP mode** (recommended) – Uses the generic OTLP exporter pointing at
|
|
9
|
+
* the Azure Monitor OTLP endpoint. Requires an Application Insights
|
|
10
|
+
* connection string.
|
|
11
|
+
* 2. **Azure Exporter mode** – Uses `@azure/monitor-opentelemetry-exporter`
|
|
12
|
+
* for native Azure integration with automatic sampling and live metrics.
|
|
13
|
+
*
|
|
14
|
+
* All Azure SDK dependencies are loaded lazily so the framework doesn't
|
|
15
|
+
* hard-depend on any Azure packages. If the packages are not installed
|
|
16
|
+
* `init()` returns false and the integration is a no-op.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { AzureMonitorIntegration } from "@blokjs/runner";
|
|
21
|
+
*
|
|
22
|
+
* const azure = new AzureMonitorIntegration({
|
|
23
|
+
* connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING!,
|
|
24
|
+
* serviceName: "blok-http",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* await azure.init();
|
|
28
|
+
*
|
|
29
|
+
* // Track a custom event
|
|
30
|
+
* azure.trackEvent("WorkflowCompleted", { workflowName: "get-user", durationMs: "42" });
|
|
31
|
+
*
|
|
32
|
+
* // Track an exception
|
|
33
|
+
* azure.trackException(error, { workflowName: "get-user", nodeName: "fetch-db" });
|
|
34
|
+
*
|
|
35
|
+
* // Track a metric
|
|
36
|
+
* azure.trackMetric("WorkflowDuration", 42);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface AzureMonitorConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Application Insights connection string.
|
|
42
|
+
* Falls back to APPLICATIONINSIGHTS_CONNECTION_STRING env var.
|
|
43
|
+
*/
|
|
44
|
+
connectionString?: string;
|
|
45
|
+
/** Blok service name */
|
|
46
|
+
serviceName: string;
|
|
47
|
+
/** Service version */
|
|
48
|
+
serviceVersion?: string;
|
|
49
|
+
/** Environment label */
|
|
50
|
+
environment?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Export mode:
|
|
53
|
+
* - "azure" – use @azure/monitor-opentelemetry-exporter (native)
|
|
54
|
+
* - "otlp" – use generic OTLP exporter with Azure ingestion endpoint
|
|
55
|
+
* Default: "azure"
|
|
56
|
+
*/
|
|
57
|
+
exportMode?: "azure" | "otlp";
|
|
58
|
+
/** Trace sampling ratio (0.0 – 1.0, default: 1.0) */
|
|
59
|
+
samplingRatio?: number;
|
|
60
|
+
/** Enable live metrics stream (default: false) */
|
|
61
|
+
enableLiveMetrics?: boolean;
|
|
62
|
+
/** Enable debug logging */
|
|
63
|
+
debug?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface AzureMonitorStats {
|
|
66
|
+
initialized: boolean;
|
|
67
|
+
eventsTracked: number;
|
|
68
|
+
exceptionsTracked: number;
|
|
69
|
+
metricsTracked: number;
|
|
70
|
+
}
|
|
71
|
+
export declare class AzureMonitorIntegration {
|
|
72
|
+
private config;
|
|
73
|
+
private initialized;
|
|
74
|
+
private exporter;
|
|
75
|
+
private tracingShutdown;
|
|
76
|
+
private telemetryClient;
|
|
77
|
+
private eventsTracked;
|
|
78
|
+
private exceptionsTracked;
|
|
79
|
+
private metricsTracked;
|
|
80
|
+
constructor(config: AzureMonitorConfig);
|
|
81
|
+
/**
|
|
82
|
+
* Initialize Azure Monitor.
|
|
83
|
+
* Returns false if required packages or connection string are missing.
|
|
84
|
+
*/
|
|
85
|
+
init(): Promise<boolean>;
|
|
86
|
+
private initAzureExporter;
|
|
87
|
+
private initOTLP;
|
|
88
|
+
private initTelemetryClient;
|
|
89
|
+
/**
|
|
90
|
+
* Track a custom event (e.g. "WorkflowCompleted").
|
|
91
|
+
*/
|
|
92
|
+
trackEvent(name: string, properties?: Record<string, string>): void;
|
|
93
|
+
/**
|
|
94
|
+
* Track an exception.
|
|
95
|
+
*/
|
|
96
|
+
trackException(error: Error, properties?: Record<string, string>): void;
|
|
97
|
+
/**
|
|
98
|
+
* Track a numeric metric.
|
|
99
|
+
*/
|
|
100
|
+
trackMetric(name: string, value: number, properties?: Record<string, string>): void;
|
|
101
|
+
/**
|
|
102
|
+
* Record a workflow execution as both a custom event and metric.
|
|
103
|
+
*/
|
|
104
|
+
recordWorkflowExecution(workflowName: string, durationMs: number, success: boolean): void;
|
|
105
|
+
isInitialized(): boolean;
|
|
106
|
+
getStats(): AzureMonitorStats;
|
|
107
|
+
shutdown(): Promise<void>;
|
|
108
|
+
flush(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Extract the ingestion endpoint from an Application Insights connection string.
|
|
111
|
+
* Format: InstrumentationKey=...;IngestionEndpoint=https://...;...
|
|
112
|
+
*/
|
|
113
|
+
private extractEndpoint;
|
|
114
|
+
/**
|
|
115
|
+
* Extract the instrumentation key from an Application Insights connection string.
|
|
116
|
+
*/
|
|
117
|
+
private extractInstrumentationKey;
|
|
118
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure Monitor Integration for Blok
|
|
3
|
+
*
|
|
4
|
+
* Exports traces, metrics, and logs to Azure Application Insights via the
|
|
5
|
+
* Azure Monitor OpenTelemetry Exporter or the Application Insights SDK.
|
|
6
|
+
*
|
|
7
|
+
* Supports two modes:
|
|
8
|
+
* 1. **OTLP mode** (recommended) – Uses the generic OTLP exporter pointing at
|
|
9
|
+
* the Azure Monitor OTLP endpoint. Requires an Application Insights
|
|
10
|
+
* connection string.
|
|
11
|
+
* 2. **Azure Exporter mode** – Uses `@azure/monitor-opentelemetry-exporter`
|
|
12
|
+
* for native Azure integration with automatic sampling and live metrics.
|
|
13
|
+
*
|
|
14
|
+
* All Azure SDK dependencies are loaded lazily so the framework doesn't
|
|
15
|
+
* hard-depend on any Azure packages. If the packages are not installed
|
|
16
|
+
* `init()` returns false and the integration is a no-op.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { AzureMonitorIntegration } from "@blokjs/runner";
|
|
21
|
+
*
|
|
22
|
+
* const azure = new AzureMonitorIntegration({
|
|
23
|
+
* connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING!,
|
|
24
|
+
* serviceName: "blok-http",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* await azure.init();
|
|
28
|
+
*
|
|
29
|
+
* // Track a custom event
|
|
30
|
+
* azure.trackEvent("WorkflowCompleted", { workflowName: "get-user", durationMs: "42" });
|
|
31
|
+
*
|
|
32
|
+
* // Track an exception
|
|
33
|
+
* azure.trackException(error, { workflowName: "get-user", nodeName: "fetch-db" });
|
|
34
|
+
*
|
|
35
|
+
* // Track a metric
|
|
36
|
+
* azure.trackMetric("WorkflowDuration", 42);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class AzureMonitorIntegration {
|
|
40
|
+
config;
|
|
41
|
+
initialized = false;
|
|
42
|
+
exporter = null;
|
|
43
|
+
tracingShutdown = null;
|
|
44
|
+
// Telemetry client for custom events / metrics (Application Insights SDK)
|
|
45
|
+
telemetryClient = null;
|
|
46
|
+
// stats
|
|
47
|
+
eventsTracked = 0;
|
|
48
|
+
exceptionsTracked = 0;
|
|
49
|
+
metricsTracked = 0;
|
|
50
|
+
constructor(config) {
|
|
51
|
+
this.config = {
|
|
52
|
+
connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING,
|
|
53
|
+
serviceVersion: "0.0.1",
|
|
54
|
+
environment: process.env.NODE_ENV || "development",
|
|
55
|
+
exportMode: "azure",
|
|
56
|
+
samplingRatio: 1.0,
|
|
57
|
+
enableLiveMetrics: false,
|
|
58
|
+
debug: false,
|
|
59
|
+
...config,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Initialize Azure Monitor.
|
|
64
|
+
* Returns false if required packages or connection string are missing.
|
|
65
|
+
*/
|
|
66
|
+
async init() {
|
|
67
|
+
if (this.initialized)
|
|
68
|
+
return true;
|
|
69
|
+
const connStr = this.config.connectionString;
|
|
70
|
+
if (!connStr)
|
|
71
|
+
return false;
|
|
72
|
+
try {
|
|
73
|
+
if (this.config.exportMode === "azure") {
|
|
74
|
+
return await this.initAzureExporter(connStr);
|
|
75
|
+
}
|
|
76
|
+
return await this.initOTLP(connStr);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/* ------------------------------------------------------------------ */
|
|
83
|
+
/* Azure Monitor exporter mode */
|
|
84
|
+
/* ------------------------------------------------------------------ */
|
|
85
|
+
async initAzureExporter(connectionString) {
|
|
86
|
+
try {
|
|
87
|
+
// @ts-expect-error: optional peer dependency
|
|
88
|
+
const azureMod = await import("@azure/monitor-opentelemetry-exporter");
|
|
89
|
+
// The Azure trace exporter works via OpenTelemetry's TracerProvider.
|
|
90
|
+
// We bootstrap tracing with it by piping through our standard bootstrap
|
|
91
|
+
// path — the Azure exporter is OTLP-compatible.
|
|
92
|
+
const exporter = new azureMod.AzureMonitorTraceExporter({
|
|
93
|
+
connectionString,
|
|
94
|
+
});
|
|
95
|
+
this.exporter = exporter;
|
|
96
|
+
// Also try to set up a lightweight telemetry client for custom events
|
|
97
|
+
await this.initTelemetryClient(connectionString);
|
|
98
|
+
this.initialized = true;
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Fall back to OTLP mode
|
|
103
|
+
return this.initOTLP(connectionString);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/* ------------------------------------------------------------------ */
|
|
107
|
+
/* OTLP mode (uses TracingBootstrap pointing at Azure endpoint) */
|
|
108
|
+
/* ------------------------------------------------------------------ */
|
|
109
|
+
async initOTLP(connectionString) {
|
|
110
|
+
try {
|
|
111
|
+
// Extract ingestion endpoint from connection string
|
|
112
|
+
const endpoint = this.extractEndpoint(connectionString);
|
|
113
|
+
const instrumentationKey = this.extractInstrumentationKey(connectionString);
|
|
114
|
+
if (!endpoint || !instrumentationKey)
|
|
115
|
+
return false;
|
|
116
|
+
const { bootstrapTracing } = await import("../monitoring/TracingBootstrap");
|
|
117
|
+
const result = await bootstrapTracing({
|
|
118
|
+
serviceName: this.config.serviceName,
|
|
119
|
+
serviceVersion: this.config.serviceVersion,
|
|
120
|
+
exporter: "otlp",
|
|
121
|
+
endpoint: `${endpoint}/v2/track`,
|
|
122
|
+
headers: {
|
|
123
|
+
"x-ms-instrumentationkey": instrumentationKey,
|
|
124
|
+
},
|
|
125
|
+
samplingRatio: this.config.samplingRatio,
|
|
126
|
+
});
|
|
127
|
+
if (!result)
|
|
128
|
+
return false;
|
|
129
|
+
this.tracingShutdown = result.shutdown;
|
|
130
|
+
await this.initTelemetryClient(connectionString);
|
|
131
|
+
this.initialized = true;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/* ------------------------------------------------------------------ */
|
|
139
|
+
/* Lightweight telemetry client (custom events, metrics) */
|
|
140
|
+
/* ------------------------------------------------------------------ */
|
|
141
|
+
async initTelemetryClient(connectionString) {
|
|
142
|
+
try {
|
|
143
|
+
// @ts-expect-error: optional peer dependency
|
|
144
|
+
const appInsights = await import("applicationinsights");
|
|
145
|
+
appInsights.setup(connectionString).setAutoCollectRequests(false).start();
|
|
146
|
+
const client = appInsights.defaultClient;
|
|
147
|
+
if (!client)
|
|
148
|
+
return;
|
|
149
|
+
this.telemetryClient = {
|
|
150
|
+
trackEvent: (event) => client.trackEvent(event),
|
|
151
|
+
trackException: (exc) => client.trackException(exc),
|
|
152
|
+
trackMetric: (metric) => client.trackMetric(metric),
|
|
153
|
+
flush: () => new Promise((resolve) => {
|
|
154
|
+
client.flush({ callback: () => resolve() });
|
|
155
|
+
}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// applicationinsights package not installed — custom events won't work
|
|
160
|
+
// but tracing via OTLP will still function
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/* ------------------------------------------------------------------ */
|
|
164
|
+
/* Custom telemetry helpers */
|
|
165
|
+
/* ------------------------------------------------------------------ */
|
|
166
|
+
/**
|
|
167
|
+
* Track a custom event (e.g. "WorkflowCompleted").
|
|
168
|
+
*/
|
|
169
|
+
trackEvent(name, properties) {
|
|
170
|
+
if (!this.telemetryClient)
|
|
171
|
+
return;
|
|
172
|
+
this.telemetryClient.trackEvent({ name, properties });
|
|
173
|
+
this.eventsTracked++;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Track an exception.
|
|
177
|
+
*/
|
|
178
|
+
trackException(error, properties) {
|
|
179
|
+
if (!this.telemetryClient)
|
|
180
|
+
return;
|
|
181
|
+
this.telemetryClient.trackException({ exception: error, properties });
|
|
182
|
+
this.exceptionsTracked++;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Track a numeric metric.
|
|
186
|
+
*/
|
|
187
|
+
trackMetric(name, value, properties) {
|
|
188
|
+
if (!this.telemetryClient)
|
|
189
|
+
return;
|
|
190
|
+
this.telemetryClient.trackMetric({ name, value, properties });
|
|
191
|
+
this.metricsTracked++;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Record a workflow execution as both a custom event and metric.
|
|
195
|
+
*/
|
|
196
|
+
recordWorkflowExecution(workflowName, durationMs, success) {
|
|
197
|
+
this.trackEvent(success ? "WorkflowCompleted" : "WorkflowFailed", {
|
|
198
|
+
workflowName,
|
|
199
|
+
durationMs: String(durationMs),
|
|
200
|
+
environment: this.config.environment || "development",
|
|
201
|
+
});
|
|
202
|
+
this.trackMetric("WorkflowDuration", durationMs, { workflowName });
|
|
203
|
+
if (!success) {
|
|
204
|
+
this.trackMetric("WorkflowErrors", 1, { workflowName });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/* ------------------------------------------------------------------ */
|
|
208
|
+
/* Lifecycle */
|
|
209
|
+
/* ------------------------------------------------------------------ */
|
|
210
|
+
isInitialized() {
|
|
211
|
+
return this.initialized;
|
|
212
|
+
}
|
|
213
|
+
getStats() {
|
|
214
|
+
return {
|
|
215
|
+
initialized: this.initialized,
|
|
216
|
+
eventsTracked: this.eventsTracked,
|
|
217
|
+
exceptionsTracked: this.exceptionsTracked,
|
|
218
|
+
metricsTracked: this.metricsTracked,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
async shutdown() {
|
|
222
|
+
if (this.tracingShutdown) {
|
|
223
|
+
await this.tracingShutdown();
|
|
224
|
+
}
|
|
225
|
+
if (this.exporter?.shutdown) {
|
|
226
|
+
await this.exporter.shutdown();
|
|
227
|
+
}
|
|
228
|
+
this.initialized = false;
|
|
229
|
+
}
|
|
230
|
+
async flush() {
|
|
231
|
+
if (this.telemetryClient) {
|
|
232
|
+
await this.telemetryClient.flush();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/* ------------------------------------------------------------------ */
|
|
236
|
+
/* Connection string parsing */
|
|
237
|
+
/* ------------------------------------------------------------------ */
|
|
238
|
+
/**
|
|
239
|
+
* Extract the ingestion endpoint from an Application Insights connection string.
|
|
240
|
+
* Format: InstrumentationKey=...;IngestionEndpoint=https://...;...
|
|
241
|
+
*/
|
|
242
|
+
extractEndpoint(connectionString) {
|
|
243
|
+
const match = connectionString.match(/IngestionEndpoint=([^;]+)/i);
|
|
244
|
+
return match?.[1]?.replace(/\/$/, "") ?? null;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Extract the instrumentation key from an Application Insights connection string.
|
|
248
|
+
*/
|
|
249
|
+
extractInstrumentationKey(connectionString) {
|
|
250
|
+
const match = connectionString.match(/InstrumentationKey=([^;]+)/i);
|
|
251
|
+
return match?.[1] ?? null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=AzureMonitorIntegration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AzureMonitorIntegration.js","sourceRoot":"","sources":["../../src/integrations/AzureMonitorIntegration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AA8CH,MAAM,OAAO,uBAAuB;IAC3B,MAAM,CAAyE;IAC/E,WAAW,GAAG,KAAK,CAAC;IACpB,QAAQ,GAA6B,IAAI,CAAC;IAC1C,eAAe,GAAiC,IAAI,CAAC;IAE7D,0EAA0E;IAClE,eAAe,GAKZ,IAAI,CAAC;IAEhB,QAAQ;IACA,aAAa,GAAG,CAAC,CAAC;IAClB,iBAAiB,GAAG,CAAC,CAAC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AAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACb,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK;QACV,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QACpC,CAAC;IACF,CAAC;IAED,wEAAwE;IACxE,wEAAwE;IACxE,wEAAwE;IAExE;;;OAGG;IACK,eAAe,CAAC,gBAAwB;QAC/C,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACnE,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC;IAC/C,CAAC;IAED;;OAEG;IACK,yBAAyB,CAAC,gBAAwB;QACzD,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACpE,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC3B,CAAC;CACD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS CloudWatch Integration for Blok
|
|
3
|
+
*
|
|
4
|
+
* Sends metrics to CloudWatch Metrics and logs to CloudWatch Logs.
|
|
5
|
+
* Traces are exported via OTLP to the AWS Distro for OpenTelemetry (ADOT)
|
|
6
|
+
* Collector, which forwards them to AWS X-Ray.
|
|
7
|
+
*
|
|
8
|
+
* Uses lazy dynamic imports so AWS SDK packages are optional peer
|
|
9
|
+
* dependencies. If the SDK is not installed the integration silently
|
|
10
|
+
* degrades (init returns false).
|
|
11
|
+
*
|
|
12
|
+
* Supported transports:
|
|
13
|
+
* - **Metrics** – CloudWatch PutMetricData (via @aws-sdk/client-cloudwatch)
|
|
14
|
+
* - **Logs** – CloudWatch Logs PutLogEvents (via @aws-sdk/client-cloudwatch-logs)
|
|
15
|
+
* - **Traces** – OTLP → ADOT Collector → X-Ray (reuses TracingBootstrap)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { CloudWatchIntegration } from "@blokjs/runner";
|
|
20
|
+
*
|
|
21
|
+
* const cw = new CloudWatchIntegration({
|
|
22
|
+
* region: "us-east-1",
|
|
23
|
+
* serviceName: "blok-http",
|
|
24
|
+
* logGroupName: "/blok/workflows",
|
|
25
|
+
* namespace: "Blok",
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* await cw.init();
|
|
29
|
+
*
|
|
30
|
+
* // Send a custom metric
|
|
31
|
+
* await cw.putMetric("WorkflowDuration", 42, "Milliseconds");
|
|
32
|
+
*
|
|
33
|
+
* // Send a structured log entry
|
|
34
|
+
* await cw.putLog({ level: "info", message: "workflow completed", workflowName: "get-user" });
|
|
35
|
+
*
|
|
36
|
+
* // Enable OTLP traces via ADOT Collector
|
|
37
|
+
* const cw = new CloudWatchIntegration({
|
|
38
|
+
* region: "us-east-1",
|
|
39
|
+
* serviceName: "blok-http",
|
|
40
|
+
* enableTracing: true,
|
|
41
|
+
* adotEndpoint: "http://localhost:4318/v1/traces",
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface CloudWatchConfig {
|
|
46
|
+
/** AWS region (e.g. "us-east-1"). Falls back to AWS_REGION env var. */
|
|
47
|
+
region?: string;
|
|
48
|
+
/** Blok service name (used in metric dimensions and log metadata) */
|
|
49
|
+
serviceName: string;
|
|
50
|
+
/** Service version */
|
|
51
|
+
serviceVersion?: string;
|
|
52
|
+
/** Environment label */
|
|
53
|
+
environment?: string;
|
|
54
|
+
/** CloudWatch Logs log group name (default: "/blok/workflows") */
|
|
55
|
+
logGroupName?: string;
|
|
56
|
+
/** CloudWatch Logs log stream name (default: serviceName-<date>) */
|
|
57
|
+
logStreamName?: string;
|
|
58
|
+
/** CloudWatch Metrics namespace (default: "Blok") */
|
|
59
|
+
namespace?: string;
|
|
60
|
+
/** Enable OTLP trace export via ADOT Collector → X-Ray */
|
|
61
|
+
enableTracing?: boolean;
|
|
62
|
+
/** ADOT Collector OTLP endpoint (default: http://localhost:4318/v1/traces) */
|
|
63
|
+
adotEndpoint?: string;
|
|
64
|
+
/** Trace sampling ratio (0.0 – 1.0, default: 1.0) */
|
|
65
|
+
samplingRatio?: number;
|
|
66
|
+
/** Enable debug logging */
|
|
67
|
+
debug?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** Supported CloudWatch metric units */
|
|
70
|
+
export type CloudWatchUnit = "Seconds" | "Microseconds" | "Milliseconds" | "Bytes" | "Kilobytes" | "Megabytes" | "Gigabytes" | "Bits" | "Percent" | "Count" | "Count/Second" | "None";
|
|
71
|
+
export interface CloudWatchLogEntry {
|
|
72
|
+
level: "debug" | "info" | "warn" | "error" | "fatal";
|
|
73
|
+
message: string;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
export interface CloudWatchStats {
|
|
77
|
+
initialized: boolean;
|
|
78
|
+
metricsPublished: number;
|
|
79
|
+
logsPublished: number;
|
|
80
|
+
metricErrors: number;
|
|
81
|
+
logErrors: number;
|
|
82
|
+
tracingEnabled: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare class CloudWatchIntegration {
|
|
85
|
+
private config;
|
|
86
|
+
private cwClient;
|
|
87
|
+
private cwLogsClient;
|
|
88
|
+
private initialized;
|
|
89
|
+
private tracingInitialized;
|
|
90
|
+
private tracingShutdown;
|
|
91
|
+
private sequenceToken;
|
|
92
|
+
private PutMetricDataCommand;
|
|
93
|
+
private PutLogEventsCommand;
|
|
94
|
+
private CreateLogGroupCommand;
|
|
95
|
+
private CreateLogStreamCommand;
|
|
96
|
+
private metricsPublished;
|
|
97
|
+
private logsPublished;
|
|
98
|
+
private metricErrors;
|
|
99
|
+
private logErrors;
|
|
100
|
+
constructor(config: CloudWatchConfig);
|
|
101
|
+
/**
|
|
102
|
+
* Initialize CloudWatch clients.
|
|
103
|
+
* Returns false if AWS SDK packages are not installed.
|
|
104
|
+
*/
|
|
105
|
+
init(): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Publish a custom metric to CloudWatch.
|
|
108
|
+
*/
|
|
109
|
+
putMetric(metricName: string, value: number, unit?: CloudWatchUnit, dimensions?: Record<string, string>): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Publish workflow execution metrics (duration + error count).
|
|
112
|
+
*/
|
|
113
|
+
recordWorkflowExecution(workflowName: string, durationMs: number, success: boolean): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Send a structured log entry to CloudWatch Logs.
|
|
116
|
+
*/
|
|
117
|
+
putLog(entry: CloudWatchLogEntry): Promise<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* Log a workflow error to CloudWatch Logs.
|
|
120
|
+
*/
|
|
121
|
+
logWorkflowError(error: Error, context: {
|
|
122
|
+
workflowName: string;
|
|
123
|
+
workflowPath: string;
|
|
124
|
+
requestId?: string;
|
|
125
|
+
nodeName?: string;
|
|
126
|
+
}): Promise<boolean>;
|
|
127
|
+
private initTracing;
|
|
128
|
+
isInitialized(): boolean;
|
|
129
|
+
isTracingEnabled(): boolean;
|
|
130
|
+
getStats(): CloudWatchStats;
|
|
131
|
+
shutdown(): Promise<void>;
|
|
132
|
+
flush(): Promise<void>;
|
|
133
|
+
private getLogStreamName;
|
|
134
|
+
private ensureLogDestination;
|
|
135
|
+
}
|