@redthreadlabs/tracelog-client 1.7.0 → 1.8.0

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.
@@ -13,6 +13,13 @@ export declare class LogClient {
13
13
  event(type?: string): EventBuilder;
14
14
  startPerf(name: string, parent?: PerfToken): PerfToken;
15
15
  endPerf(token: PerfToken, context?: Record<string, JsonValue>): void;
16
+ /**
17
+ * Record a complete perf measurement in one call — for operations timed
18
+ * elsewhere (a pre-measured duration with no live start/end pair). Buffers a
19
+ * parent-less, root perf, which the server maps to a `transaction` record.
20
+ * Reach for startPerf/endPerf instead when you need a live span tree.
21
+ */
22
+ recordPerf(name: string, durationMs: number, context?: Record<string, JsonValue>, outcome?: 'success' | 'failure' | 'unknown'): void;
16
23
  flush(): Promise<void>;
17
24
  dispose(): void;
18
25
  private _enqueueEvent;
package/dist/LogClient.js CHANGED
@@ -92,6 +92,40 @@ class LogClient {
92
92
  this.flush();
93
93
  }
94
94
  }
95
+ /**
96
+ * Record a complete perf measurement in one call — for operations timed
97
+ * elsewhere (a pre-measured duration with no live start/end pair). Buffers a
98
+ * parent-less, root perf, which the server maps to a `transaction` record.
99
+ * Reach for startPerf/endPerf instead when you need a live span tree.
100
+ */
101
+ recordPerf(name, durationMs, context, outcome = 'success') {
102
+ if (this._disposed)
103
+ return;
104
+ if (!isFinite(durationMs) || durationMs < 0)
105
+ durationMs = 0;
106
+ const id = randomHex(16);
107
+ const end = now();
108
+ const perf = {
109
+ id,
110
+ trace_id: randomHex(32),
111
+ root_id: id,
112
+ name,
113
+ type: 'client-perf',
114
+ // No live start time, so back-compute it from the measured duration.
115
+ timestamp: Math.round(end - durationMs),
116
+ duration: Math.round(durationMs),
117
+ outcome,
118
+ tz_offset: (0, util_1.tzOffsetMinutes)(),
119
+ };
120
+ if (context && Object.keys(context).length > 0) {
121
+ perf.context = { tags: context };
122
+ }
123
+ this._perfBuffer.push(perf);
124
+ this._schedulePersist();
125
+ if (this._perfBuffer.length + this._eventBuffer.length >= (this._opts.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE)) {
126
+ this.flush();
127
+ }
128
+ }
95
129
  // ---- Transport ----
96
130
  async flush() {
97
131
  if (this._disposed || this._flushing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redthreadlabs/tracelog-client",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Lightweight logging client for tracelog — works in React Native and browsers",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",