@effectstream/log 0.100.14 → 0.100.16

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 ADDED
@@ -0,0 +1,88 @@
1
+ # @effectstream/log
2
+
3
+ OpenTelemetry-instrumented structured logging for EffectStream. Wraps
4
+ `tslog` and the OpenTelemetry SDK behind a single `log` object that emits
5
+ both pretty console output (`log.local`) and OTLP traces/logs to your
6
+ collector (`log.remote`).
7
+
8
+ - OpenTelemetry-instrumented structured logging on top of `tslog`.
9
+ - Pretty console output and OTLP traces / logs from one `log` object.
10
+ - Used by every package in the framework so the node emits one trace tree.
11
+ - `ComponentNames` constants tag log records by component, powering per-component log views.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ bun add @effectstream/log
17
+ # or
18
+ npm install @effectstream/log
19
+ ```
20
+
21
+ ## Standalone usage
22
+
23
+ Any Node service that wants colored terminal logs plus OTLP export with one
24
+ dependency.
25
+
26
+ ```typescript
27
+ import {
28
+ ComponentNames,
29
+ defaultOtelSetup,
30
+ log,
31
+ SeverityNumber,
32
+ } from "@effectstream/log";
33
+
34
+ // Initialize OpenTelemetry once at startup (optional — defaults work too).
35
+ defaultOtelSetup({ serviceName: "my-app" });
36
+
37
+ // Local-only: pretty console output, no OTLP.
38
+ log.local(
39
+ "my-app", // component name (any string)
40
+ "startup", // namespace
41
+ SeverityNumber.INFO,
42
+ (l) => l("started on port", 3000),
43
+ );
44
+
45
+ // Remote: console + OpenTelemetry log record + trace correlation.
46
+ log.remote(
47
+ "my-app",
48
+ "auth",
49
+ SeverityNumber.INFO,
50
+ (l) => l("user logged in", { userId: "u_123" }),
51
+ );
52
+ ```
53
+
54
+ The deferred `(l) => l(...)` form means message construction is skipped
55
+ entirely when the level is filtered out — handy when log arguments are
56
+ expensive to format (`JSON.stringify` of a big object).
57
+
58
+ Point the SDK at any OTLP-compatible collector (Grafana Alloy, Tempo,
59
+ Honeycomb, …) via the standard `OTEL_EXPORTER_OTLP_ENDPOINT` env var.
60
+
61
+ ## Inside EffectStream
62
+
63
+ Every package in the framework — sync, runtime, batcher, sm — logs through
64
+ this module so the whole node emits one consistent trace tree. The
65
+ `ComponentNames` constants tag log records by component, which is what
66
+ powers the orchestrator's per-component log views.
67
+
68
+ ## Key exports
69
+
70
+ - `log.local(component, namespace, level, deferred)`: console-only logging. `level` is `SeverityNumber`; `deferred = (l) => l(...args)` is called only if the level passes the filter.
71
+ - `log.localForce(...)` bypasses level filtering.
72
+ - `log.remote(...)`: console + OpenTelemetry log record. Same signature as `local`.
73
+ - `log.remoteForce(...)` is `remote` without level filtering.
74
+ - `log.formatMessage(...)` — the formatter used internally; useful for custom transports.
75
+ - `defaultOtelSetup(opts)`: one-call OpenTelemetry SDK setup with sensible defaults.
76
+ - `attachTransport(transport)` registers a custom tslog transport (e.g. ship logs to a file).
77
+ - `SeverityNumber`: re-export of OpenTelemetry severity levels.
78
+ - `ComponentNames`: string-enum constants used to tag logs by component.
79
+ - `Namespace`: `string | string[]` for log namespacing.
80
+
81
+ ## Examples
82
+
83
+ Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
84
+
85
+ ## Links
86
+
87
+ - Docs: https://effectstream.github.io/docs/packages/sdk/log
88
+ - Source: https://github.com/effectstream/effectstream/tree/main/packages/effectstream-sdk/log
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/log",
3
- "version": "0.100.14",
3
+ "version": "0.100.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "exports": "./src/mod.ts",
15
15
  "dependencies": {
16
- "@effectstream/utils": "0.100.14",
16
+ "@effectstream/utils": "0.100.16",
17
17
  "@opentelemetry/api": "^1.9.0",
18
18
  "@opentelemetry/api-logs": "0.56.0",
19
19
  "@opentelemetry/exporter-logs-otlp-http": "0.56.0",
@@ -0,0 +1,52 @@
1
+ // Examples for the README.
2
+
3
+ import { test, expect } from "bun:test";
4
+ import { ComponentNames, log, SeverityNumber } from "../src/mod.ts";
5
+
6
+ test("README: log.local accepts a deferred message function", () => {
7
+ let called = 0;
8
+ log.local(
9
+ "my-app",
10
+ "startup",
11
+ SeverityNumber.INFO,
12
+ (l) => {
13
+ called++;
14
+ l("started on port", 3000);
15
+ },
16
+ );
17
+ // The deferred is invoked synchronously at the appropriate level.
18
+ expect(called).toBe(1);
19
+ });
20
+
21
+ test("README: log.remote accepts the same signature as log.local", () => {
22
+ let called = 0;
23
+ log.remote(
24
+ "my-app",
25
+ "auth",
26
+ SeverityNumber.INFO,
27
+ (l) => {
28
+ called++;
29
+ l("user logged in", { userId: "u_123" });
30
+ },
31
+ );
32
+ expect(called).toBe(1);
33
+ });
34
+
35
+ test("README: log.localForce bypasses level filtering", () => {
36
+ let called = 0;
37
+ log.localForce(
38
+ "my-app",
39
+ "audit",
40
+ SeverityNumber.DEBUG,
41
+ (l) => {
42
+ called++;
43
+ l("low-severity message that would normally be filtered");
44
+ },
45
+ );
46
+ expect(called).toBe(1);
47
+ });
48
+
49
+ test("README: ComponentNames are usable as component tags", () => {
50
+ expect(typeof ComponentNames.EFFECTSTREAM_SYNC).toBe("string");
51
+ expect(typeof ComponentNames.EFFECTSTREAM_RUNTIME).toBe("string");
52
+ });