@diveinto/obs 1.1.0 → 1.1.1

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/setup.js CHANGED
@@ -29,6 +29,10 @@ import { renderJson, renderPretty } from "./render.js";
29
29
  import { configureSinks, makeFileSink, makeStdoutSink, setSinkInitializer } from "./sinks.js";
30
30
  import { LEVELS } from "./types.js";
31
31
  let configured = false;
32
+ // Whether the sinks were set up before configure() ran, and so hold stdout alone. A record written
33
+ // that early (a heartbeat from startOtel, which a service may call before createObs) must not cost
34
+ // the service its files: the next setupLogging() once configured sets them up again, whole.
35
+ let setUpUnconfigured = false;
32
36
  // Register lazy self-init: the first log emitted in any module context (Next
33
37
  // can isolate the instrumentation hook from the route handlers) runs
34
38
  // setupLogging for THAT context, so request and domain logs are never
@@ -115,11 +119,13 @@ function fileSetting(raw) {
115
119
  /** Test seam: let a test re-run setupLogging() with a different environment. */
116
120
  export function resetLoggingForTests() {
117
121
  configured = false;
122
+ setUpUnconfigured = false;
118
123
  }
119
124
  export function setupLogging() {
120
- if (configured)
125
+ if (configured && !(setUpUnconfigured && isConfigured()))
121
126
  return;
122
127
  configured = true;
128
+ setUpUnconfigured = !isConfigured();
123
129
  const level = resolveLevel();
124
130
  const stdoutFormat = (process.env.LOG_FORMAT || "pretty").trim().toLowerCase() === "json" ? "json" : "pretty";
125
131
  // stdout is always on; its renderer follows LOG_FORMAT.
package/dist/spans.js CHANGED
@@ -142,7 +142,9 @@ export function startExportHeartbeat(exportOn, everyMs = 60_000) {
142
142
  : `export off: ${counters.spansWritten} span(s) written to the files only`, { "obs.export": exportOn ? "on" : "off", ...counters });
143
143
  if (heartbeat)
144
144
  clearInterval(heartbeat);
145
- beat();
145
+ // the first a tick later: startOtel runs before a service's createObs in the usual order, and a
146
+ // record written before configure() can only reach stdout
147
+ setTimeout(beat, 0).unref?.();
146
148
  if (!exportOn)
147
149
  return;
148
150
  heartbeat = setInterval(beat, everyMs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diveinto/obs",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Structured logging, tracing and metrics for Next.js and Node services: one record shape, rotating files, W3C trace context, optional OpenTelemetry export",
5
5
  "license": "MIT",
6
6
  "private": false,