@logbrew/sdk 0.1.15 → 0.1.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.
Files changed (2) hide show
  1. package/core.cjs +12 -1
  2. package/package.json +1 -1
package/core.cjs CHANGED
@@ -85,6 +85,7 @@ const MAX_DELIVERY_INTERVAL_MS = 60 * 1000;
85
85
  const DEFAULT_DELIVERY_QUEUE_THRESHOLD = 50;
86
86
  const DELIVERY_HEALTH_SCHEMA_VERSION = 1;
87
87
  const EVENT_QUEUE_FACTORY = Symbol.for("@logbrew/sdk.eventQueueFactory");
88
+ const CONTEXT_PROVIDER = Symbol.for("@logbrew/sdk.contextProvider");
88
89
  const MAX_ERROR_CAUSES = 5;
89
90
  const BUILTIN_ERROR_NAMES = new Set([
90
91
  "AggregateError",
@@ -200,6 +201,7 @@ class LogBrewClient {
200
201
  sdkName,
201
202
  sdkVersion,
202
203
  context,
204
+ [CONTEXT_PROVIDER]: contextProvider,
203
205
  maxRetries = 2,
204
206
  eventFilter,
205
207
  maxQueueSize = DEFAULT_MAX_QUEUE_SIZE,
@@ -218,6 +220,9 @@ class LogBrewClient {
218
220
  requireNonEmpty("sdkName", sdkName);
219
221
  requireNonEmpty("sdkVersion", sdkVersion);
220
222
  const clientContext = validateTelemetryContext(context, "client telemetry context");
223
+ if (contextProvider !== undefined && typeof contextProvider !== "function") {
224
+ throw new SdkError("validation_error", "context provider must be a function");
225
+ }
221
226
  requireNonNegativeInteger("maxRetries", maxRetries);
222
227
  if (eventFilter !== undefined && typeof eventFilter !== "function") {
223
228
  throw new SdkError("validation_error", "eventFilter must be a function");
@@ -266,6 +271,7 @@ class LogBrewClient {
266
271
  maxQueueSize,
267
272
  onEventDropped,
268
273
  context: clientContext,
274
+ contextProvider,
269
275
  sdk: {
270
276
  name: sdkName,
271
277
  language: "javascript",
@@ -287,6 +293,7 @@ class LogBrewClient {
287
293
  maxQueueSize,
288
294
  onEventDropped,
289
295
  context,
296
+ contextProvider,
290
297
  eventStore,
291
298
  eventQueueFactory,
292
299
  transport,
@@ -305,6 +312,7 @@ class LogBrewClient {
305
312
  this.maxQueueSize = maxQueueSize;
306
313
  this.onEventDropped = onEventDropped;
307
314
  this.context = cloneTelemetryContext(context);
315
+ this.contextProvider = contextProvider;
308
316
  this.transport = transport;
309
317
  this.sdk = sdk;
310
318
  this.maxRetries = maxRetries;
@@ -624,7 +632,10 @@ class LogBrewClient {
624
632
  }
625
633
  requireNonEmpty("event id", id);
626
634
  requireTimestamp(timestamp);
627
- const context = mergeTelemetryContexts(this.context, attributes.context);
635
+ const context = mergeTelemetryContexts(
636
+ mergeTelemetryContexts(this.context, this.contextProvider?.()),
637
+ attributes.context
638
+ );
628
639
  const eventAttributes = context === undefined
629
640
  ? attributes
630
641
  : { ...attributes, context };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/sdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Public LogBrew JavaScript SDK for building, validating, and flushing event batches.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",