@livestore/utils 0.0.0 → 0.0.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/dist/.tsbuildinfo.json +1 -1
- package/dist/NoopTracer.d.ts +1 -0
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/NoopTracer.js +1 -1
- package/dist/NoopTracer.js.map +1 -1
- package/dist/effect/Effect.d.ts +4 -0
- package/dist/effect/Effect.d.ts.map +1 -1
- package/dist/effect/Effect.js +8 -0
- package/dist/effect/Effect.js.map +1 -1
- package/dist/effect/Layer.d.ts +17 -3
- package/dist/effect/Layer.d.ts.map +1 -1
- package/dist/effect/Layer.js +8 -7
- package/dist/effect/Layer.js.map +1 -1
- package/dist/effect/ServiceContext.d.ts.map +1 -1
- package/dist/effect/ServiceContext.js +7 -7
- package/dist/effect/ServiceContext.js.map +1 -1
- package/dist/effect/index.d.ts +3 -2
- package/dist/effect/index.d.ts.map +1 -1
- package/dist/effect/index.js +3 -3
- package/dist/effect/index.js.map +1 -1
- package/package.json +12 -23
- package/src/NoopTracer.ts +1 -1
- package/src/effect/Effect.ts +18 -0
- package/src/effect/Layer.ts +42 -0
- package/src/effect/ServiceContext.ts +7 -9
- package/src/effect/index.ts +4 -4
- package/dist/binary.d.ts +0 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -23
- package/dist/binary.js.map +0 -1
- package/dist/effect/Debounce.d.ts +0 -5
- package/dist/effect/Debounce.d.ts.map +0 -1
- package/dist/effect/Debounce.js +0 -33
- package/dist/effect/Debounce.js.map +0 -1
- package/dist/effect/EndableQueue.d.ts +0 -11
- package/dist/effect/EndableQueue.d.ts.map +0 -1
- package/dist/effect/EndableQueue.js +0 -22
- package/dist/effect/EndableQueue.js.map +0 -1
- package/dist/effect/EnvVar.d.ts +0 -16
- package/dist/effect/EnvVar.d.ts.map +0 -1
- package/dist/effect/EnvVar.js +0 -21
- package/dist/effect/EnvVar.js.map +0 -1
- package/dist/effect/Gate.d.ts +0 -14
- package/dist/effect/Gate.d.ts.map +0 -1
- package/dist/effect/Gate.js +0 -17
- package/dist/effect/Gate.js.map +0 -1
- package/dist/effect/Otel/Dummy.d.ts +0 -5
- package/dist/effect/Otel/Dummy.d.ts.map +0 -1
- package/dist/effect/Otel/Dummy.js +0 -22
- package/dist/effect/Otel/Dummy.js.map +0 -1
- package/dist/effect/Otel/Meter.d.ts +0 -20
- package/dist/effect/Otel/Meter.d.ts.map +0 -1
- package/dist/effect/Otel/Meter.js +0 -76
- package/dist/effect/Otel/Meter.js.map +0 -1
- package/dist/effect/Otel/OtlpGrpc.d.ts +0 -6
- package/dist/effect/Otel/OtlpGrpc.d.ts.map +0 -1
- package/dist/effect/Otel/OtlpGrpc.js +0 -42
- package/dist/effect/Otel/OtlpGrpc.js.map +0 -1
- package/dist/effect/Otel/OtlpHttp.d.ts +0 -6
- package/dist/effect/Otel/OtlpHttp.d.ts.map +0 -1
- package/dist/effect/Otel/OtlpHttp.js +0 -42
- package/dist/effect/Otel/OtlpHttp.js.map +0 -1
- package/dist/effect/Otel/OtlpWebsocket.d.ts +0 -6
- package/dist/effect/Otel/OtlpWebsocket.d.ts.map +0 -1
- package/dist/effect/Otel/OtlpWebsocket.js +0 -42
- package/dist/effect/Otel/OtlpWebsocket.js.map +0 -1
- package/dist/effect/Otel/Span.d.ts +0 -32
- package/dist/effect/Otel/Span.d.ts.map +0 -1
- package/dist/effect/Otel/Span.js +0 -97
- package/dist/effect/Otel/Span.js.map +0 -1
- package/dist/effect/Otel/Tracer.d.ts +0 -15
- package/dist/effect/Otel/Tracer.d.ts.map +0 -1
- package/dist/effect/Otel/Tracer.js +0 -17
- package/dist/effect/Otel/Tracer.js.map +0 -1
- package/dist/effect/Otel/index.d.ts +0 -8
- package/dist/effect/Otel/index.d.ts.map +0 -1
- package/dist/effect/Otel/index.js +0 -9
- package/dist/effect/Otel/index.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpGrpc.d.ts +0 -14
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpGrpc.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpGrpc.js +0 -15
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpGrpc.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpHttp.d.ts +0 -14
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpHttp.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpHttp.js +0 -15
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpHttp.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpWebsocket.d.ts +0 -19
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpWebsocket.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpWebsocket.js +0 -17
- package/dist/effect/Otel/lib-metrics/ExporterMetricsOltpWebsocket.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/MetricsProvider.d.ts +0 -10
- package/dist/effect/Otel/lib-metrics/MetricsProvider.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/MetricsProvider.js +0 -4
- package/dist/effect/Otel/lib-metrics/MetricsProvider.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderGrpc.d.ts +0 -16
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderGrpc.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderGrpc.js +0 -39
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderGrpc.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderHttp.d.ts +0 -16
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderHttp.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderHttp.js +0 -39
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderHttp.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderWebsocket.d.ts +0 -16
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderWebsocket.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderWebsocket.js +0 -39
- package/dist/effect/Otel/lib-metrics/OTLPMetricsProviderWebsocket.js.map +0 -1
- package/dist/effect/Otel/lib-metrics/PeriodicMetricsProvider.d.ts +0 -17
- package/dist/effect/Otel/lib-metrics/PeriodicMetricsProvider.d.ts.map +0 -1
- package/dist/effect/Otel/lib-metrics/PeriodicMetricsProvider.js +0 -27
- package/dist/effect/Otel/lib-metrics/PeriodicMetricsProvider.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/BatchSpanProcessor.d.ts +0 -18
- package/dist/effect/Otel/lib-tracer/BatchSpanProcessor.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/BatchSpanProcessor.js +0 -31
- package/dist/effect/Otel/lib-tracer/BatchSpanProcessor.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpGrpc.d.ts +0 -19
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpGrpc.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpGrpc.js +0 -36
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpGrpc.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpHttp.d.ts +0 -19
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpHttp.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpHttp.js +0 -36
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpHttp.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpWebsocket.d.ts +0 -9
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpWebsocket.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpWebsocket.js +0 -29
- package/dist/effect/Otel/lib-tracer/ExporterTraceOtlpWebsocket.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/SimpleProcessor.d.ts +0 -19
- package/dist/effect/Otel/lib-tracer/SimpleProcessor.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/SimpleProcessor.js +0 -25
- package/dist/effect/Otel/lib-tracer/SimpleProcessor.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/TracerProvider.d.ts +0 -10
- package/dist/effect/Otel/lib-tracer/TracerProvider.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/TracerProvider.js +0 -7
- package/dist/effect/Otel/lib-tracer/TracerProvider.js.map +0 -1
- package/dist/effect/Otel/lib-tracer/WebProvider.d.ts +0 -18
- package/dist/effect/Otel/lib-tracer/WebProvider.d.ts.map +0 -1
- package/dist/effect/Otel/lib-tracer/WebProvider.js +0 -25
- package/dist/effect/Otel/lib-tracer/WebProvider.js.map +0 -1
- package/dist/effect/ReadonlyArray.d.ts +0 -4
- package/dist/effect/ReadonlyArray.d.ts.map +0 -1
- package/dist/effect/ReadonlyArray.js +0 -11
- package/dist/effect/ReadonlyArray.js.map +0 -1
- package/dist/effect/RequestResolver.d.ts +0 -11
- package/dist/effect/RequestResolver.d.ts.map +0 -1
- package/dist/effect/RequestResolver.js +0 -18
- package/dist/effect/RequestResolver.js.map +0 -1
- package/dist/effect/STM.d.ts +0 -3
- package/dist/effect/STM.d.ts.map +0 -1
- package/dist/effect/STM.js +0 -3
- package/dist/effect/STM.js.map +0 -1
- package/dist/effect/Scheduler.d.ts +0 -49
- package/dist/effect/Scheduler.d.ts.map +0 -1
- package/dist/effect/Scheduler.js +0 -168
- package/dist/effect/Scheduler.js.map +0 -1
- package/dist/effect/Schema/SchemaHash.d.ts +0 -3
- package/dist/effect/Schema/SchemaHash.d.ts.map +0 -1
- package/dist/effect/Schema/SchemaHash.js +0 -15
- package/dist/effect/Schema/SchemaHash.js.map +0 -1
- package/dist/effect/Schema/SchemaHash.test.d.ts +0 -2
- package/dist/effect/Schema/SchemaHash.test.d.ts.map +0 -1
- package/dist/effect/Schema/SchemaHash.test.js +0 -13
- package/dist/effect/Schema/SchemaHash.test.js.map +0 -1
- package/dist/effect/Schema/SchemaJsonWrapper.d.ts +0 -11
- package/dist/effect/Schema/SchemaJsonWrapper.d.ts.map +0 -1
- package/dist/effect/Schema/SchemaJsonWrapper.js +0 -38
- package/dist/effect/Schema/SchemaJsonWrapper.js.map +0 -1
- package/dist/effect/Schema/SchemaJsonWrapper.test.d.ts +0 -2
- package/dist/effect/Schema/SchemaJsonWrapper.test.d.ts.map +0 -1
- package/dist/effect/Schema/SchemaJsonWrapper.test.js +0 -42
- package/dist/effect/Schema/SchemaJsonWrapper.test.js.map +0 -1
- package/dist/effect/Schema/index.d.ts +0 -15
- package/dist/effect/Schema/index.d.ts.map +0 -1
- package/dist/effect/Schema/index.js +0 -14
- package/dist/effect/Schema/index.js.map +0 -1
- package/dist/effect/SmartQueue.d.ts +0 -38
- package/dist/effect/SmartQueue.d.ts.map +0 -1
- package/dist/effect/SmartQueue.js +0 -123
- package/dist/effect/SmartQueue.js.map +0 -1
- package/dist/effect/Stream/chainSwitch.d.ts +0 -3
- package/dist/effect/Stream/chainSwitch.d.ts.map +0 -1
- package/dist/effect/Stream/chainSwitch.js +0 -48
- package/dist/effect/Stream/chainSwitch.js.map +0 -1
- package/dist/effect/Stream/index.d.ts +0 -37
- package/dist/effect/Stream/index.d.ts.map +0 -1
- package/dist/effect/Stream/index.js +0 -82
- package/dist/effect/Stream/index.js.map +0 -1
- package/dist/effect/SubscriptionRef.d.ts +0 -10
- package/dist/effect/SubscriptionRef.d.ts.map +0 -1
- package/dist/effect/SubscriptionRef.js +0 -8
- package/dist/effect/SubscriptionRef.js.map +0 -1
- package/dist/effect/TimeoutGate.d.ts +0 -13
- package/dist/effect/TimeoutGate.d.ts.map +0 -1
- package/dist/effect/TimeoutGate.js +0 -41
- package/dist/effect/TimeoutGate.js.map +0 -1
- package/dist/effect/WebCrypto.d.ts +0 -18
- package/dist/effect/WebCrypto.d.ts.map +0 -1
- package/dist/effect/WebCrypto.js +0 -56
- package/dist/effect/WebCrypto.js.map +0 -1
- package/dist/effect/WebLock.d.ts +0 -5
- package/dist/effect/WebLock.d.ts.map +0 -1
- package/dist/effect/WebLock.js +0 -20
- package/dist/effect/WebLock.js.map +0 -1
- package/dist/effect/browser.d.ts +0 -19
- package/dist/effect/browser.d.ts.map +0 -1
- package/dist/effect/browser.js +0 -82
- package/dist/effect/browser.js.map +0 -1
- package/dist/effect/fetch.d.ts +0 -89
- package/dist/effect/fetch.d.ts.map +0 -1
- package/dist/effect/fetch.js +0 -142
- package/dist/effect/fetch.js.map +0 -1
- package/dist/single-item.d.ts +0 -8
- package/dist/single-item.d.ts.map +0 -1
- package/dist/single-item.js +0 -9
- package/dist/single-item.js.map +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/json.d.ts +0 -27
- package/dist/types/json.d.ts.map +0 -1
- package/dist/types/json.js +0 -2
- package/dist/types/json.js.map +0 -1
- package/src/effect/Otel/Dummy.ts +0 -32
- package/src/effect/Otel/Meter.ts +0 -145
- package/src/effect/Otel/OtlpGrpc.ts +0 -75
- package/src/effect/Otel/OtlpHttp.ts +0 -75
- package/src/effect/Otel/OtlpWebsocket.ts +0 -75
- package/src/effect/Otel/Span.ts +0 -222
- package/src/effect/Otel/Tracer.ts +0 -30
- package/src/effect/Otel/index.ts +0 -8
- package/src/effect/Otel/lib-metrics/ExporterMetricsOltpGrpc.ts +0 -39
- package/src/effect/Otel/lib-metrics/ExporterMetricsOltpHttp.ts +0 -39
- package/src/effect/Otel/lib-metrics/ExporterMetricsOltpWebsocket.ts +0 -47
- package/src/effect/Otel/lib-metrics/MetricsProvider.ts +0 -12
- package/src/effect/Otel/lib-metrics/OTLPMetricsProviderGrpc.ts +0 -77
- package/src/effect/Otel/lib-metrics/OTLPMetricsProviderHttp.ts +0 -77
- package/src/effect/Otel/lib-metrics/OTLPMetricsProviderWebsocket.ts +0 -80
- package/src/effect/Otel/lib-metrics/PeriodicMetricsProvider.ts +0 -55
- package/src/effect/Otel/lib-tracer/BatchSpanProcessor.ts +0 -58
- package/src/effect/Otel/lib-tracer/ExporterTraceOtlpGrpc.ts +0 -64
- package/src/effect/Otel/lib-tracer/ExporterTraceOtlpHttp.ts +0 -64
- package/src/effect/Otel/lib-tracer/ExporterTraceOtlpWebsocket.ts +0 -38
- package/src/effect/Otel/lib-tracer/README.md +0 -1
- package/src/effect/Otel/lib-tracer/SimpleProcessor.ts +0 -46
- package/src/effect/Otel/lib-tracer/TracerProvider.ts +0 -16
- package/src/effect/Otel/lib-tracer/WebProvider.ts +0 -48
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as Layer from '@effect/io/Layer'
|
|
2
|
-
import type { ResourceAttributes } from '@opentelemetry/resources'
|
|
3
|
-
import { Resource } from '@opentelemetry/resources'
|
|
4
|
-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
|
|
5
|
-
|
|
6
|
-
import * as Otel from './index.js'
|
|
7
|
-
import { makeOTLPMetricExporterConfigLayer } from './lib-metrics/ExporterMetricsOltpHttp.js'
|
|
8
|
-
import { OTLPMetricsProvider } from './lib-metrics/OTLPMetricsProviderHttp.js'
|
|
9
|
-
import { BatchProcessor } from './lib-tracer/BatchSpanProcessor.js'
|
|
10
|
-
import * as HttpExporter from './lib-tracer/ExporterTraceOtlpHttp.js'
|
|
11
|
-
import * as OTWeb from './lib-tracer/WebProvider.js'
|
|
12
|
-
import { LiveMeter } from './Meter.js'
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
// TRACING
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
const makeWebTracingProvider = (serviceName: string, resourceAttributes?: ResourceAttributes) =>
|
|
19
|
-
OTWeb.WebProvider({
|
|
20
|
-
resource: new Resource({
|
|
21
|
-
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
22
|
-
...resourceAttributes,
|
|
23
|
-
}),
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const TraceCollectorConfig = (exporterUrl?: string) =>
|
|
27
|
-
HttpExporter.makeOTLPTraceExporterConfigLayer({
|
|
28
|
-
// empty headers makes sure to use XHR instead of `navigator.sendBeacon`
|
|
29
|
-
headers: {},
|
|
30
|
-
url: exporterUrl,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const LiveBatchHttpProcessor = BatchProcessor(HttpExporter.makeTracingSpanExporter)
|
|
34
|
-
|
|
35
|
-
export const makeWebTracingLayer = (
|
|
36
|
-
serviceName: string,
|
|
37
|
-
exporterUrl?: string,
|
|
38
|
-
resourceAttributes?: ResourceAttributes,
|
|
39
|
-
): Layer.Layer<never, never, Otel.Tracer> =>
|
|
40
|
-
Layer.provideMerge(
|
|
41
|
-
TraceCollectorConfig(exporterUrl),
|
|
42
|
-
Layer.provide(
|
|
43
|
-
Layer.provideMerge(makeWebTracingProvider(serviceName, resourceAttributes), LiveBatchHttpProcessor),
|
|
44
|
-
Otel.LiveTracer,
|
|
45
|
-
),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
// METRICS
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
const makeWebMetricProvider = (serviceName: string, resourceAttributes?: ResourceAttributes) =>
|
|
53
|
-
OTLPMetricsProvider({
|
|
54
|
-
resource: new Resource({
|
|
55
|
-
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
56
|
-
...resourceAttributes,
|
|
57
|
-
}),
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const MetricCollectorConfig = (exporterUrl?: string) =>
|
|
61
|
-
makeOTLPMetricExporterConfigLayer({
|
|
62
|
-
// empty headers makes sure to use XHR instead of `navigator.sendBeacon`
|
|
63
|
-
headers: {},
|
|
64
|
-
url: exporterUrl,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
export const makeWebMetricLayer = (
|
|
68
|
-
serviceName: string,
|
|
69
|
-
exporterUrl?: string,
|
|
70
|
-
resourceAttributes?: ResourceAttributes,
|
|
71
|
-
): Layer.Layer<never, never, Otel.Meter> =>
|
|
72
|
-
Layer.provide(
|
|
73
|
-
Layer.provideMerge(MetricCollectorConfig(exporterUrl), makeWebMetricProvider(serviceName, resourceAttributes)),
|
|
74
|
-
LiveMeter,
|
|
75
|
-
)
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as Layer from '@effect/io/Layer'
|
|
2
|
-
import type { ResourceAttributes } from '@opentelemetry/resources'
|
|
3
|
-
import { Resource } from '@opentelemetry/resources'
|
|
4
|
-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
|
|
5
|
-
|
|
6
|
-
import * as Otel from './index.js'
|
|
7
|
-
import { makeOTLPMetricExporterConfigLayer } from './lib-metrics/ExporterMetricsOltpWebsocket.js'
|
|
8
|
-
import { OTLPMetricsProvider } from './lib-metrics/OTLPMetricsProviderWebsocket.js'
|
|
9
|
-
import { BatchProcessor } from './lib-tracer/BatchSpanProcessor.js'
|
|
10
|
-
import * as WebSocketExporter from './lib-tracer/ExporterTraceOtlpWebsocket.js'
|
|
11
|
-
import * as OTWeb from './lib-tracer/WebProvider.js'
|
|
12
|
-
import { LiveMeter } from './Meter.js'
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
// TRACING
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
const makeWebTracingProvider = (serviceName: string, resourceAttributes?: ResourceAttributes) =>
|
|
19
|
-
OTWeb.WebProvider({
|
|
20
|
-
resource: new Resource({
|
|
21
|
-
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
22
|
-
...resourceAttributes,
|
|
23
|
-
}),
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const TraceCollectorConfig = (exporterUrl?: string) =>
|
|
27
|
-
WebSocketExporter.makeOTLPTraceExporterConfigLayer({
|
|
28
|
-
// empty headers makes sure to use XHR instead of `navigator.sendBeacon`
|
|
29
|
-
headers: {},
|
|
30
|
-
url: exporterUrl,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const LiveBatchWebsocketProcessor = BatchProcessor(WebSocketExporter.makeTracingSpanExporter)
|
|
34
|
-
|
|
35
|
-
export const makeWebTracingLayer = (
|
|
36
|
-
serviceName: string,
|
|
37
|
-
exporterUrl?: string,
|
|
38
|
-
resourceAttributes?: ResourceAttributes,
|
|
39
|
-
): Layer.Layer<never, never, Otel.Tracer> =>
|
|
40
|
-
Layer.provideMerge(
|
|
41
|
-
TraceCollectorConfig(exporterUrl),
|
|
42
|
-
Layer.provide(
|
|
43
|
-
Layer.provideMerge(makeWebTracingProvider(serviceName, resourceAttributes), LiveBatchWebsocketProcessor),
|
|
44
|
-
Otel.LiveTracer,
|
|
45
|
-
),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
// METRICS
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
const makeWebMetricProvider = (serviceName: string, resourceAttributes?: ResourceAttributes) =>
|
|
53
|
-
OTLPMetricsProvider({
|
|
54
|
-
resource: new Resource({
|
|
55
|
-
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
56
|
-
...resourceAttributes,
|
|
57
|
-
}),
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const MetricCollectorConfig = (exporterUrl?: string) =>
|
|
61
|
-
makeOTLPMetricExporterConfigLayer({
|
|
62
|
-
// empty headers makes sure to use XHR instead of `navigator.sendBeacon`
|
|
63
|
-
headers: {},
|
|
64
|
-
url: exporterUrl,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
export const makeWebMetricLayer = (
|
|
68
|
-
serviceName: string,
|
|
69
|
-
exporterUrl?: string,
|
|
70
|
-
resourceAttributes?: ResourceAttributes,
|
|
71
|
-
): Layer.Layer<never, never, Otel.Meter> =>
|
|
72
|
-
Layer.provide(
|
|
73
|
-
Layer.provideMerge(MetricCollectorConfig(exporterUrl), makeWebMetricProvider(serviceName, resourceAttributes)),
|
|
74
|
-
LiveMeter,
|
|
75
|
-
)
|
package/src/effect/Otel/Span.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { pipe } from '@effect/data/Function'
|
|
3
|
-
import * as Option from '@effect/data/Option'
|
|
4
|
-
import * as Cause from '@effect/io/Cause'
|
|
5
|
-
import * as Effect from '@effect/io/Effect'
|
|
6
|
-
import * as Exit from '@effect/io/Exit'
|
|
7
|
-
import * as Layer from '@effect/io/Layer'
|
|
8
|
-
import * as Stream from '@effect/stream/Stream'
|
|
9
|
-
import * as otel from '@opentelemetry/api'
|
|
10
|
-
|
|
11
|
-
import { Tracer } from './Tracer.js'
|
|
12
|
-
|
|
13
|
-
export const SpanSymbol = Symbol.for('effect-otel/Span')
|
|
14
|
-
export type SpanSymbol = typeof SpanSymbol
|
|
15
|
-
|
|
16
|
-
// TODO refactor to use 2nd `Context.Tag` type generic instead of symbol
|
|
17
|
-
export interface Span {
|
|
18
|
-
readonly [SpanSymbol]: SpanSymbol
|
|
19
|
-
readonly span: otel.Span
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const Span = Context.Tag<Span>(SpanSymbol)
|
|
23
|
-
|
|
24
|
-
export const makeSpan = (span: otel.Span): Span => ({
|
|
25
|
-
[SpanSymbol]: SpanSymbol,
|
|
26
|
-
span,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
export const requireParentSpan = <R, E, A>(effect: Effect.Effect<R, E, A>): Effect.Effect<R | Span, E, A> => effect
|
|
30
|
-
|
|
31
|
-
export const activeSpanContext: Effect.Effect<Span, never, otel.SpanContext> = Effect.map(Span, (_) =>
|
|
32
|
-
_.span.spanContext(),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
export const activeContext: Effect.Effect<Span, never, otel.Context> = Effect.flatMap(Span, (_) =>
|
|
36
|
-
Effect.sync(() => otel.trace.setSpan(otel.context.active(), _.span)),
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
// TODO get rid of this
|
|
40
|
-
const inProgressSpans = new Set<otel.Span>()
|
|
41
|
-
// @ts-expect-error `inProgressSpans` is not a global variable
|
|
42
|
-
globalThis.inProgressSpans = inProgressSpans
|
|
43
|
-
|
|
44
|
-
// TODO get rid of this
|
|
45
|
-
export const endInProgressSpans = Effect.sync(() => {
|
|
46
|
-
inProgressSpans.forEach((span) => span.end())
|
|
47
|
-
inProgressSpans.clear()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const startSpan = (
|
|
51
|
-
tracer: otel.Tracer,
|
|
52
|
-
context: Context.Context<never>,
|
|
53
|
-
name: string,
|
|
54
|
-
options: otel.SpanOptions | undefined,
|
|
55
|
-
ctx: otel.Context | undefined,
|
|
56
|
-
): otel.Span => {
|
|
57
|
-
let span: otel.Span
|
|
58
|
-
const maybeSpan = Context.getOption(context, Span)
|
|
59
|
-
if (ctx !== undefined) {
|
|
60
|
-
span = tracer.startSpan(name, options, ctx)
|
|
61
|
-
} else if (options?.root !== true && Option.isSome(maybeSpan)) {
|
|
62
|
-
const ctx = otel.trace.setSpan(otel.context.active(), maybeSpan.value.span)
|
|
63
|
-
span = tracer.startSpan(name, options, ctx)
|
|
64
|
-
} else {
|
|
65
|
-
span = tracer.startSpan(name, { ...options, root: true })
|
|
66
|
-
}
|
|
67
|
-
inProgressSpans.add(span)
|
|
68
|
-
return span
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const handleExit = <E, A>(span: otel.Span, exit: Exit.Exit<E, A>) =>
|
|
72
|
-
Effect.sync(() => {
|
|
73
|
-
if (Exit.isFailure(exit)) {
|
|
74
|
-
if (Cause.isInterruptedOnly(exit.cause)) {
|
|
75
|
-
// TODO in the future set a special status code for interruption (once Otel supports it)
|
|
76
|
-
span.setStatus({ code: otel.SpanStatusCode.OK, message: Cause.pretty(exit.cause) })
|
|
77
|
-
// NOTE as a workaround we're using the `span.label` attribute which is visible in Grafana
|
|
78
|
-
// See https://github.com/grafana/grafana/pull/50931
|
|
79
|
-
span.setAttribute('span.label', '⚠️ Interrupted️')
|
|
80
|
-
} else {
|
|
81
|
-
span.setStatus({ code: otel.SpanStatusCode.ERROR, message: Cause.pretty(exit.cause) })
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
span.setStatus({ code: otel.SpanStatusCode.OK })
|
|
85
|
-
}
|
|
86
|
-
inProgressSpans.delete(span)
|
|
87
|
-
span.end()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
export const withSpan =
|
|
91
|
-
(name: string, options?: otel.SpanOptions, ctx?: otel.Context) =>
|
|
92
|
-
<R, E, A>(effect: Effect.Effect<R, E, A>): Effect.Effect<Exclude<R, Span> | Tracer, E, A> =>
|
|
93
|
-
Effect.flatMap(Tracer, (tracer) =>
|
|
94
|
-
Effect.acquireUseRelease(
|
|
95
|
-
Effect.flatMap(Effect.context<never>(), (context) =>
|
|
96
|
-
Effect.sync(() => startSpan(tracer.tracer, context, name, options, ctx)),
|
|
97
|
-
),
|
|
98
|
-
(span) => Effect.provideService(effect, Span, makeSpan(span)),
|
|
99
|
-
handleExit,
|
|
100
|
-
),
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
export const withSpanScoped =
|
|
104
|
-
(name: string, options?: otel.SpanOptions, ctx?: otel.Context) =>
|
|
105
|
-
<R, E, A>(effect: Effect.Effect<R, E, A>) =>
|
|
106
|
-
Effect.flatMap(Tracer, (tracer) => {
|
|
107
|
-
const createSpan = Effect.acquireRelease(
|
|
108
|
-
Effect.flatMap(Effect.context<never>(), (context) =>
|
|
109
|
-
Effect.sync(() => startSpan(tracer.tracer, context, name, options, ctx)),
|
|
110
|
-
),
|
|
111
|
-
handleExit,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
return Effect.flatMap(createSpan, (span) => Effect.provideService(effect, Span, makeSpan(span)))
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
export const withSpanStream =
|
|
118
|
-
(name: string, options?: otel.SpanOptions, ctx?: otel.Context) =>
|
|
119
|
-
<R, E, A>(stream: Stream.Stream<R | Span, E, A>): Stream.Stream<Exclude<R, Span> | Tracer, E, A> =>
|
|
120
|
-
Stream.unwrapScoped(
|
|
121
|
-
Effect.flatMap(Tracer, (tracer) =>
|
|
122
|
-
pipe(
|
|
123
|
-
Effect.acquireRelease(
|
|
124
|
-
Effect.flatMap(Effect.context<never>(), (context) =>
|
|
125
|
-
Effect.sync(() => startSpan(tracer.tracer, context, name, options, ctx)),
|
|
126
|
-
),
|
|
127
|
-
handleExit,
|
|
128
|
-
),
|
|
129
|
-
Effect.map((span) => Stream.provideService(stream, Span, makeSpan(span))),
|
|
130
|
-
),
|
|
131
|
-
),
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
// TODO add optional arg for `Tag` of `Span`
|
|
135
|
-
export const spanLayer: {
|
|
136
|
-
(
|
|
137
|
-
name: string,
|
|
138
|
-
options?: otel.SpanOptions,
|
|
139
|
-
ctx?: otel.Context,
|
|
140
|
-
afterEnded?: (span: otel.Span) => Effect.Effect<never, never, void>,
|
|
141
|
-
): Layer.Layer<Tracer, never, Span>
|
|
142
|
-
<TIdentifier>(
|
|
143
|
-
name: string,
|
|
144
|
-
options: otel.SpanOptions | undefined,
|
|
145
|
-
ctx: otel.Context | undefined,
|
|
146
|
-
afterEnded: ((span: otel.Span) => Effect.Effect<never, never, void>) | undefined,
|
|
147
|
-
tag: Context.Tag<TIdentifier, Span>,
|
|
148
|
-
): Layer.Layer<Tracer, never, TIdentifier>
|
|
149
|
-
} = <TIdentifier>(
|
|
150
|
-
name: string,
|
|
151
|
-
options?: otel.SpanOptions,
|
|
152
|
-
ctx?: otel.Context,
|
|
153
|
-
afterEnded?: (span: otel.Span) => Effect.Effect<never, never, void>,
|
|
154
|
-
tag?: Context.Tag<TIdentifier, Span>,
|
|
155
|
-
): Layer.Layer<Tracer, never, TIdentifier> =>
|
|
156
|
-
Layer.flatMap(Layer.context<Tracer>(), (context) =>
|
|
157
|
-
Layer.scoped(
|
|
158
|
-
tag ?? Span,
|
|
159
|
-
pipe(
|
|
160
|
-
Effect.sync(() => {
|
|
161
|
-
const tracer = Context.get(context, Tracer)
|
|
162
|
-
return startSpan(tracer.tracer, context, name, options, ctx)
|
|
163
|
-
}),
|
|
164
|
-
Effect.map(makeSpan),
|
|
165
|
-
Effect.acquireRelease(({ span }, exit) =>
|
|
166
|
-
pipe(
|
|
167
|
-
handleExit(span, exit),
|
|
168
|
-
Effect.tap(() => {
|
|
169
|
-
if (afterEnded !== undefined) {
|
|
170
|
-
return afterEnded(span)
|
|
171
|
-
}
|
|
172
|
-
return Effect.unit
|
|
173
|
-
}),
|
|
174
|
-
),
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
),
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
export const spanLayerFromContext = (parentSpanCtx: otel.Context) => {
|
|
181
|
-
// const _spanId = otel.trace.getSpan(parentSpanCtx)!.spanContext().spanId
|
|
182
|
-
return Layer.succeed(Span, makeSpan(otel.trace.getSpan(parentSpanCtx)!))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export const withSpanLayer =
|
|
186
|
-
(name: string, options?: otel.SpanOptions, ctx?: otel.Context) =>
|
|
187
|
-
<R, E, A>(layer: Layer.Layer<R | Span, E, A>): Layer.Layer<Tracer | Exclude<R, Span>, E, A> =>
|
|
188
|
-
Layer.provide(spanLayer(name, options, ctx), layer)
|
|
189
|
-
|
|
190
|
-
export const addAttribute = (name: string, value: otel.AttributeValue) =>
|
|
191
|
-
Effect.flatMap(Span, ({ span }) =>
|
|
192
|
-
Effect.sync(() => {
|
|
193
|
-
span.setAttribute(name, value)
|
|
194
|
-
}),
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
export const addAttributes = (attributes: otel.Attributes) =>
|
|
198
|
-
Effect.flatMap(Span, ({ span }) =>
|
|
199
|
-
Effect.sync(() => {
|
|
200
|
-
span.setAttributes(attributes)
|
|
201
|
-
}),
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
export const addAttributesEffect = <R, E>(attributes: Effect.Effect<R, E, otel.Attributes>) =>
|
|
205
|
-
Effect.flatMap(attributes, (attributes) =>
|
|
206
|
-
Effect.flatMap(Span, ({ span }) =>
|
|
207
|
-
Effect.sync(() => {
|
|
208
|
-
span.setAttributes(attributes)
|
|
209
|
-
}),
|
|
210
|
-
),
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
export const addEvent = (
|
|
214
|
-
name: string,
|
|
215
|
-
attributesOrStartTime?: otel.SpanAttributes | otel.TimeInput,
|
|
216
|
-
startTime?: otel.TimeInput,
|
|
217
|
-
) =>
|
|
218
|
-
Effect.flatMap(Span, ({ span }) =>
|
|
219
|
-
Effect.sync(() => {
|
|
220
|
-
span.addEvent(name, attributesOrStartTime, startTime)
|
|
221
|
-
}),
|
|
222
|
-
)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { identity } from '@effect/data/Function'
|
|
3
|
-
import * as Effect from '@effect/io/Effect'
|
|
4
|
-
import * as Layer from '@effect/io/Layer'
|
|
5
|
-
import type * as otel from '@opentelemetry/api'
|
|
6
|
-
|
|
7
|
-
import { TracerProvider } from './lib-tracer/TracerProvider.js'
|
|
8
|
-
|
|
9
|
-
export const TracerSymbol = Symbol.for('effect-otel/Tracer')
|
|
10
|
-
export type TracerSymbol = typeof TracerSymbol
|
|
11
|
-
|
|
12
|
-
export interface Tracer {
|
|
13
|
-
readonly [TracerSymbol]: TracerSymbol
|
|
14
|
-
readonly tracer: otel.Tracer
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Tracer = Context.Tag<Tracer>(TracerSymbol)
|
|
18
|
-
|
|
19
|
-
export const makeTracer = (name: string) =>
|
|
20
|
-
Effect.gen(function* ($) {
|
|
21
|
-
const { tracerProvider } = yield* $(TracerProvider)
|
|
22
|
-
const tracer = yield* $(Effect.sync(() => tracerProvider.getTracer(name)))
|
|
23
|
-
|
|
24
|
-
return identity<Tracer>({
|
|
25
|
-
[TracerSymbol]: TracerSymbol,
|
|
26
|
-
tracer,
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export const LiveTracer = Layer.scoped(Tracer, makeTracer('@effect/otel/Tracer'))
|
package/src/effect/Otel/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// otel
|
|
2
|
-
export * from './Meter.js'
|
|
3
|
-
export * from './Tracer.js'
|
|
4
|
-
export * from './Span.js'
|
|
5
|
-
export * from './Dummy.js'
|
|
6
|
-
export * from './lib-tracer/BatchSpanProcessor.js'
|
|
7
|
-
export * from './lib-metrics/MetricsProvider.js'
|
|
8
|
-
export * as OTWeb from './lib-tracer/WebProvider.js'
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { pipe } from '@effect/data/Function'
|
|
3
|
-
import * as Effect from '@effect/io/Effect'
|
|
4
|
-
import * as Layer from '@effect/io/Layer'
|
|
5
|
-
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'
|
|
6
|
-
import type { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'
|
|
7
|
-
|
|
8
|
-
import { PeriodicMetricsProvider } from './PeriodicMetricsProvider.js'
|
|
9
|
-
|
|
10
|
-
export interface OTLPMetricExporterConfig {
|
|
11
|
-
readonly _: unique symbol
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const OTLPMetricExporterConfig = Context.Tag<OTLPMetricExporterConfig, OTLPExporterNodeConfigBase>(
|
|
15
|
-
'otel-metric-exporter-config',
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export const makeOTLPMetricExporterConfigLayer = (config: OTLPExporterNodeConfigBase) =>
|
|
19
|
-
Layer.succeed(OTLPMetricExporterConfig, config)
|
|
20
|
-
|
|
21
|
-
export const makeMetricExporter = Effect.gen(function* (_) {
|
|
22
|
-
const config = yield* _(OTLPMetricExporterConfig)
|
|
23
|
-
|
|
24
|
-
const metricExporter = yield* _(
|
|
25
|
-
pipe(
|
|
26
|
-
Effect.sync(() => new OTLPMetricExporter(config)),
|
|
27
|
-
Effect.acquireRelease((p) =>
|
|
28
|
-
pipe(
|
|
29
|
-
Effect.tryPromise(() => p.shutdown()),
|
|
30
|
-
Effect.orDie,
|
|
31
|
-
),
|
|
32
|
-
),
|
|
33
|
-
),
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
return metricExporter
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export const LivePeriodicMetricsProvider = PeriodicMetricsProvider(makeMetricExporter)
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { pipe } from '@effect/data/Function'
|
|
3
|
-
import * as Effect from '@effect/io/Effect'
|
|
4
|
-
import * as Layer from '@effect/io/Layer'
|
|
5
|
-
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
|
|
6
|
-
import type { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'
|
|
7
|
-
|
|
8
|
-
import { PeriodicMetricsProvider } from './PeriodicMetricsProvider.js'
|
|
9
|
-
|
|
10
|
-
export interface OTLPMetricExporterConfig {
|
|
11
|
-
readonly _: unique symbol
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const OTLPMetricExporterConfig = Context.Tag<OTLPMetricExporterConfig, OTLPExporterNodeConfigBase>(
|
|
15
|
-
'otel-metric-exporter-config',
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export const makeOTLPMetricExporterConfigLayer = (config: OTLPExporterNodeConfigBase) =>
|
|
19
|
-
Layer.succeed(OTLPMetricExporterConfig, config)
|
|
20
|
-
|
|
21
|
-
export const makeMetricExporter = Effect.gen(function* (_) {
|
|
22
|
-
const config = yield* _(OTLPMetricExporterConfig)
|
|
23
|
-
|
|
24
|
-
const metricExporter = yield* _(
|
|
25
|
-
pipe(
|
|
26
|
-
Effect.sync(() => new OTLPMetricExporter(config)),
|
|
27
|
-
Effect.acquireRelease((p) =>
|
|
28
|
-
pipe(
|
|
29
|
-
Effect.tryPromise(() => p.shutdown()),
|
|
30
|
-
Effect.orDie,
|
|
31
|
-
),
|
|
32
|
-
),
|
|
33
|
-
),
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
return metricExporter
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export const LivePeriodicMetricsProvider = PeriodicMetricsProvider(makeMetricExporter)
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { pipe } from '@effect/data/Function'
|
|
3
|
-
import * as Effect from '@effect/io/Effect'
|
|
4
|
-
import * as Layer from '@effect/io/Layer'
|
|
5
|
-
import type { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'
|
|
6
|
-
import { WebsocketMetricExporter } from 'otel-websocket-exporter'
|
|
7
|
-
|
|
8
|
-
import { PeriodicMetricsProvider } from './PeriodicMetricsProvider.js'
|
|
9
|
-
|
|
10
|
-
export const OTLPMetricExporterConfigSymbol = Symbol.for('otel-metric-exporter-config')
|
|
11
|
-
type OTLPMetricExporterConfigSymbol = typeof OTLPMetricExporterConfigSymbol
|
|
12
|
-
|
|
13
|
-
export interface OTLPMetricExporterConfig {
|
|
14
|
-
readonly [OTLPMetricExporterConfigSymbol]: OTLPMetricExporterConfigSymbol
|
|
15
|
-
readonly config: OTLPExporterNodeConfigBase
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const OTLPMetricExporterConfig = Context.Tag<OTLPMetricExporterConfig>(OTLPMetricExporterConfigSymbol)
|
|
19
|
-
|
|
20
|
-
export const makeOTLPMetricExporterConfigLayer = (config: OTLPExporterNodeConfigBase) =>
|
|
21
|
-
Layer.succeed(OTLPMetricExporterConfig, { [OTLPMetricExporterConfigSymbol]: OTLPMetricExporterConfigSymbol, config })
|
|
22
|
-
|
|
23
|
-
export const makeOTLPMetricExporterConfigLayerM = <R, E>(configEff: Effect.Effect<R, E, OTLPExporterNodeConfigBase>) =>
|
|
24
|
-
Layer.effect(
|
|
25
|
-
OTLPMetricExporterConfig,
|
|
26
|
-
Effect.map(
|
|
27
|
-
configEff,
|
|
28
|
-
(config) => ({ [OTLPMetricExporterConfigSymbol]: OTLPMetricExporterConfigSymbol, config }) as const,
|
|
29
|
-
),
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
export const makeMetricExporter = Effect.gen(function* (_) {
|
|
33
|
-
const { config } = yield* _(OTLPMetricExporterConfig)
|
|
34
|
-
|
|
35
|
-
const metricExporter = yield* _(
|
|
36
|
-
Effect.acquireRelease(Effect.succeed(new WebsocketMetricExporter(config)), (p) =>
|
|
37
|
-
pipe(
|
|
38
|
-
Effect.tryPromise(() => p.shutdown()),
|
|
39
|
-
Effect.orDie,
|
|
40
|
-
),
|
|
41
|
-
),
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return metricExporter
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
export const LivePeriodicMetricsProvider = PeriodicMetricsProvider(makeMetricExporter)
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import type { MeterProvider } from '@opentelemetry/sdk-metrics'
|
|
3
|
-
|
|
4
|
-
export const MeterProviderSymbol = Symbol.for('effect-otel/MetricsProvider')
|
|
5
|
-
export type MeterProviderSymbol = typeof MeterProviderSymbol
|
|
6
|
-
|
|
7
|
-
export interface MetricsProvider {
|
|
8
|
-
readonly [MeterProviderSymbol]: MeterProviderSymbol
|
|
9
|
-
readonly metricsProvider: MeterProvider
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const MetricsProvider = Context.Tag<MetricsProvider>(MeterProviderSymbol)
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import * as Context from '@effect/data/Context'
|
|
2
|
-
import { identity, pipe } from '@effect/data/Function'
|
|
3
|
-
import * as Option from '@effect/data/Option'
|
|
4
|
-
import * as Effect from '@effect/io/Effect'
|
|
5
|
-
import * as Layer from '@effect/io/Layer'
|
|
6
|
-
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'
|
|
7
|
-
import type { MeterProviderOptions } from '@opentelemetry/sdk-metrics'
|
|
8
|
-
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
|
|
9
|
-
|
|
10
|
-
import { OTLPMetricExporterConfig } from './ExporterMetricsOltpGrpc.js'
|
|
11
|
-
import { MeterProviderSymbol, MetricsProvider } from './MetricsProvider.js'
|
|
12
|
-
|
|
13
|
-
export const OTLPMetricsProviderConfigSymbol = Symbol.for('effect-otel/OTLPMetricsProviderConfig')
|
|
14
|
-
|
|
15
|
-
export interface OTLPMetricsProviderConfig {
|
|
16
|
-
readonly options: MeterProviderOptions
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const OTLPMetricsProviderConfig = Context.Tag<OTLPMetricsProviderConfig>(OTLPMetricsProviderConfigSymbol)
|
|
20
|
-
|
|
21
|
-
export const LiveOTLPMetricsProviderConfig = (options: MeterProviderOptions) =>
|
|
22
|
-
Layer.succeed(OTLPMetricsProviderConfig, { options })
|
|
23
|
-
|
|
24
|
-
export const makeOTLPMetricsProvider = Effect.gen(function* ($) {
|
|
25
|
-
const ctx = yield* $(Effect.context<never>())
|
|
26
|
-
|
|
27
|
-
const options = pipe(
|
|
28
|
-
Context.getOption(ctx, OTLPMetricsProviderConfig),
|
|
29
|
-
Option.map((_) => _.options),
|
|
30
|
-
Option.getOrUndefined,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
const metricsProvider = yield* $(Effect.sync(() => new MeterProvider(options)))
|
|
34
|
-
|
|
35
|
-
// TODO remove below
|
|
36
|
-
|
|
37
|
-
// const metricsExporter = yield* _(exporter)
|
|
38
|
-
const config = yield* $(OTLPMetricExporterConfig)
|
|
39
|
-
|
|
40
|
-
const metricExporter = yield* $(
|
|
41
|
-
Effect.sync(() => new OTLPMetricExporter(config)),
|
|
42
|
-
// TODO re-enable
|
|
43
|
-
Effect.acquireRelease((_p) =>
|
|
44
|
-
pipe(
|
|
45
|
-
// Effect.tryPromise(() => p.shutdown()),
|
|
46
|
-
Effect.unit, // TODO without this I'm seeing a "`config` of undefined" bug
|
|
47
|
-
Effect.orDie,
|
|
48
|
-
),
|
|
49
|
-
),
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
const metricReader = yield* $(
|
|
53
|
-
Effect.sync(
|
|
54
|
-
() =>
|
|
55
|
-
new PeriodicExportingMetricReader({
|
|
56
|
-
exporter: metricExporter,
|
|
57
|
-
exportIntervalMillis: 1000, // TODO make configurable
|
|
58
|
-
}),
|
|
59
|
-
),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
yield* $(Effect.sync(() => metricsProvider.addMetricReader(metricReader)))
|
|
63
|
-
|
|
64
|
-
// TODO remove above
|
|
65
|
-
|
|
66
|
-
return identity<MetricsProvider>({
|
|
67
|
-
[MeterProviderSymbol]: MeterProviderSymbol,
|
|
68
|
-
metricsProvider,
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
export const OTLPMetricsProviderLayer = Layer.scoped(MetricsProvider, makeOTLPMetricsProvider)
|
|
73
|
-
|
|
74
|
-
export const OTLPMetricsProvider = (
|
|
75
|
-
config?: MeterProviderOptions,
|
|
76
|
-
): Layer.Layer<OTLPMetricExporterConfig, never, MetricsProvider> =>
|
|
77
|
-
config ? Layer.provide(LiveOTLPMetricsProviderConfig(config), OTLPMetricsProviderLayer) : OTLPMetricsProviderLayer
|