@logbrew/sdk 0.1.7 → 0.1.8

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
@@ -250,6 +250,7 @@ Use `client.metric()` when application code already knows the measurement name,
250
250
  ```js
251
251
  client.metric("evt_metric_001", "2026-06-02T10:00:06Z", {
252
252
  name: "checkout.requests",
253
+ description: "Number of checkout requests accepted by the application.",
253
254
  kind: "counter",
254
255
  value: 42,
255
256
  unit: "{request}",
@@ -258,7 +259,7 @@ client.metric("evt_metric_001", "2026-06-02T10:00:06Z", {
258
259
  });
259
260
  ```
260
261
 
261
- Metric `kind` must be `counter`, `gauge`, or `histogram`. Counters and histograms must be non-negative and use `delta` or `cumulative` temporality; gauges use `instant` temporality and may be negative. Keep metric metadata primitive and low-cardinality, such as service, region, or route template.
262
+ Metric `kind` must be `counter`, `gauge`, or `histogram`. Counters and histograms must be non-negative and use `delta` or `cumulative` temporality; gauges use `instant` temporality and may be negative. An optional `description` gives humans and investigation tools stable meaning for the measurement; keep it generic, single-line, between 1 and 1,024 Unicode characters, and free of identifiers, personal data, or changing values. It is not a query dimension. Keep metric metadata primitive and low-cardinality, such as service, region, or route template.
262
263
 
263
264
  ## W3C Trace Context
264
265
 
package/core.cjs CHANGED
@@ -23,6 +23,7 @@ const PRODUCT_ANALYTICS_SCHEMA_VERSION = 1;
23
23
  const PRODUCT_ANALYTICS_KINDS = Object.freeze(["page_view", "screen_view", "interaction"]);
24
24
  const MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH = 256;
25
25
  const METRIC_KINDS = new Set(["counter", "gauge", "histogram"]);
26
+ const MAX_METRIC_DESCRIPTION_LENGTH = 1024;
26
27
  const NON_NEGATIVE_METRIC_KINDS = new Set(["counter", "histogram"]);
27
28
  const METRIC_TEMPORALITIES_BY_KIND = new Map([
28
29
  ["counter", new Set(["delta", "cumulative"])],
@@ -2272,9 +2273,11 @@ function validateMetric(attributes) {
2272
2273
  if (NON_NEGATIVE_METRIC_KINDS.has(attributes.kind) && attributes.value < 0) {
2273
2274
  throw new SdkError("validation_error", `metric ${attributes.kind} value must be non-negative`);
2274
2275
  }
2276
+ const description = metricDescriptionOrUndefined(attributes.description);
2275
2277
 
2276
2278
  return withMetadata({
2277
2279
  name: attributes.name,
2280
+ ...(description === undefined ? {} : { description }),
2278
2281
  kind: attributes.kind,
2279
2282
  value: attributes.value,
2280
2283
  unit: attributes.unit,
@@ -2282,6 +2285,33 @@ function validateMetric(attributes) {
2282
2285
  }, attributes.metadata, attributes.context);
2283
2286
  }
2284
2287
 
2288
+ function metricDescriptionOrUndefined(value) {
2289
+ if (value === undefined) {
2290
+ return undefined;
2291
+ }
2292
+ const characters = typeof value === "string" ? Array.from(value) : [];
2293
+ if (
2294
+ typeof value !== "string"
2295
+ || value.trim() === ""
2296
+ || characters.length > MAX_METRIC_DESCRIPTION_LENGTH
2297
+ || characters.some((character) => {
2298
+ const code = character.codePointAt(0);
2299
+ return code !== undefined && (
2300
+ code <= 31
2301
+ || (code >= 127 && code <= 159)
2302
+ || code === 0x2028
2303
+ || code === 0x2029
2304
+ );
2305
+ })
2306
+ ) {
2307
+ throw new SdkError(
2308
+ "validation_error",
2309
+ `metric description must be a non-blank string of at most ${MAX_METRIC_DESCRIPTION_LENGTH} non-control characters`
2310
+ );
2311
+ }
2312
+ return value.trim();
2313
+ }
2314
+
2285
2315
  function productActionDetails(action) {
2286
2316
  if (typeof action === "string") {
2287
2317
  return { name: action, status: "success" };
package/index.d.cts CHANGED
@@ -623,6 +623,8 @@ export type SupportTicketDraft = {
623
623
  /** Public metric event attributes. Use low-cardinality metadata only. */
624
624
  export type MetricAttributes = {
625
625
  name: string;
626
+ /** Optional stable, single-line meaning; 1 to 1,024 Unicode characters. */
627
+ description?: string;
626
628
  kind: "counter" | "histogram";
627
629
  value: number;
628
630
  unit: string;
@@ -631,6 +633,8 @@ export type MetricAttributes = {
631
633
  context?: TelemetryContext;
632
634
  } | {
633
635
  name: string;
636
+ /** Optional stable, single-line meaning; 1 to 1,024 Unicode characters. */
637
+ description?: string;
634
638
  kind: "gauge";
635
639
  value: number;
636
640
  unit: string;
package/index.d.ts CHANGED
@@ -623,6 +623,8 @@ export type SupportTicketDraft = {
623
623
  /** Public metric event attributes. Use low-cardinality metadata only. */
624
624
  export type MetricAttributes = {
625
625
  name: string;
626
+ /** Optional stable, single-line meaning; 1 to 1,024 Unicode characters. */
627
+ description?: string;
626
628
  kind: "counter" | "histogram";
627
629
  value: number;
628
630
  unit: string;
@@ -631,6 +633,8 @@ export type MetricAttributes = {
631
633
  context?: TelemetryContext;
632
634
  } | {
633
635
  name: string;
636
+ /** Optional stable, single-line meaning; 1 to 1,024 Unicode characters. */
637
+ description?: string;
634
638
  kind: "gauge";
635
639
  value: number;
636
640
  unit: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Public LogBrew JavaScript SDK for building, validating, and flushing event batches.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",