@safaricom-mxl/effect-sdk 0.0.15 → 0.0.17

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/README.md CHANGED
@@ -5,7 +5,7 @@ OpenTelemetry traces, logs, and metrics for [Effect](https://effect.website) app
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- pnpm add @safaricom-mxl/effect-sdk effect
8
+ pnpm add @safaricom-mxl/effect-sdk effect @effect/opentelemetry
9
9
  ```
10
10
 
11
11
  ## Server
@@ -23,16 +23,40 @@ const program = Effect.log("Hello!").pipe(Effect.withSpan("hello"));
23
23
  Effect.runPromise(program.pipe(Effect.provide(ObservabilityLive)));
24
24
  ```
25
25
 
26
- ## Browser
26
+ ## Product events
27
27
 
28
- Use `@safaricom-mxl/effect-sdk/browser` explicitly in browser bundles (Vite client, etc.):
28
+ Server `MxlEvents.track` buffers product events and flushes NDJSON to Basket `POST /events` (or `POST /v1/events` when `eventsPath` is set). Send `mxl-client-id`. Send `mxl-api-key` when configured.
29
29
 
30
30
  ```typescript
31
- import { Mxl } from "@safaricom-mxl/effect-sdk/browser";
31
+ import { MxlEvents, MxlFlush } from "@safaricom-mxl/effect-sdk/server";
32
32
 
33
- const ObservabilityLive = Mxl.layer({ serviceName: "mxl-console" });
33
+ const telemetry = MxlFlush.make({
34
+ clientId: process.env.MXL_CLIENT_ID,
35
+ ingestUrl: process.env.MXL_BASKET_URL,
36
+ serviceName: "billing",
37
+ });
38
+
39
+ telemetry.track("plan_started", { userId: "user_1" });
40
+ await telemetry.flush();
41
+ ```
42
+
43
+ Browser `track` dual-writes a product line to `/events` and a session row to `/sessionEvents` with `type: "custom"`. `identify` / increment / decrement go through `POST /track`. `@safaricom-mxl/effect-sdk/client` is an alias of `./browser`.
44
+
45
+ ```typescript
46
+ import { identify, MxlFlush, track } from "@safaricom-mxl/effect-sdk/browser";
47
+
48
+ const telemetry = MxlFlush.make({
49
+ clientId: "client_1",
50
+ ingestUrl: "https://basket.example",
51
+ serviceName: "web",
52
+ });
53
+
54
+ identify({ id: "user_1", email: "a@b.com" });
55
+ track("checkout_completed", { plan: "pro" });
34
56
  ```
35
57
 
58
+ Cloudflare workers use `./cloudflare`. `make()` is module-scope; `flush(env)` resolves `MXL_CLIENT_ID` / `MXL_API_KEY` lazily and is safe inside `waitUntil`. Replay posts `/sessionReplays/meta` and `/sessionReplays/blob`, and stands down when `@safaricom-mxl/web-sdk` already owns the page.
59
+
36
60
  Do not import `@safaricom-mxl/effect-sdk/server` from browser code. The package root (`"."`) resolves to the server build under Node/default conditions.
37
61
 
38
62
  ### Environment variables
@@ -45,9 +69,12 @@ Do not import `@safaricom-mxl/effect-sdk/server` from browser code. The package
45
69
  | `OTEL_SERVICE_NAME` | Service name |
46
70
  | `OTEL_RESOURCE_ATTRIBUTES` | Extra resource attributes |
47
71
  | `OTEL_SDK_DISABLED` | When `true`, installs a no-op layer |
72
+ | `MXL_BASKET_URL` | Basket origin for product events |
73
+ | `MXL_CLIENT_ID` | Required for product-event ingest |
74
+ | `MXL_API_KEY` | Sent as `mxl-api-key` when configured |
48
75
 
49
76
  Default endpoint: `http://127.0.0.1:4318` (local `mxl-otel-collector`).
50
77
 
51
78
  ## License
52
79
 
53
- MIT
80
+ Apache-2.0
@@ -1,22 +1,86 @@
1
+ import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
1
2
  import { Effect, Layer } from "effect";
3
+ //#region src/shared/product-event.d.ts
4
+ interface TrackProps {
5
+ readonly [key: string]: unknown;
6
+ }
7
+ //#endregion
8
+ //#region src/shared/identity.d.ts
9
+ interface MapleIdentity {
10
+ readonly email?: string | undefined;
11
+ readonly groupId?: string | undefined;
12
+ readonly groupName?: string | undefined;
13
+ readonly id: string;
14
+ readonly traits?: Record<string, unknown> | undefined;
15
+ }
16
+ type IdentifyInput = string | MapleIdentity | null | undefined;
17
+ //#endregion
18
+ //#region src/browser/analytics.d.ts
19
+ interface PrivacyOptions {
20
+ readonly requireConsent?: boolean | undefined;
21
+ }
22
+ export declare const setConsent: (granted: boolean) => void;
23
+ export declare const identify: (input?: IdentifyInput) => void;
24
+ export declare const clearIdentity: () => void;
25
+ export declare const track: (name: string, props?: TrackProps) => void;
26
+ export declare const increment: (property: string, value?: number) => void;
27
+ export declare const decrement: (property: string, value?: number) => void;
28
+ //#endregion
29
+ //#region src/browser/replay.d.ts
30
+ interface ClientReplayConfig {
31
+ readonly enabled?: boolean | undefined;
32
+ readonly maskAllInputs?: boolean | undefined;
33
+ readonly maskAllText?: boolean | undefined;
34
+ readonly sampleRate?: number | undefined;
35
+ }
2
36
  declare namespace layer_d_exports {
3
- export { MxlBrowserConfig, layer };
37
+ export { MxlBrowserConfig, clearIdentity$1 as clearIdentity, identify$1 as identify, layer, stampUserIdOnSpan, track$1 as track };
4
38
  }
5
39
  interface MxlBrowserConfig {
6
- readonly serviceName?: string | undefined;
7
- readonly serviceVersion?: string | undefined;
8
- readonly environment?: string | undefined;
9
- readonly endpoint?: string | undefined;
10
- readonly headers?: Record<string, string> | undefined;
40
+ readonly apiKey?: string | undefined;
11
41
  readonly attributes?: Record<string, string> | undefined;
42
+ readonly clientId?: string | undefined;
12
43
  readonly disabled?: boolean | undefined;
44
+ readonly endpoint?: string | undefined;
45
+ readonly environment?: string | undefined;
46
+ readonly headers?: Record<string, string> | undefined;
47
+ readonly ingestUrl?: string | undefined;
48
+ readonly privacy?: PrivacyOptions | undefined;
49
+ readonly replay?: ClientReplayConfig | undefined;
50
+ readonly serviceName?: string | undefined;
51
+ readonly serviceVersion?: string | undefined;
13
52
  }
53
+ declare const stampUserIdOnSpan: (span: {
54
+ setAttribute: (key: string, value: string) => unknown;
55
+ }) => void;
14
56
  /**
15
57
  * Browser Effect observability layer backed by OpenTelemetry WebSdk.
16
58
  *
17
59
  * Returns a no-op layer when `disabled` is true or no OTLP endpoint is configured.
18
60
  */
19
61
  declare const layer: (config?: MxlBrowserConfig) => Layer.Layer<never, never, never>;
62
+ declare const identify$1: (input?: IdentifyInput) => Effect.Effect<void, never, never>;
63
+ declare const clearIdentity$1: Effect.Effect<void, never, never>;
64
+ declare const track$1: (name: string, props?: TrackProps) => Effect.Effect<void, never, never>;
65
+ declare namespace flushable_d_exports {
66
+ export { FlushableTelemetry, MxlBrowserFlushableConfig, attachProcessor, make };
67
+ }
68
+ interface MxlBrowserFlushableConfig extends MxlBrowserConfig {
69
+ readonly autoFlushInterval?: number | false | undefined;
70
+ readonly captureGlobalErrors?: boolean | undefined;
71
+ readonly flushOnUnload?: boolean | undefined;
72
+ }
73
+ interface FlushableTelemetry {
74
+ readonly captureException: (error: unknown, options?: {
75
+ readonly attributes?: Record<string, string>;
76
+ readonly name?: string;
77
+ }) => void;
78
+ readonly dispose: () => Promise<void>;
79
+ readonly flush: () => Promise<void>;
80
+ readonly layer: Layer.Layer<never>;
81
+ }
82
+ declare const attachProcessor: (telemetry: FlushableTelemetry, processor: BatchSpanProcessor) => void;
83
+ declare const make: (config?: MxlBrowserFlushableConfig) => FlushableTelemetry;
20
84
  //#endregion
21
85
  //#region src/shared/dependency-spans.d.ts
22
86
  type DbSystem = "clickhouse" | "postgresql" | "redis";
@@ -42,5 +106,5 @@ export declare function withDependencySpan<A, E, R>(name: string, options: WithD
42
106
  /** Promise-based dependency span for non-Effect code paths. */
43
107
  export declare function withPromiseDependencySpan<T>(name: string, attributes: Record<string, string>, operation: () => Promise<T>, kind?: DependencySpanKind): Promise<T>;
44
108
  //#endregion
45
- export { type DbSystem, type DependencySpanKind, layer_d_exports as Mxl, type MxlBrowserConfig, type QueueTraceContextCarrier, type WithDependencySpanOptions };
109
+ export { type ClientReplayConfig, type DbSystem, type DependencySpanKind, type FlushableTelemetry, type IdentifyInput, type MapleIdentity, layer_d_exports as Mxl, type MxlBrowserConfig, type MxlBrowserFlushableConfig, flushable_d_exports as MxlFlush, type PrivacyOptions, type QueueTraceContextCarrier, type TrackProps, type WithDependencySpanOptions };
46
110
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/browser/layer.ts","../../src/shared/dependency-spans.ts"],"mappings":";;;;UASiB;WACN;WACA;WACA;WACA;WACA,UAAU;WACV,aAAa;WACb;;;;;;;cAkBE,QAAK,SAAY,qBAAgB,MAAA;;;KCzBlC;KAEA;UAIK;WACN;WACA;WACA;;wBAGK,uBACd,UAAU,UACV,qBACC;wBASa,4BACd,yBACA,uBACC;wBAQa,4BACd,0BACC;wBAOa,4BACd,eACA,uBACC;wBAQa,qBACd,oBACA,oBACC;wBAUa,qBAAqB;wBASrB,8BACd,mBAAmB;UAiCJ;WACN,aAAa;WACb,OAAO;;wBAGF,mBAAmB,GAAG,GAAG,GACvC,cACA,YAAY,wBACZ,SAAS,OAAO,OAAO,GAAG,GAAG,KAC5B,OAAO,OAAO,GAAG,GAAG;wBACP,mBAAmB,GAAG,GAAG,GACvC,cACA,SAAS,2BACT,SAAS,OAAO,OAAO,GAAG,GAAG,KAC5B,OAAO,OAAO,GAAG,GAAG;;wBA2BD,0BAA0B,GAC9C,cACA,YAAY,wBACZ,iBAAiB,QAAQ,IACzB,OAAM,qBACL,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shared/product-event.ts","../../src/shared/identity.ts","../../src/browser/analytics.ts","../../src/browser/replay.ts","../../src/browser/layer.ts","../../src/browser/flushable.ts","../../src/shared/dependency-spans.ts"],"mappings":";;;UAoBiB;YACL;;;;UCrBK;WACN;WACA;WACA;WACA;WACA,SAAS;;KAGR,yBAAyB;;;UCMpB;WACN;;qBA4HE,aAAU;qBAOV,WAAQ,QAAY;qBA+BpB;qBAiDA,QAAK,cAAgB,QAAU;qBAiC/B,YAAS,kBAAoB;qBAI7B,YAAS,kBAAoB;;;UCpQzB;WACN;WACA;WACA;WACA;;;;;UCgBM;WACN;WACA,aAAa;WACb;WACA;WACA;WACA;WACA,UAAU;WACV;WACA,UAAU;WACV,SAAS;WACT;WACA;;cAGE,oBAAiB;EAC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