@logbrew/sdk 0.1.27 → 0.1.28
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/core.cjs +40 -16
- package/index.d.ts +10 -0
- package/package.json +1 -1
- package/react-native.d.ts +1 -0
package/core.cjs
CHANGED
|
@@ -17,6 +17,14 @@ const SEVERITY_ALIASES = new Map([
|
|
|
17
17
|
["critical", "critical"]
|
|
18
18
|
]);
|
|
19
19
|
const SEVERITY_VALUES = new Set(SEVERITY_ALIASES.keys());
|
|
20
|
+
const EVENT_ADMISSIONS = Object.freeze({
|
|
21
|
+
admitted: Object.freeze({ status: "admitted" }),
|
|
22
|
+
filtered: Object.freeze({ status: "filtered" }),
|
|
23
|
+
unavailable: Object.freeze({ status: "unavailable" }),
|
|
24
|
+
event_too_large: Object.freeze({ status: "dropped", reason: "event_too_large" }),
|
|
25
|
+
queue_overflow: Object.freeze({ status: "dropped", reason: "queue_overflow" }),
|
|
26
|
+
queue_bytes_overflow: Object.freeze({ status: "dropped", reason: "queue_bytes_overflow" })
|
|
27
|
+
});
|
|
20
28
|
const SPAN_STATUSES = new Set(["ok", "error"]);
|
|
21
29
|
const ACTION_STATUSES = new Set(["queued", "running", "success", "failure"]);
|
|
22
30
|
const PRODUCT_ANALYTICS_SCHEMA_VERSION = 1;
|
|
@@ -197,6 +205,8 @@ class RecordingTransport {
|
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
class LogBrewClient {
|
|
208
|
+
static #issueCapture = LogBrewClient.prototype.issue;
|
|
209
|
+
|
|
200
210
|
static create({
|
|
201
211
|
apiKey,
|
|
202
212
|
sdkName,
|
|
@@ -517,18 +527,16 @@ class LogBrewClient {
|
|
|
517
527
|
}
|
|
518
528
|
|
|
519
529
|
issue(id, timestamp, attributes) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
};
|
|
531
|
-
this.#pushEvent("issue", id, timestamp, validateIssue(withBreadcrumbs));
|
|
530
|
+
this.#pushIssue(id, timestamp, attributes);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
issueWithAdmission(id, timestamp, attributes) {
|
|
534
|
+
const issue = this.issue;
|
|
535
|
+
if (issue !== LogBrewClient.#issueCapture) {
|
|
536
|
+
issue.call(this, id, timestamp, attributes);
|
|
537
|
+
return EVENT_ADMISSIONS.unavailable;
|
|
538
|
+
}
|
|
539
|
+
return this.#pushIssue(id, timestamp, attributes);
|
|
532
540
|
}
|
|
533
541
|
|
|
534
542
|
log(id, timestamp, attributes) {
|
|
@@ -617,6 +625,21 @@ class LogBrewClient {
|
|
|
617
625
|
}
|
|
618
626
|
}
|
|
619
627
|
|
|
628
|
+
#pushIssue(id, timestamp, attributes) {
|
|
629
|
+
const withBreadcrumbs = attributes.breadcrumbs !== undefined || this.issueBreadcrumbs.length === 0
|
|
630
|
+
? attributes
|
|
631
|
+
: {
|
|
632
|
+
...attributes,
|
|
633
|
+
breadcrumbs: this.issueBreadcrumbs,
|
|
634
|
+
...(
|
|
635
|
+
attributes.breadcrumbsTruncated === true || this.issueBreadcrumbsTruncated
|
|
636
|
+
? { breadcrumbsTruncated: true }
|
|
637
|
+
: {}
|
|
638
|
+
)
|
|
639
|
+
};
|
|
640
|
+
return this.#pushEvent("issue", id, timestamp, validateIssue(withBreadcrumbs));
|
|
641
|
+
}
|
|
642
|
+
|
|
620
643
|
#pushEvent(eventType, id, timestamp, attributes) {
|
|
621
644
|
if (this.closed) {
|
|
622
645
|
throw new SdkError("shutdown_error", "client is already shut down");
|
|
@@ -635,21 +658,21 @@ class LogBrewClient {
|
|
|
635
658
|
: { ...attributes, context };
|
|
636
659
|
const event = { type: eventType, id, timestamp, attributes: eventAttributes };
|
|
637
660
|
if (this.eventFilter && this.eventFilter(cloneEvent(event)) === false) {
|
|
638
|
-
return;
|
|
661
|
+
return EVENT_ADMISSIONS.filtered;
|
|
639
662
|
}
|
|
640
663
|
const serializedEvent = JSON.stringify(event);
|
|
641
664
|
const eventBytes = utf8ByteLength(serializedEvent);
|
|
642
665
|
if (this.batchPrefixBytes + eventBytes + this.batchSuffixBytes > this.maxBatchBytes) {
|
|
643
666
|
this.#recordDroppedEvent(event, "event_too_large");
|
|
644
|
-
return;
|
|
667
|
+
return EVENT_ADMISSIONS.event_too_large;
|
|
645
668
|
}
|
|
646
669
|
if (this.events.length >= this.maxQueueSize) {
|
|
647
670
|
this.#recordDroppedEvent(event, "queue_overflow");
|
|
648
|
-
return;
|
|
671
|
+
return EVENT_ADMISSIONS.queue_overflow;
|
|
649
672
|
}
|
|
650
673
|
if (this.queuedEventBytes + eventBytes > this.maxQueueBytes) {
|
|
651
674
|
this.#recordDroppedEvent(event, "queue_bytes_overflow");
|
|
652
|
-
return;
|
|
675
|
+
return EVENT_ADMISSIONS.queue_bytes_overflow;
|
|
653
676
|
}
|
|
654
677
|
if (this.eventStore) {
|
|
655
678
|
requireSynchronousStoreResult("append", this.eventStore.append({
|
|
@@ -663,6 +686,7 @@ class LogBrewClient {
|
|
|
663
686
|
this.serializedEventBytes.push(eventBytes);
|
|
664
687
|
this.queuedEventBytes += eventBytes;
|
|
665
688
|
this.#scheduleAutomaticDelivery();
|
|
689
|
+
return EVENT_ADMISSIONS.admitted;
|
|
666
690
|
}
|
|
667
691
|
|
|
668
692
|
#recordDroppedEvent(event, reason) {
|
package/index.d.ts
CHANGED
|
@@ -849,6 +849,14 @@ export declare class RecordingTransport {
|
|
|
849
849
|
send(apiKey: string, body: string): Promise<TransportResponse>;
|
|
850
850
|
}
|
|
851
851
|
|
|
852
|
+
/** Synchronous queue admission only; this result does not report delivery or retention. */
|
|
853
|
+
export type IssueAdmission = Readonly<
|
|
854
|
+
| { status: "admitted" }
|
|
855
|
+
| { status: "filtered" }
|
|
856
|
+
| { status: "dropped"; reason: DroppedEvent["reason"] }
|
|
857
|
+
| { status: "unavailable" }
|
|
858
|
+
>;
|
|
859
|
+
|
|
852
860
|
/** Buffered public client for validating, previewing, and flushing LogBrew events. */
|
|
853
861
|
export declare class LogBrewClient {
|
|
854
862
|
/** Create a client from public SDK identity, retry, and API key settings. */
|
|
@@ -899,6 +907,8 @@ export declare class LogBrewClient {
|
|
|
899
907
|
release(id: string, timestamp: string, attributes: ReleaseAttributes): void;
|
|
900
908
|
environment(id: string, timestamp: string, attributes: EnvironmentAttributes): void;
|
|
901
909
|
issue(id: string, timestamp: string, attributes: IssueAttributes): void;
|
|
910
|
+
/** Capture once and report queue admission. Custom issue overrides run once and return unavailable. */
|
|
911
|
+
issueWithAdmission(id: string, timestamp: string, attributes: IssueAttributes): IssueAdmission;
|
|
902
912
|
log(id: string, timestamp: string, attributes: LogAttributes): void;
|
|
903
913
|
span(id: string, timestamp: string, attributes: SpanAttributes): void;
|
|
904
914
|
action(id: string, timestamp: string, attributes: ActionAttributes): void;
|
package/package.json
CHANGED