@krak-stack/registry 0.1.50 → 0.1.52
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/CHANGELOG.md +34 -0
- package/README.md +16 -424
- package/dist/components/ui/data-table.d.ts +20 -1
- package/dist/components/ui/data-table.js +52 -1
- package/dist/lib/docs.js +2 -2
- package/dist/services/agent/client/index.js +1 -1
- package/dist/services/events/browser.d.ts +26 -0
- package/dist/services/events/browser.js +579 -0
- package/dist/services/events/client/audit-log-table.d.ts +53 -0
- package/dist/services/events/client/audit-log-table.js +3655 -0
- package/dist/services/events/index.d.ts +215 -0
- package/dist/services/events/index.js +1046 -0
- package/dist/services/events/migrations.d.ts +4 -0
- package/dist/services/events/migrations.js +42 -0
- package/dist/services/events/record.d.ts +3 -0
- package/dist/services/events/record.js +14 -0
- package/dist/services/events/request-context.d.ts +6 -0
- package/dist/services/events/schema.d.ts +237 -0
- package/dist/services/events/schema.js +361 -0
- package/dist/services/opentelemetry/api.d.ts +3 -1
- package/dist/services/opentelemetry/api.js +133 -64
- package/dist/services/opentelemetry/browser.d.ts +17 -20
- package/dist/services/opentelemetry/browser.js +58 -162
- package/dist/services/opentelemetry/events.d.ts +3 -1
- package/dist/services/opentelemetry/{server.d.ts → index.d.ts} +8 -5
- package/dist/services/opentelemetry/{server.js → index.js} +66 -48
- package/dist/services/opentelemetry/processor.d.ts +19 -0
- package/dist/services/opentelemetry/schema.d.ts +8 -20
- package/dist/services/opentelemetry/web-vitals.d.ts +15 -0
- package/dist/services/opentelemetry/web-vitals.js +229 -0
- package/package.json +35 -5
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Effect, Layer, Schema } from "effect";
|
|
2
|
-
import { OtlpExporter } from "effect/observability";
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { OtlpExporter, OtlpResource } from "effect/observability";
|
|
3
3
|
import { OtlpEvents } from "./events.js";
|
|
4
4
|
export type { EventAttributes, EventOptions } from "./schema.js";
|
|
5
|
+
declare const Otlp_base: Context.ServiceClass<Otlp, "krakstack/opentelemetry/Otlp", {
|
|
6
|
+
readonly resource: Effect.Effect<OtlpResource.Resource>;
|
|
7
|
+
}>;
|
|
5
8
|
/** Runtime-neutral server telemetry for HTTP applications, workers, and CLIs. */
|
|
6
|
-
export declare class
|
|
7
|
-
static readonly
|
|
9
|
+
export declare class Otlp extends Otlp_base {
|
|
10
|
+
static readonly event: (name: string, properties?: {
|
|
8
11
|
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
9
12
|
} | undefined, options?: {
|
|
10
13
|
readonly userId?: string | undefined;
|
|
@@ -16,5 +19,5 @@ export declare class ServerOtlp {
|
|
|
16
19
|
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
17
20
|
} | undefined;
|
|
18
21
|
} | undefined) => Effect.Effect<void, Schema.SchemaError, OtlpEvents>;
|
|
19
|
-
static readonly layer: Layer.Layer<OtlpExporter.Flusher | OtlpEvents, never, never>;
|
|
22
|
+
static readonly layer: Layer.Layer<OtlpExporter.Flusher | Otlp | OtlpEvents, never, never>;
|
|
20
23
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
// ../../src/services/opentelemetry/
|
|
2
|
-
import { Config, Effect as Effect2, Layer as Layer2, Schema as Schema3 } from "effect";
|
|
1
|
+
// ../../src/services/opentelemetry/index.ts
|
|
2
|
+
import { Config, Context as Context2, Effect as Effect2, Layer as Layer2, Schema as Schema3 } from "effect";
|
|
3
3
|
import { FetchHttpClient } from "effect/http";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Otlp as EffectOtlp,
|
|
6
|
+
OtlpExporter as OtlpExporter2,
|
|
7
|
+
OtlpResource as OtlpResource2,
|
|
8
|
+
OtlpSerialization as OtlpSerialization2
|
|
9
|
+
} from "effect/observability";
|
|
5
10
|
|
|
6
11
|
// ../../src/services/opentelemetry/events.ts
|
|
7
12
|
import {
|
|
@@ -22,6 +27,21 @@ import {
|
|
|
22
27
|
|
|
23
28
|
// ../../src/services/opentelemetry/schema.ts
|
|
24
29
|
import { Schema } from "effect";
|
|
30
|
+
var BrowserWebVital = Schema.Struct({
|
|
31
|
+
name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
|
|
32
|
+
id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
|
|
33
|
+
value: Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
34
|
+
delta: Schema.Finite,
|
|
35
|
+
rating: Schema.Literals(["good", "needs-improvement", "poor"]),
|
|
36
|
+
navigationType: Schema.Literals([
|
|
37
|
+
"navigate",
|
|
38
|
+
"reload",
|
|
39
|
+
"back-forward",
|
|
40
|
+
"back-forward-cache",
|
|
41
|
+
"prerender",
|
|
42
|
+
"restore"
|
|
43
|
+
])
|
|
44
|
+
}).annotate({ identifier: "BrowserWebVital" });
|
|
25
45
|
var EventAttributeValue = Schema.Union([
|
|
26
46
|
Schema.String,
|
|
27
47
|
Schema.Finite,
|
|
@@ -44,17 +64,6 @@ var TelemetryEvent = Schema.Struct({
|
|
|
44
64
|
properties: Schema.optional(EventAttributesSchema),
|
|
45
65
|
options: Schema.optional(EventOptionsSchema)
|
|
46
66
|
}).annotate({ identifier: "TelemetryEvent" });
|
|
47
|
-
var PageEvent = Schema.Struct({
|
|
48
|
-
name: Schema.optional(Schema.NonEmptyString),
|
|
49
|
-
category: Schema.optional(Schema.NonEmptyString),
|
|
50
|
-
path: Schema.optional(Schema.NonEmptyString),
|
|
51
|
-
properties: Schema.optional(EventAttributesSchema),
|
|
52
|
-
options: Schema.optional(EventOptionsSchema)
|
|
53
|
-
}).annotate({ identifier: "PageEvent" });
|
|
54
|
-
var BrowserIdentity = Schema.Struct({
|
|
55
|
-
userId: Schema.optional(Schema.NonEmptyString),
|
|
56
|
-
organizationId: Schema.optional(Schema.NonEmptyString)
|
|
57
|
-
}).annotate({ identifier: "BrowserTelemetryIdentity" });
|
|
58
67
|
|
|
59
68
|
// ../../src/services/opentelemetry/events.ts
|
|
60
69
|
class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
|
|
@@ -65,27 +74,36 @@ class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
|
|
|
65
74
|
return yield* OtlpExporter.make({
|
|
66
75
|
...options,
|
|
67
76
|
label: "OtlpEvents",
|
|
68
|
-
body: (logRecords) =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
body: (logRecords) => {
|
|
78
|
+
const scopes = new Map;
|
|
79
|
+
for (const { scopeName, ...record } of logRecords) {
|
|
80
|
+
const name = scopeName ?? options.scopeName ?? "krakstack.events";
|
|
81
|
+
const records = scopes.get(name);
|
|
82
|
+
if (records)
|
|
83
|
+
records.push(record);
|
|
84
|
+
else
|
|
85
|
+
scopes.set(name, [record]);
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
serialization.logs({
|
|
89
|
+
resourceLogs: [
|
|
90
|
+
{
|
|
91
|
+
resource,
|
|
92
|
+
scopeLogs: Array.from(scopes, ([name, records]) => ({
|
|
93
|
+
scope: { name },
|
|
94
|
+
logRecords: records
|
|
95
|
+
}))
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}),
|
|
99
|
+
Effect.void
|
|
100
|
+
];
|
|
101
|
+
}
|
|
84
102
|
});
|
|
85
103
|
}));
|
|
86
104
|
}
|
|
87
|
-
var
|
|
88
|
-
const
|
|
105
|
+
var event = Effect.fnUntraced(function* (name, properties, options) {
|
|
106
|
+
const decoded = yield* Schema2.decodeUnknownEffect(TelemetryEvent)({
|
|
89
107
|
name,
|
|
90
108
|
properties,
|
|
91
109
|
options
|
|
@@ -93,20 +111,20 @@ var track = Effect.fnUntraced(function* (name, properties, options) {
|
|
|
93
111
|
const events = yield* OtlpEvents;
|
|
94
112
|
const clock = yield* Clock.Clock;
|
|
95
113
|
const observedTime = clock.currentTimeNanosUnsafe().toString();
|
|
96
|
-
const timestamp =
|
|
114
|
+
const timestamp = decoded.options?.timestamp ? (BigInt(DateTime.toEpochMillis(decoded.options.timestamp)) * 1000000n).toString() : observedTime;
|
|
97
115
|
const span = yield* Effect.currentSpan.pipe(Effect.option);
|
|
98
|
-
const attributes = { ...
|
|
99
|
-
if (
|
|
100
|
-
attributes["user.id"] =
|
|
101
|
-
if (
|
|
102
|
-
attributes["analytics.anonymous_id"] =
|
|
103
|
-
if (
|
|
104
|
-
attributes["session.id"] =
|
|
105
|
-
if (
|
|
106
|
-
attributes["log.record.uid"] =
|
|
116
|
+
const attributes = { ...decoded.options?.context, ...decoded.properties };
|
|
117
|
+
if (decoded.options?.userId)
|
|
118
|
+
attributes["user.id"] = decoded.options.userId;
|
|
119
|
+
if (decoded.options?.anonymousId)
|
|
120
|
+
attributes["analytics.anonymous_id"] = decoded.options.anonymousId;
|
|
121
|
+
if (decoded.options?.sessionId)
|
|
122
|
+
attributes["session.id"] = decoded.options.sessionId;
|
|
123
|
+
if (decoded.options?.messageId)
|
|
124
|
+
attributes["log.record.uid"] = decoded.options.messageId;
|
|
107
125
|
const annotations = yield* References.CurrentLogAnnotations;
|
|
108
126
|
events.push({
|
|
109
|
-
eventName:
|
|
127
|
+
eventName: decoded.name,
|
|
110
128
|
timeUnixNano: timestamp,
|
|
111
129
|
observedTimeUnixNano: observedTime,
|
|
112
130
|
severityNumber: 9,
|
|
@@ -120,7 +138,7 @@ var track = Effect.fnUntraced(function* (name, properties, options) {
|
|
|
120
138
|
});
|
|
121
139
|
});
|
|
122
140
|
|
|
123
|
-
// ../../src/services/opentelemetry/
|
|
141
|
+
// ../../src/services/opentelemetry/index.ts
|
|
124
142
|
var ServerEventsLive = Layer2.unwrap(Effect2.gen(function* () {
|
|
125
143
|
const disabled = yield* Config.Boolean("OTEL_SDK_DISABLED").pipe(Config.withDefault(false));
|
|
126
144
|
const exporters = yield* Config.Array(Schema3.String, "OTEL_LOGS_EXPORTER").pipe(Config.withDefault([]));
|
|
@@ -145,10 +163,10 @@ var ServerEventsLive = Layer2.unwrap(Effect2.gen(function* () {
|
|
|
145
163
|
});
|
|
146
164
|
}).pipe(Effect2.orDie));
|
|
147
165
|
|
|
148
|
-
class
|
|
149
|
-
static
|
|
150
|
-
static layer = Layer2.mergeAll(
|
|
166
|
+
class Otlp extends Context2.Service()("krakstack/opentelemetry/Otlp") {
|
|
167
|
+
static event = event;
|
|
168
|
+
static layer = Layer2.mergeAll(Layer2.succeed(this, { resource: OtlpResource2.fromConfig() }), EffectOtlp.layerFromConfig(), ServerEventsLive).pipe(Layer2.provideMerge(OtlpExporter2.layerFlusher), Layer2.provide(OtlpSerialization2.layerJson), Layer2.provide(FetchHttpClient.layer));
|
|
151
169
|
}
|
|
152
170
|
export {
|
|
153
|
-
|
|
171
|
+
Otlp
|
|
154
172
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
import type { HttpServerRequest } from "effect/http";
|
|
3
|
+
export interface OtlpLogsResult {
|
|
4
|
+
readonly body: Uint8Array;
|
|
5
|
+
/** All records in this batch have committed to authoritative storage. */
|
|
6
|
+
readonly persisted: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const OtlpProcessingError_base: Schema.Class<OtlpProcessingError, Schema.TaggedStruct<"OtlpProcessingError", {
|
|
9
|
+
readonly status: Schema.Literals<readonly [400, 403, 409, 413, 503]>;
|
|
10
|
+
}>, import("effect/Cause").YieldableError>;
|
|
11
|
+
export declare class OtlpProcessingError extends OtlpProcessingError_base {
|
|
12
|
+
}
|
|
13
|
+
declare const OtlpLogsProcessor_base: Context.ServiceClass<OtlpLogsProcessor, "krakstack/opentelemetry/OtlpLogsProcessor", {
|
|
14
|
+
readonly process: (body: Uint8Array) => Effect.Effect<OtlpLogsResult, OtlpProcessingError, HttpServerRequest.HttpServerRequest>;
|
|
15
|
+
}>;
|
|
16
|
+
/** Optional processing at the existing OTLP/HTTP logs boundary. */
|
|
17
|
+
export declare class OtlpLogsProcessor extends OtlpLogsProcessor_base {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
export declare const BrowserWebVital: Schema.Struct<{
|
|
3
|
+
readonly name: Schema.Literals<readonly ["LCP", "INP", "CLS", "FCP", "TTFB"]>;
|
|
4
|
+
readonly id: Schema.NonEmptyString;
|
|
5
|
+
readonly value: Schema.Finite;
|
|
6
|
+
readonly delta: Schema.Finite;
|
|
7
|
+
readonly rating: Schema.Literals<readonly ["good", "needs-improvement", "poor"]>;
|
|
8
|
+
readonly navigationType: Schema.Literals<readonly ["navigate", "reload", "back-forward", "back-forward-cache", "prerender", "restore"]>;
|
|
9
|
+
}>;
|
|
2
10
|
export declare const EventAttributesSchema: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>;
|
|
3
11
|
export declare const EventOptionsSchema: Schema.Struct<{
|
|
4
12
|
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
@@ -20,25 +28,5 @@ export declare const TelemetryEvent: Schema.Struct<{
|
|
|
20
28
|
readonly context: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>>;
|
|
21
29
|
}>>;
|
|
22
30
|
}>;
|
|
23
|
-
export declare const PageEvent: Schema.Struct<{
|
|
24
|
-
readonly name: Schema.optional<Schema.NonEmptyString>;
|
|
25
|
-
readonly category: Schema.optional<Schema.NonEmptyString>;
|
|
26
|
-
readonly path: Schema.optional<Schema.NonEmptyString>;
|
|
27
|
-
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>>;
|
|
28
|
-
readonly options: Schema.optional<Schema.Struct<{
|
|
29
|
-
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
30
|
-
readonly anonymousId: Schema.optional<Schema.NonEmptyString>;
|
|
31
|
-
readonly sessionId: Schema.optional<Schema.NonEmptyString>;
|
|
32
|
-
readonly messageId: Schema.optional<Schema.NonEmptyString>;
|
|
33
|
-
readonly timestamp: Schema.optional<Schema.DateTimeUtc>;
|
|
34
|
-
readonly context: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>>;
|
|
35
|
-
}>>;
|
|
36
|
-
}>;
|
|
37
31
|
export type EventAttributes = typeof EventAttributesSchema.Type;
|
|
38
32
|
export type EventOptions = typeof EventOptionsSchema.Type;
|
|
39
|
-
export type PageOptions = typeof PageEvent.Type;
|
|
40
|
-
export declare const BrowserIdentity: Schema.Struct<{
|
|
41
|
-
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
42
|
-
readonly organizationId: Schema.optional<Schema.NonEmptyString>;
|
|
43
|
-
}>;
|
|
44
|
-
export type BrowserIdentity = typeof BrowserIdentity.Type;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Metric } from "web-vitals";
|
|
2
|
+
import { Context, Layer, Schema } from "effect";
|
|
3
|
+
import { OtlpEvents } from "./events.js";
|
|
4
|
+
/** web-vitals observers are document-scoped; only subscribers retain application state. */
|
|
5
|
+
export declare const subscribeWebVitals: (subscriber: (metric: Metric) => void) => () => void;
|
|
6
|
+
export declare const WebVitals: Context.Reference<{
|
|
7
|
+
readonly subscribe: typeof subscribeWebVitals;
|
|
8
|
+
}>;
|
|
9
|
+
export interface BrowserWebVitalsOptions {
|
|
10
|
+
readonly respectDoNotTrack?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class BrowserWebVitals {
|
|
13
|
+
/** Provide a browser telemetry layer with events enabled; no exporter is created here. */
|
|
14
|
+
static readonly layer: ({ respectDoNotTrack, }?: BrowserWebVitalsOptions) => Layer.Layer<never, Schema.SchemaError, OtlpEvents>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// ../../src/services/opentelemetry/web-vitals.ts
|
|
2
|
+
import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
|
|
3
|
+
import { Clock as Clock2, Context as Context2, Effect as Effect2, Layer as Layer2, Schema as Schema3 } from "effect";
|
|
4
|
+
|
|
5
|
+
// ../../src/services/opentelemetry/events.ts
|
|
6
|
+
import {
|
|
7
|
+
Clock,
|
|
8
|
+
Context,
|
|
9
|
+
DateTime,
|
|
10
|
+
Effect,
|
|
11
|
+
Layer,
|
|
12
|
+
Option,
|
|
13
|
+
References,
|
|
14
|
+
Schema as Schema2
|
|
15
|
+
} from "effect";
|
|
16
|
+
import {
|
|
17
|
+
OtlpExporter,
|
|
18
|
+
OtlpResource,
|
|
19
|
+
OtlpSerialization
|
|
20
|
+
} from "effect/observability";
|
|
21
|
+
|
|
22
|
+
// ../../src/services/opentelemetry/schema.ts
|
|
23
|
+
import { Schema } from "effect";
|
|
24
|
+
var BrowserWebVital = Schema.Struct({
|
|
25
|
+
name: Schema.Literals(["LCP", "INP", "CLS", "FCP", "TTFB"]),
|
|
26
|
+
id: Schema.NonEmptyString.check(Schema.isMaxLength(64)),
|
|
27
|
+
value: Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
28
|
+
delta: Schema.Finite,
|
|
29
|
+
rating: Schema.Literals(["good", "needs-improvement", "poor"]),
|
|
30
|
+
navigationType: Schema.Literals([
|
|
31
|
+
"navigate",
|
|
32
|
+
"reload",
|
|
33
|
+
"back-forward",
|
|
34
|
+
"back-forward-cache",
|
|
35
|
+
"prerender",
|
|
36
|
+
"restore"
|
|
37
|
+
])
|
|
38
|
+
}).annotate({ identifier: "BrowserWebVital" });
|
|
39
|
+
var EventAttributeValue = Schema.Union([
|
|
40
|
+
Schema.String,
|
|
41
|
+
Schema.Finite,
|
|
42
|
+
Schema.Boolean,
|
|
43
|
+
Schema.Array(Schema.String),
|
|
44
|
+
Schema.Array(Schema.Finite),
|
|
45
|
+
Schema.Array(Schema.Boolean)
|
|
46
|
+
]);
|
|
47
|
+
var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
|
|
48
|
+
var EventOptionsSchema = Schema.Struct({
|
|
49
|
+
userId: Schema.optional(Schema.NonEmptyString),
|
|
50
|
+
anonymousId: Schema.optional(Schema.NonEmptyString),
|
|
51
|
+
sessionId: Schema.optional(Schema.NonEmptyString),
|
|
52
|
+
messageId: Schema.optional(Schema.NonEmptyString),
|
|
53
|
+
timestamp: Schema.optional(Schema.DateTimeUtc),
|
|
54
|
+
context: Schema.optional(EventAttributesSchema)
|
|
55
|
+
}).annotate({ identifier: "EventOptions" });
|
|
56
|
+
var TelemetryEvent = Schema.Struct({
|
|
57
|
+
name: Schema.NonEmptyString,
|
|
58
|
+
properties: Schema.optional(EventAttributesSchema),
|
|
59
|
+
options: Schema.optional(EventOptionsSchema)
|
|
60
|
+
}).annotate({ identifier: "TelemetryEvent" });
|
|
61
|
+
|
|
62
|
+
// ../../src/services/opentelemetry/events.ts
|
|
63
|
+
class OtlpEvents extends Context.Service()("krakstack/opentelemetry/Events") {
|
|
64
|
+
static disabledLayer = Layer.succeed(this, { push: () => {} });
|
|
65
|
+
static layer = (options) => Layer.effect(this, Effect.gen(function* () {
|
|
66
|
+
const serialization = yield* OtlpSerialization.OtlpSerialization;
|
|
67
|
+
const resource = yield* OtlpResource.fromConfig(options.resource);
|
|
68
|
+
return yield* OtlpExporter.make({
|
|
69
|
+
...options,
|
|
70
|
+
label: "OtlpEvents",
|
|
71
|
+
body: (logRecords) => {
|
|
72
|
+
const scopes = new Map;
|
|
73
|
+
for (const { scopeName, ...record } of logRecords) {
|
|
74
|
+
const name = scopeName ?? options.scopeName ?? "krakstack.events";
|
|
75
|
+
const records = scopes.get(name);
|
|
76
|
+
if (records)
|
|
77
|
+
records.push(record);
|
|
78
|
+
else
|
|
79
|
+
scopes.set(name, [record]);
|
|
80
|
+
}
|
|
81
|
+
return [
|
|
82
|
+
serialization.logs({
|
|
83
|
+
resourceLogs: [
|
|
84
|
+
{
|
|
85
|
+
resource,
|
|
86
|
+
scopeLogs: Array.from(scopes, ([name, records]) => ({
|
|
87
|
+
scope: { name },
|
|
88
|
+
logRecords: records
|
|
89
|
+
}))
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}),
|
|
93
|
+
Effect.void
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
var event = Effect.fnUntraced(function* (name, properties, options) {
|
|
100
|
+
const decoded = yield* Schema2.decodeUnknownEffect(TelemetryEvent)({
|
|
101
|
+
name,
|
|
102
|
+
properties,
|
|
103
|
+
options
|
|
104
|
+
});
|
|
105
|
+
const events = yield* OtlpEvents;
|
|
106
|
+
const clock = yield* Clock.Clock;
|
|
107
|
+
const observedTime = clock.currentTimeNanosUnsafe().toString();
|
|
108
|
+
const timestamp = decoded.options?.timestamp ? (BigInt(DateTime.toEpochMillis(decoded.options.timestamp)) * 1000000n).toString() : observedTime;
|
|
109
|
+
const span = yield* Effect.currentSpan.pipe(Effect.option);
|
|
110
|
+
const attributes = { ...decoded.options?.context, ...decoded.properties };
|
|
111
|
+
if (decoded.options?.userId)
|
|
112
|
+
attributes["user.id"] = decoded.options.userId;
|
|
113
|
+
if (decoded.options?.anonymousId)
|
|
114
|
+
attributes["analytics.anonymous_id"] = decoded.options.anonymousId;
|
|
115
|
+
if (decoded.options?.sessionId)
|
|
116
|
+
attributes["session.id"] = decoded.options.sessionId;
|
|
117
|
+
if (decoded.options?.messageId)
|
|
118
|
+
attributes["log.record.uid"] = decoded.options.messageId;
|
|
119
|
+
const annotations = yield* References.CurrentLogAnnotations;
|
|
120
|
+
events.push({
|
|
121
|
+
eventName: decoded.name,
|
|
122
|
+
timeUnixNano: timestamp,
|
|
123
|
+
observedTimeUnixNano: observedTime,
|
|
124
|
+
severityNumber: 9,
|
|
125
|
+
attributes: OtlpResource.entriesToAttributes(Object.entries({
|
|
126
|
+
...attributes,
|
|
127
|
+
...annotations
|
|
128
|
+
})),
|
|
129
|
+
droppedAttributesCount: 0,
|
|
130
|
+
traceId: Option.isSome(span) ? span.value.traceId : undefined,
|
|
131
|
+
spanId: Option.isSome(span) ? span.value.spanId : undefined
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// ../../src/services/opentelemetry/web-vitals.ts
|
|
136
|
+
var subscribers = new Set;
|
|
137
|
+
var started = false;
|
|
138
|
+
var subscribeWebVitals = (subscriber) => {
|
|
139
|
+
subscribers.add(subscriber);
|
|
140
|
+
if (!started) {
|
|
141
|
+
started = true;
|
|
142
|
+
const report = (metric) => {
|
|
143
|
+
for (const listener of subscribers)
|
|
144
|
+
listener(metric);
|
|
145
|
+
};
|
|
146
|
+
onCLS(report);
|
|
147
|
+
onFCP(report);
|
|
148
|
+
onINP(report);
|
|
149
|
+
onLCP(report);
|
|
150
|
+
onTTFB(report);
|
|
151
|
+
}
|
|
152
|
+
return () => {
|
|
153
|
+
subscribers.delete(subscriber);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
var WebVitals = Context2.Reference("krakstack/opentelemetry/WebVitals", {
|
|
157
|
+
defaultValue: () => ({ subscribe: subscribeWebVitals })
|
|
158
|
+
});
|
|
159
|
+
var WebVitalsLive = Layer2.effectDiscard(Effect2.gen(function* () {
|
|
160
|
+
const vitals = yield* WebVitals;
|
|
161
|
+
const events = yield* OtlpEvents;
|
|
162
|
+
const clock = yield* Clock2.Clock;
|
|
163
|
+
const seen = new Map;
|
|
164
|
+
yield* Effect2.acquireRelease(Effect2.sync(() => vitals.subscribe((input) => {
|
|
165
|
+
const parsed = Schema3.decodeUnknownOption(BrowserWebVital)(input);
|
|
166
|
+
if (parsed._tag === "None")
|
|
167
|
+
return;
|
|
168
|
+
const metric = parsed.value;
|
|
169
|
+
const key = `${metric.name}:${metric.id}`;
|
|
170
|
+
if (seen.get(key) === metric.value)
|
|
171
|
+
return;
|
|
172
|
+
seen.set(key, metric.value);
|
|
173
|
+
const timestamp = clock.currentTimeNanosUnsafe().toString();
|
|
174
|
+
events.push({
|
|
175
|
+
eventName: "browser.web_vital",
|
|
176
|
+
timeUnixNano: timestamp,
|
|
177
|
+
observedTimeUnixNano: timestamp,
|
|
178
|
+
severityNumber: 9,
|
|
179
|
+
droppedAttributesCount: 0,
|
|
180
|
+
attributes: [
|
|
181
|
+
{
|
|
182
|
+
key: "browser.web_vital.name",
|
|
183
|
+
value: { stringValue: metric.name.toLowerCase() }
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
key: "browser.web_vital.id",
|
|
187
|
+
value: { stringValue: metric.id }
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
key: "browser.web_vital.value",
|
|
191
|
+
value: { doubleValue: metric.value }
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
key: "browser.web_vital.delta",
|
|
195
|
+
value: { doubleValue: metric.delta }
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "browser.web_vital.rating",
|
|
199
|
+
value: { stringValue: metric.rating }
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
key: "browser.web_vital.navigation_type",
|
|
203
|
+
value: { stringValue: metric.navigationType }
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
key: "log.record.uid",
|
|
207
|
+
value: { stringValue: `${metric.id}:${metric.value}` }
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
});
|
|
211
|
+
})), (unsubscribe) => Effect2.sync(unsubscribe));
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
class BrowserWebVitals {
|
|
215
|
+
static layer = ({
|
|
216
|
+
respectDoNotTrack = true
|
|
217
|
+
} = {}) => Layer2.unwrap(Effect2.gen(function* () {
|
|
218
|
+
const privacy = yield* Schema3.decodeUnknownEffect(Schema3.Struct({
|
|
219
|
+
globalPrivacyControl: Schema3.optional(Schema3.Boolean)
|
|
220
|
+
}))(navigator);
|
|
221
|
+
const optedOut = respectDoNotTrack && (navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || privacy.globalPrivacyControl === true);
|
|
222
|
+
return optedOut ? Layer2.empty : WebVitalsLive;
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
BrowserWebVitals,
|
|
227
|
+
WebVitals,
|
|
228
|
+
subscribeWebVitals
|
|
229
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/registry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
4
4
|
"description": "Tree-shakable KrakStack components and Effect services.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,30 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
20
|
+
"./events/client": {
|
|
21
|
+
"types": "./dist/services/events/client/audit-log-table.d.ts",
|
|
22
|
+
"import": "./dist/services/events/client/audit-log-table.js"
|
|
23
|
+
},
|
|
24
|
+
"./events/schema": {
|
|
25
|
+
"types": "./dist/services/events/schema.d.ts",
|
|
26
|
+
"import": "./dist/services/events/schema.js"
|
|
27
|
+
},
|
|
28
|
+
"./events/record": {
|
|
29
|
+
"types": "./dist/services/events/record.d.ts",
|
|
30
|
+
"import": "./dist/services/events/record.js"
|
|
31
|
+
},
|
|
32
|
+
"./events": {
|
|
33
|
+
"types": "./dist/services/events/index.d.ts",
|
|
34
|
+
"import": "./dist/services/events/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./events/browser": {
|
|
37
|
+
"types": "./dist/services/events/browser.d.ts",
|
|
38
|
+
"import": "./dist/services/events/browser.js"
|
|
39
|
+
},
|
|
40
|
+
"./events/migrations": {
|
|
41
|
+
"types": "./dist/services/events/migrations.d.ts",
|
|
42
|
+
"import": "./dist/services/events/migrations.js"
|
|
43
|
+
},
|
|
20
44
|
"./agent": {
|
|
21
45
|
"types": "./dist/services/agent/index.d.ts",
|
|
22
46
|
"import": "./dist/services/agent/index.js"
|
|
@@ -49,9 +73,13 @@
|
|
|
49
73
|
"types": "./dist/services/opentelemetry/browser.d.ts",
|
|
50
74
|
"import": "./dist/services/opentelemetry/browser.js"
|
|
51
75
|
},
|
|
52
|
-
"./opentelemetry/
|
|
53
|
-
"types": "./dist/services/opentelemetry/
|
|
54
|
-
"import": "./dist/services/opentelemetry/
|
|
76
|
+
"./opentelemetry/web-vitals": {
|
|
77
|
+
"types": "./dist/services/opentelemetry/web-vitals.d.ts",
|
|
78
|
+
"import": "./dist/services/opentelemetry/web-vitals.js"
|
|
79
|
+
},
|
|
80
|
+
"./opentelemetry": {
|
|
81
|
+
"types": "./dist/services/opentelemetry/index.d.ts",
|
|
82
|
+
"import": "./dist/services/opentelemetry/index.js"
|
|
55
83
|
},
|
|
56
84
|
"./docs": {
|
|
57
85
|
"types": "./dist/lib/docs.d.ts",
|
|
@@ -232,7 +260,9 @@
|
|
|
232
260
|
"prepack": "bun run check:release"
|
|
233
261
|
},
|
|
234
262
|
"dependencies": {
|
|
235
|
-
"@oxlint/plugins": "1.78.0"
|
|
263
|
+
"@oxlint/plugins": "1.78.0",
|
|
264
|
+
"bowser": "^2.14.1",
|
|
265
|
+
"web-vitals": "^5.1.0"
|
|
236
266
|
},
|
|
237
267
|
"peerDependencies": {
|
|
238
268
|
"@aws-sdk/client-sesv2": "^3.1068.0",
|