@microsoft/applicationinsights-common 3.3.12-nightly3.2602-20 → 3.4.0-beta

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 (175) hide show
  1. package/README.md +21 -2
  2. package/browser/es5/applicationinsights-common.cjs.js +1089 -289
  3. package/browser/es5/applicationinsights-common.cjs.js.map +1 -1
  4. package/browser/es5/applicationinsights-common.cjs.min.js +2 -2
  5. package/browser/es5/applicationinsights-common.cjs.min.js.map +1 -1
  6. package/browser/es5/applicationinsights-common.gbl.js +1091 -291
  7. package/browser/es5/applicationinsights-common.gbl.js.map +1 -1
  8. package/browser/es5/applicationinsights-common.gbl.min.js +2 -2
  9. package/browser/es5/applicationinsights-common.gbl.min.js.map +1 -1
  10. package/browser/es5/applicationinsights-common.integrity.json +25 -25
  11. package/browser/es5/applicationinsights-common.js +1091 -291
  12. package/browser/es5/applicationinsights-common.js.map +1 -1
  13. package/browser/es5/applicationinsights-common.min.js +2 -2
  14. package/browser/es5/applicationinsights-common.min.js.map +1 -1
  15. package/dist/es5/applicationinsights-common.js +1089 -289
  16. package/dist/es5/applicationinsights-common.js.map +1 -1
  17. package/dist/es5/applicationinsights-common.min.js +2 -2
  18. package/dist/es5/applicationinsights-common.min.js.map +1 -1
  19. package/dist-es5/applicationinsights-common.js +42 -32
  20. package/dist-es5/applicationinsights-common.js.map +1 -1
  21. package/package.json +65 -66
  22. package/types/applicationinsights-common.d.ts +408 -2574
  23. package/types/applicationinsights-common.namespaced.d.ts +2385 -89
  24. package/dist-es5/ConnectionStringParser.js +0 -44
  25. package/dist-es5/ConnectionStringParser.js.map +0 -1
  26. package/dist-es5/Constants.js +0 -22
  27. package/dist-es5/Constants.js.map +0 -1
  28. package/dist-es5/DomHelperFuncs.js +0 -22
  29. package/dist-es5/DomHelperFuncs.js.map +0 -1
  30. package/dist-es5/Enums.js +0 -30
  31. package/dist-es5/Enums.js.map +0 -1
  32. package/dist-es5/HelperFuncs.js +0 -50
  33. package/dist-es5/HelperFuncs.js.map +0 -1
  34. package/dist-es5/Interfaces/ConnectionString.js +0 -6
  35. package/dist-es5/Interfaces/ConnectionString.js.map +0 -1
  36. package/dist-es5/Interfaces/Context/IApplication.js +0 -8
  37. package/dist-es5/Interfaces/Context/IApplication.js.map +0 -1
  38. package/dist-es5/Interfaces/Context/IDevice.js +0 -8
  39. package/dist-es5/Interfaces/Context/IDevice.js.map +0 -1
  40. package/dist-es5/Interfaces/Context/IInternal.js +0 -8
  41. package/dist-es5/Interfaces/Context/IInternal.js.map +0 -1
  42. package/dist-es5/Interfaces/Context/ILocation.js +0 -8
  43. package/dist-es5/Interfaces/Context/ILocation.js.map +0 -1
  44. package/dist-es5/Interfaces/Context/IOperatingSystem.js +0 -8
  45. package/dist-es5/Interfaces/Context/IOperatingSystem.js.map +0 -1
  46. package/dist-es5/Interfaces/Context/ISample.js +0 -8
  47. package/dist-es5/Interfaces/Context/ISample.js.map +0 -1
  48. package/dist-es5/Interfaces/Context/ISession.js +0 -8
  49. package/dist-es5/Interfaces/Context/ISession.js.map +0 -1
  50. package/dist-es5/Interfaces/Context/ISessionManager.js +0 -8
  51. package/dist-es5/Interfaces/Context/ISessionManager.js.map +0 -1
  52. package/dist-es5/Interfaces/Context/ITelemetryTrace.js +0 -8
  53. package/dist-es5/Interfaces/Context/ITelemetryTrace.js.map +0 -1
  54. package/dist-es5/Interfaces/Context/IUser.js +0 -8
  55. package/dist-es5/Interfaces/Context/IUser.js.map +0 -1
  56. package/dist-es5/Interfaces/Context/IWeb.js +0 -8
  57. package/dist-es5/Interfaces/Context/IWeb.js.map +0 -1
  58. package/dist-es5/Interfaces/Contracts/AvailabilityData.js +0 -52
  59. package/dist-es5/Interfaces/Contracts/AvailabilityData.js.map +0 -1
  60. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js +0 -89
  61. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js.map +0 -1
  62. package/dist-es5/Interfaces/Contracts/DataPointType.js +0 -8
  63. package/dist-es5/Interfaces/Contracts/DataPointType.js.map +0 -1
  64. package/dist-es5/Interfaces/Contracts/DependencyKind.js +0 -8
  65. package/dist-es5/Interfaces/Contracts/DependencyKind.js.map +0 -1
  66. package/dist-es5/Interfaces/Contracts/DependencySourceType.js +0 -8
  67. package/dist-es5/Interfaces/Contracts/DependencySourceType.js.map +0 -1
  68. package/dist-es5/Interfaces/Contracts/IBase.js +0 -8
  69. package/dist-es5/Interfaces/Contracts/IBase.js.map +0 -1
  70. package/dist-es5/Interfaces/Contracts/IData.js +0 -8
  71. package/dist-es5/Interfaces/Contracts/IData.js.map +0 -1
  72. package/dist-es5/Interfaces/Contracts/IDataPoint.js +0 -6
  73. package/dist-es5/Interfaces/Contracts/IDataPoint.js.map +0 -1
  74. package/dist-es5/Interfaces/Contracts/IDomain.js +0 -8
  75. package/dist-es5/Interfaces/Contracts/IDomain.js.map +0 -1
  76. package/dist-es5/Interfaces/Contracts/IEnvelope.js +0 -46
  77. package/dist-es5/Interfaces/Contracts/IEnvelope.js.map +0 -1
  78. package/dist-es5/Interfaces/Contracts/IEventData.js +0 -8
  79. package/dist-es5/Interfaces/Contracts/IEventData.js.map +0 -1
  80. package/dist-es5/Interfaces/Contracts/IExceptionData.js +0 -8
  81. package/dist-es5/Interfaces/Contracts/IExceptionData.js.map +0 -1
  82. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js +0 -8
  83. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js.map +0 -1
  84. package/dist-es5/Interfaces/Contracts/IMessageData.js +0 -8
  85. package/dist-es5/Interfaces/Contracts/IMessageData.js.map +0 -1
  86. package/dist-es5/Interfaces/Contracts/IMetricData.js +0 -8
  87. package/dist-es5/Interfaces/Contracts/IMetricData.js.map +0 -1
  88. package/dist-es5/Interfaces/Contracts/IPageViewData.js +0 -8
  89. package/dist-es5/Interfaces/Contracts/IPageViewData.js.map +0 -1
  90. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js +0 -8
  91. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js.map +0 -1
  92. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js +0 -8
  93. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js.map +0 -1
  94. package/dist-es5/Interfaces/Contracts/IStackFrame.js +0 -8
  95. package/dist-es5/Interfaces/Contracts/IStackFrame.js.map +0 -1
  96. package/dist-es5/Interfaces/Contracts/RequestData.js +0 -46
  97. package/dist-es5/Interfaces/Contracts/RequestData.js.map +0 -1
  98. package/dist-es5/Interfaces/Contracts/SeverityLevel.js +0 -18
  99. package/dist-es5/Interfaces/Contracts/SeverityLevel.js.map +0 -1
  100. package/dist-es5/Interfaces/IAppInsights.js +0 -8
  101. package/dist-es5/Interfaces/IAppInsights.js.map +0 -1
  102. package/dist-es5/Interfaces/IConfig.js +0 -26
  103. package/dist-es5/Interfaces/IConfig.js.map +0 -1
  104. package/dist-es5/Interfaces/ICorrelationConfig.js +0 -8
  105. package/dist-es5/Interfaces/ICorrelationConfig.js.map +0 -1
  106. package/dist-es5/Interfaces/IDependencyTelemetry.js +0 -8
  107. package/dist-es5/Interfaces/IDependencyTelemetry.js.map +0 -1
  108. package/dist-es5/Interfaces/IEventTelemetry.js +0 -6
  109. package/dist-es5/Interfaces/IEventTelemetry.js.map +0 -1
  110. package/dist-es5/Interfaces/IExceptionTelemetry.js +0 -8
  111. package/dist-es5/Interfaces/IExceptionTelemetry.js.map +0 -1
  112. package/dist-es5/Interfaces/IMetricTelemetry.js +0 -6
  113. package/dist-es5/Interfaces/IMetricTelemetry.js.map +0 -1
  114. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js +0 -6
  115. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js.map +0 -1
  116. package/dist-es5/Interfaces/IPageViewTelemetry.js +0 -6
  117. package/dist-es5/Interfaces/IPageViewTelemetry.js.map +0 -1
  118. package/dist-es5/Interfaces/IPartC.js +0 -8
  119. package/dist-es5/Interfaces/IPartC.js.map +0 -1
  120. package/dist-es5/Interfaces/IPropertiesPlugin.js +0 -8
  121. package/dist-es5/Interfaces/IPropertiesPlugin.js.map +0 -1
  122. package/dist-es5/Interfaces/IRequestContext.js +0 -6
  123. package/dist-es5/Interfaces/IRequestContext.js.map +0 -1
  124. package/dist-es5/Interfaces/IStorageBuffer.js +0 -6
  125. package/dist-es5/Interfaces/IStorageBuffer.js.map +0 -1
  126. package/dist-es5/Interfaces/ITelemetryContext.js +0 -8
  127. package/dist-es5/Interfaces/ITelemetryContext.js.map +0 -1
  128. package/dist-es5/Interfaces/IThrottleMgr.js +0 -6
  129. package/dist-es5/Interfaces/IThrottleMgr.js.map +0 -1
  130. package/dist-es5/Interfaces/ITraceTelemetry.js +0 -8
  131. package/dist-es5/Interfaces/ITraceTelemetry.js.map +0 -1
  132. package/dist-es5/Interfaces/PartAExtensions.js +0 -17
  133. package/dist-es5/Interfaces/PartAExtensions.js.map +0 -1
  134. package/dist-es5/Interfaces/Telemetry/IEnvelope.js +0 -8
  135. package/dist-es5/Interfaces/Telemetry/IEnvelope.js.map +0 -1
  136. package/dist-es5/Interfaces/Telemetry/ISerializable.js +0 -8
  137. package/dist-es5/Interfaces/Telemetry/ISerializable.js.map +0 -1
  138. package/dist-es5/Offline.js +0 -137
  139. package/dist-es5/Offline.js.map +0 -1
  140. package/dist-es5/RequestResponseHeaders.js +0 -19
  141. package/dist-es5/RequestResponseHeaders.js.map +0 -1
  142. package/dist-es5/StorageHelperFuncs.js +0 -184
  143. package/dist-es5/StorageHelperFuncs.js.map +0 -1
  144. package/dist-es5/Telemetry/Common/Data.js +0 -25
  145. package/dist-es5/Telemetry/Common/Data.js.map +0 -1
  146. package/dist-es5/Telemetry/Common/DataPoint.js +0 -29
  147. package/dist-es5/Telemetry/Common/DataPoint.js.map +0 -1
  148. package/dist-es5/Telemetry/Common/DataSanitizer.js +0 -129
  149. package/dist-es5/Telemetry/Common/DataSanitizer.js.map +0 -1
  150. package/dist-es5/Telemetry/Common/Envelope.js +0 -38
  151. package/dist-es5/Telemetry/Common/Envelope.js.map +0 -1
  152. package/dist-es5/Telemetry/Event.js +0 -32
  153. package/dist-es5/Telemetry/Event.js.map +0 -1
  154. package/dist-es5/Telemetry/Exception.js +0 -759
  155. package/dist-es5/Telemetry/Exception.js.map +0 -1
  156. package/dist-es5/Telemetry/Metric.js +0 -39
  157. package/dist-es5/Telemetry/Metric.js.map +0 -1
  158. package/dist-es5/Telemetry/PageView.js +0 -41
  159. package/dist-es5/Telemetry/PageView.js.map +0 -1
  160. package/dist-es5/Telemetry/PageViewPerformance.js +0 -48
  161. package/dist-es5/Telemetry/PageViewPerformance.js.map +0 -1
  162. package/dist-es5/Telemetry/RemoteDependencyData.js +0 -62
  163. package/dist-es5/Telemetry/RemoteDependencyData.js.map +0 -1
  164. package/dist-es5/Telemetry/Trace.js +0 -36
  165. package/dist-es5/Telemetry/Trace.js.map +0 -1
  166. package/dist-es5/TelemetryItemCreator.js +0 -65
  167. package/dist-es5/TelemetryItemCreator.js.map +0 -1
  168. package/dist-es5/ThrottleMgr.js +0 -388
  169. package/dist-es5/ThrottleMgr.js.map +0 -1
  170. package/dist-es5/UrlHelperFuncs.js +0 -90
  171. package/dist-es5/UrlHelperFuncs.js.map +0 -1
  172. package/dist-es5/Util.js +0 -198
  173. package/dist-es5/Util.js.map +0 -1
  174. package/dist-es5/__DynamicConstants.js +0 -44
  175. package/dist-es5/__DynamicConstants.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Common JavaScript Library, 3.3.12-nightly3.2602-20
2
+ * Microsoft Application Insights Common JavaScript Library, 3.4.0-beta
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -83,6 +83,8 @@ declare namespace ApplicationInsights {
83
83
  * @param telemetryTrace - The telemetryTrace instance that is being wrapped
84
84
  * @param parentCtx - An optional parent distributed trace instance, almost always undefined as this scenario is only used in the case of multiple property handlers.
85
85
  * @returns A new IDistributedTraceContext instance that is backed by the telemetryTrace or temporary object
86
+ * @deprecated This function is deprecated and will be removed in a future version. Use the createDistributedTraceContext function instead and set the necessary properties
87
+ * on the context object directly.
86
88
  */
87
89
  function createDistributedTraceContextFromTrace(telemetryTrace?: ITelemetryTrace, parentCtx?: IDistributedTraceContext): IDistributedTraceContext;
88
90
 
@@ -121,6 +123,10 @@ declare namespace ApplicationInsights {
121
123
 
122
124
  let CtxTagKeys: ContextTagKeys;
123
125
 
126
+ /**
127
+ * @deprecated - will be removed in future releases as this was only used by the applicationinsights-channel-js package.
128
+ * And it no longer uses this class.
129
+ */
124
130
  class Data<TDomain> implements AIData<TDomain>, ISerializable {
125
131
  /**
126
132
  * The data contract for serializing this object.
@@ -285,19 +291,125 @@ declare namespace ApplicationInsights {
285
291
  PENDING = 3
286
292
  }
287
293
 
294
+ /**
295
+ * Const enum for attribute change operation types
296
+ */
297
+ const enum eAttributeChangeOp {
298
+ /**
299
+ * Clear operation - clearing all attributes
300
+ */
301
+ Clear = 0,
302
+ /**
303
+ * Set operation - setting an attribute value (generic)
304
+ */
305
+ Set = 1,
306
+ /**
307
+ * Add operation - adding a new attribute that didn't exist before
308
+ */
309
+ Add = 2,
310
+ /**
311
+ * Delete operation - deleting an attribute
312
+ */
313
+ Delete = 3,
314
+ /**
315
+ * Dropped attributes - attributes that were dropped due to size limits
316
+ */
317
+ DroppedAttributes = 4
318
+ }
319
+
320
+ /**
321
+ * Identifies the source of an attribute value in iterator operations
322
+ * @since 3.4.0
323
+ */
324
+ const enum eAttributeFilter {
325
+ /**
326
+ * The attribute exists local to the current container instance
327
+ */
328
+ Local = 0,
329
+ /**
330
+ * The attribute does not exist locally and is inherited from a parent container or attributes object
331
+ */
332
+ Inherited = 1,
333
+ /**
334
+ * The attribute exists or has been deleted locally (only) to the current container instance
335
+ */
336
+ LocalOrDeleted = 2
337
+ }
338
+
288
339
  const enum eDistributedTracingModes {
289
340
  /**
290
- * (Default) Send Application Insights correlation headers
341
+ * Send only the legacy Application Insights correlation headers
342
+ *
343
+ * Headers Sent:
344
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
345
+ *
346
+ * Config Decimal Value: `0` (Zero)
291
347
  */
292
348
  AI = 0,
293
349
  /**
294
- * Send both W3C Trace Context headers and back-compatibility Application Insights headers
350
+ * (Default) Send both W3C Trace parent header and back-compatibility Application Insights headers
351
+ * - `Request-Id`
352
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
353
+ *
354
+ * Config Decimal Value: `1` (One)
295
355
  */
296
356
  AI_AND_W3C = 1,
297
357
  /**
298
- * Send W3C Trace Context headers
358
+ * Send Only the W3C Trace parent header
359
+ *
360
+ * Headers Sent:
361
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
362
+ *
363
+ * Config Decimal Value: `2` (Two)
364
+ */
365
+ W3C = 2,
366
+ /**
367
+ * @internal
368
+ * Bitwise mask used to separate the base distributed tracing mode from the additional optional
369
+ * tracing modes.
370
+ * @since 3.4.0
371
+ */
372
+ _BaseMask = 15,
373
+ /**
374
+ * @internal
375
+ * Enabling this bit will send the W3C Trace State header, it is not intended to be used directly
376
+ * or on its own. The code may assume that if this bit is set, then the W3C Trace Context headers
377
+ * will also be included.
378
+ *
379
+ * Config Decimal Value: `16` (Sixteen in decimal)
380
+ * @since 3.4.0
381
+ */
382
+ _W3CTraceState = 16,
383
+ /**
384
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers and back-compatibility
385
+ * Application Insights headers.
386
+ *
387
+ * Currently sent headers:
388
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
389
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
390
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
391
+ *
392
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
393
+ * to include additional headers.
394
+ *
395
+ * Config Decimal Value: `17` (Seventeen in decimal)
396
+ * @since 3.4.0
397
+ */
398
+ AI_AND_W3C_TRACE = 17,
399
+ /**
400
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers.
401
+ *
402
+ * Currently sent headers:
403
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
404
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
405
+ *
406
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
407
+ * to include additional headers.
408
+ *
409
+ * Config Decimal Value: `18` (Eighteen in decimal)
410
+ * @since 3.4.0
299
411
  */
300
- W3C = 2
412
+ W3C_TRACE = 18
301
413
  }
302
414
 
303
415
  const enum _eInternalMessageId {
@@ -392,7 +504,12 @@ declare namespace ApplicationInsights {
392
504
  SdkLdrUpdate = 111,
393
505
  InitPromiseException = 112,
394
506
  StatsBeatManagerException = 113,
395
- StatsBeatException = 114
507
+ StatsBeatException = 114,
508
+ AttributeError = 115,
509
+ SpanError = 116,
510
+ TraceError = 117,
511
+ NotImplementedError = 118,
512
+ VersionMismatch = 119
396
513
  }
397
514
 
398
515
  const enum eLoggingSeverity {
@@ -482,6 +599,57 @@ declare namespace ApplicationInsights {
482
599
  Offline = 2
483
600
  }
484
601
 
602
+ /**
603
+ * The defined set of Span Kinds as defined by the OpenTelemetry.
604
+ */
605
+ const enum eOTelSpanKind {
606
+ /** Default value. Indicates that the span is used internally. */
607
+ INTERNAL = 0,
608
+ /**
609
+ * Indicates that the span covers server-side handling of an RPC or other
610
+ * remote request.
611
+ */
612
+ SERVER = 1,
613
+ /**
614
+ * Indicates that the span covers the client-side wrapper around an RPC or
615
+ * other remote request.
616
+ */
617
+ CLIENT = 2,
618
+ /**
619
+ * Indicates that the span describes producer sending a message to a
620
+ * broker. Unlike client and server, there is no direct critical path latency
621
+ * relationship between producer and consumer spans.
622
+ */
623
+ PRODUCER = 3,
624
+ /**
625
+ * Indicates that the span describes consumer receiving a message from a
626
+ * broker. Unlike client and server, there is no direct critical path latency
627
+ * relationship between producer and consumer spans.
628
+ */
629
+ CONSUMER = 4
630
+ }
631
+
632
+ /**
633
+ * An enumeration of status codes, matching the OpenTelemetry specification.
634
+ *
635
+ * @since 3.4.0
636
+ */
637
+ const enum eOTelSpanStatusCode {
638
+ /**
639
+ * The default status.
640
+ */
641
+ UNSET = 0,
642
+ /**
643
+ * The operation has been validated by an Application developer or
644
+ * Operator to have completed successfully.
645
+ */
646
+ OK = 1,
647
+ /**
648
+ * The operation contains an error.
649
+ */
650
+ ERROR = 2
651
+ }
652
+
485
653
  const enum eRequestHeaders {
486
654
  requestContextHeader = 0,
487
655
  requestContextTargetKey = 1,
@@ -505,8 +673,38 @@ declare namespace ApplicationInsights {
505
673
  Critical = 4
506
674
  }
507
675
 
676
+ /**
677
+ * Controls how the SDK should look for trace headers (traceparent/tracestate) from the initial page load
678
+ * The values are bitwise OR'd together to allow for multiple values to be set at once.
679
+ * @since 3.4.0
680
+ */
681
+ const enum eTraceHeadersMode {
682
+ /**
683
+ * Don't look for any trace headers
684
+ */
685
+ None = 0,
686
+ /**
687
+ * Look for traceparent header/meta tag
688
+ */
689
+ TraceParent = 1,
690
+ /**
691
+ * Look for tracestate header/meta tag
692
+ */
693
+ TraceState = 2,
694
+ /**
695
+ * Look for both traceparent and tracestate headers/meta tags
696
+ */
697
+ All = 3
698
+ }
699
+
508
700
  class Event_2 implements IEventData, ISerializable {
701
+ /**
702
+ * @deprecated Use the constant EventEnvelopeType instead.
703
+ */
509
704
  static envelopeType: string;
705
+ /**
706
+ * @deprecated Use the constant EventDataType instead.
707
+ */
510
708
  static dataType: string;
511
709
  aiDataContract: {
512
710
  ver: FieldType;
@@ -537,6 +735,10 @@ declare namespace ApplicationInsights {
537
735
  }
538
736
  const Event: typeof Event_2;
539
737
 
738
+ const EventDataType = "EventData";
739
+
740
+ const EventEnvelopeType: string;
741
+
540
742
  /**
541
743
  * The EventPersistence contains a set of values that specify the event's persistence.
542
744
  */
@@ -559,7 +761,13 @@ declare namespace ApplicationInsights {
559
761
  }
560
762
 
561
763
  class Exception implements IExceptionData, ISerializable {
764
+ /**
765
+ * @deprecated Use the constant ExceptionEnvelopeType instead.
766
+ */
562
767
  static envelopeType: string;
768
+ /**
769
+ * @deprecated Use the constant ExceptionDataType instead.
770
+ */
563
771
  static dataType: string;
564
772
  id?: string;
565
773
  problemGroup?: string;
@@ -611,6 +819,10 @@ declare namespace ApplicationInsights {
611
819
  static formatError: typeof _formatErrorCode;
612
820
  }
613
821
 
822
+ const ExceptionDataType = "ExceptionData";
823
+
824
+ const ExceptionEnvelopeType: string;
825
+
614
826
  const Extensions: {
615
827
  UserExt: string;
616
828
  DeviceExt: string;
@@ -726,8 +938,7 @@ declare namespace ApplicationInsights {
726
938
  }): void;
727
939
  }
728
940
 
729
- interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
730
- readonly config: CfgType;
941
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider, ITraceHost<CfgType> {
731
942
  /**
732
943
  * The current logger instance for this instance.
733
944
  */
@@ -848,14 +1059,13 @@ declare namespace ApplicationInsights {
848
1059
  */
849
1060
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
850
1061
  /**
851
- * Gets the current distributed trace context for this instance if available
852
- * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
853
- */
854
- getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
855
- /**
856
- * Sets the current distributed trace context for this instance if available
1062
+ * Set the trace provider for creating spans.
1063
+ * This allows different SKUs to provide their own span implementations.
1064
+ *
1065
+ * @param provider - The trace provider to use for span creation
1066
+ * @since 3.4.0
857
1067
  */
858
- setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
1068
+ setTraceProvider(provider: ICachedValue<ITraceProvider>): void;
859
1069
  /**
860
1070
  * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
861
1071
  * handler will be recalled.
@@ -894,6 +1104,150 @@ declare namespace ApplicationInsights {
894
1104
  build: string;
895
1105
  }
896
1106
 
1107
+ /**
1108
+ * Information about what changed in an attribute container
1109
+ */
1110
+ interface IAttributeChangeInfo<V extends OTelAttributeValue = OTelAttributeValue> {
1111
+ /**
1112
+ * The Id of the container that is initiated the change (not the immediate sender -- which is always the parent)
1113
+ * As children only receive listener notifications from their parent in reaction to both changes
1114
+ * they make and any changes they receive from their parent
1115
+ */
1116
+ frm: string;
1117
+ /**
1118
+ * Operation type that occurred
1119
+ */
1120
+ op: eAttributeChangeOp;
1121
+ /**
1122
+ * The key that was changed (only present for 'set' operations)
1123
+ */
1124
+ k?: string;
1125
+ /**
1126
+ * The old value (only present for 'set' operations when replacing existing value)
1127
+ */
1128
+ prev?: V;
1129
+ /**
1130
+ * The new value (only present for 'set' operations)
1131
+ */
1132
+ val?: V;
1133
+ }
1134
+
1135
+ /**
1136
+ * Interface for an attribute container
1137
+ * @since 3.4.0
1138
+ */
1139
+ interface IAttributeContainer<V extends OTelAttributeValue = OTelAttributeValue> {
1140
+ /**
1141
+ * Unique identifier for the attribute container
1142
+ */
1143
+ readonly id: string;
1144
+ /**
1145
+ * The number of attributes that have been set
1146
+ * @returns The number of attributes that have been set
1147
+ */
1148
+ readonly size: number;
1149
+ /**
1150
+ * The number of attributes that were dropped due to the attribute limit being reached
1151
+ * @returns The number of attributes that were dropped due to the attribute limit being reached
1152
+ */
1153
+ readonly droppedAttributes: number;
1154
+ /**
1155
+ * Return a snapshot of the current attributes, including inherited ones.
1156
+ * This value is read-only and reflects the state of the attributes at the time of access,
1157
+ * and the returned instance will not change if any attributes are modified later, you will need
1158
+ * to access the attributes property again to get the latest state.
1159
+ *
1160
+ * Note: As this causes a snapshot to be taken, it is an expensive operation as it enumerates all
1161
+ * attributes, so you SHOULD use this property sparingly.
1162
+ * @returns A read-only snapshot of the current attributes
1163
+ */
1164
+ readonly attributes: IOTelAttributes;
1165
+ /**
1166
+ * Clear all existing attributes from the container, this will also remove any inherited attributes
1167
+ * from this instance only (it will not change the inherited attributes / container(s))
1168
+ */
1169
+ clear: () => void;
1170
+ /**
1171
+ * Get the value of an attribute by key
1172
+ * @param key - The attribute key to retrieve
1173
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
1174
+ * @returns The attribute value if found, undefined otherwise
1175
+ */
1176
+ get: (key: string, source?: eAttributeFilter) => V | undefined;
1177
+ /**
1178
+ * Check if an attribute exists by key
1179
+ * @param key - The attribute key to check
1180
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
1181
+ * @returns True if the attribute exists, false otherwise
1182
+ */
1183
+ has: (key: string, source?: eAttributeFilter) => boolean;
1184
+ /**
1185
+ * Set the value of an attribute by key on this instance.
1186
+ * @param key - The attribute key to set
1187
+ * @param value - The value to assign to the named attribute
1188
+ * @returns true if the value was successfully set / replaced
1189
+ */
1190
+ set: (key: string, value: V) => boolean;
1191
+ /**
1192
+ * Delete an existing attribute, if the key doesn't exist this will return false. If the key does
1193
+ * exist then it will be removed from this instance and any inherited value will be hidden (even if
1194
+ * the inherited value changes)
1195
+ * @param key - The attribute key to delete
1196
+ * @returns True if the attribute was deleted, false if it didn't exist (which includes if it has already been deleted)
1197
+ */
1198
+ del: (key: string) => boolean;
1199
+ /**
1200
+ * The keys() method returns a new iterator object that contains the existing keys for each element
1201
+ * in this attribute container. It will return all locally set keys first and then the inherited keys.
1202
+ * When a key exists in both the local and inherited attributes, only the local key will be returned.
1203
+ * If the key has been deleted locally, it will not be included in the iterator.
1204
+ * @returns An iterator over the keys of the attribute container
1205
+ */
1206
+ keys: () => Iterator<string>;
1207
+ /**
1208
+ * The entries() method of returns a new iterator object that contains the [key, value, source?] tuples for
1209
+ * each attribute, it returns all existing attributes of this instance including all inherited ones. If the
1210
+ * same key exists in both the local and inherited attributes, only the first (non-deleted) tuple will be returned.
1211
+ * If the key has been deleted, it will not be included in the iterator.
1212
+ *
1213
+ * The source value of the tuple identifies the origin of the attribute (Local or Inherited).
1214
+ * @returns An iterator over the entries of the attribute container
1215
+ */
1216
+ entries: () => Iterator<[string, V, eAttributeFilter]>;
1217
+ /**
1218
+ * The forEach() method of executes a provided function once per each key/value pair in this attribute container,
1219
+ * it will process all local attributes first, then the inherited attributes. If the same key exists in both the
1220
+ * local and inherited attributes, only the first (non-deleted) key/value pair will be processed.
1221
+ * If a key has been deleted, it will not be included in the set of processed key/value pairs.
1222
+ * @param callback - The function to execute for each key/value pair
1223
+ * @param thisArg - Optional value to use as `this` when executing `callback`
1224
+ */
1225
+ forEach: (callback: (key: string, value: V, source?: eAttributeFilter) => void, thisArg?: any) => void;
1226
+ /**
1227
+ * The values() method returns a new iterator instance that contains the values for each element in this
1228
+ * attribute container. It will return all locally set values first and then the inherited values. If the
1229
+ * same key is present in both the local or inherited attributes only the first (non-deleted) value will be
1230
+ * returned. If a key has been deleted, it will not be included in the iterator.
1231
+ * @returns An iterator over the values of the attribute container
1232
+ */
1233
+ values: () => Iterator<V>;
1234
+ /**
1235
+ * Register a callback listener for any attribute changes, this will include local and inherited changes.
1236
+ * @param callback - Function to be called when attributes change, receives change information
1237
+ * @returns IUnloadHook instance with rm() function to remove this listener, once called it will never be invoked again
1238
+ */
1239
+ listen: (callback: (changeInfo: IAttributeChangeInfo<V>) => void) => IUnloadHook;
1240
+ /**
1241
+ * Create a child attribute container that inherits from this one, optionally taking a snapshot
1242
+ * so that any future changes to the parent container do not affect the child container.
1243
+ * The child will use all of the configuration from the parent container.
1244
+ * @param name - Optional name for the child container
1245
+ * @param snapshot - If true, the child container will be a snapshot of the current state
1246
+ * @returns A new attribute container instance
1247
+ */
1248
+ child: (name?: string, snapshot?: boolean) => IAttributeContainer;
1249
+ }
1250
+
897
1251
  /**
898
1252
  * @description window.onerror function parameters
899
1253
  * @export
@@ -952,9 +1306,12 @@ declare namespace ApplicationInsights {
952
1306
  */
953
1307
  getCfg: () => IConfiguration;
954
1308
  /**
955
- * Gets the named extension config
1309
+ * Gets the named extension configuration
1310
+ * @param identifier - The named extension identifier
1311
+ * @param defaultValue - The default value(s) to return if no defined config exists
1312
+ * @param rootOnly - If true, only the look for the configuration in the top level and not in the "extensionConfig"
956
1313
  */
957
- getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
1314
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>, rootOnly?: boolean) => T;
958
1315
  /**
959
1316
  * Gets the named config from either the named identifier extension or core config if neither exist then the
960
1317
  * default value is returned
@@ -999,6 +1356,30 @@ declare namespace ApplicationInsights {
999
1356
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
1000
1357
  }
1001
1358
 
1359
+ /**
1360
+ * A generic interface for holding a cached value
1361
+ * @since 0.10.5
1362
+ * @group Helpers
1363
+ * @group Cache
1364
+ * @typeParam T - The type of the value to be cached
1365
+ * @example
1366
+ * ```ts
1367
+ * let cachedValue: ICachedValue<string> = {
1368
+ * v: "some value"
1369
+ * };
1370
+ * ```
1371
+ */
1372
+ interface ICachedValue<T> {
1373
+ /**
1374
+ * Returns the current cached value
1375
+ */
1376
+ v: T;
1377
+ /**
1378
+ * Returns the current cached value
1379
+ */
1380
+ toJSON(): T;
1381
+ }
1382
+
1002
1383
  /**
1003
1384
  * Provides data transmission capabilities
1004
1385
  */
@@ -1443,7 +1824,7 @@ declare namespace ApplicationInsights {
1443
1824
  /**
1444
1825
  * Configuration provided to SDK core
1445
1826
  */
1446
- interface IConfiguration {
1827
+ interface IConfiguration extends IOTelConfig {
1447
1828
  /**
1448
1829
  * Instrumentation key of resource. Either this or connectionString must be specified.
1449
1830
  */
@@ -1645,6 +2026,12 @@ declare namespace ApplicationInsights {
1645
2026
  * @example ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature","auth_token", "api_key", "private_data"]
1646
2027
  */
1647
2028
  redactQueryParams?: string[];
2029
+ /**
2030
+ * [Optional] Controls if the SDK should look for the `traceparent` and/or `tracestate` values from
2031
+ * the service timing headers or meta tags from the initial page load.
2032
+ * @defaultValue eTraceHeadersMode.All
2033
+ */
2034
+ traceHdrMode?: eTraceHeadersMode;
1648
2035
  }
1649
2036
 
1650
2037
  interface IContextTagKeys {
@@ -1936,9 +2323,68 @@ declare namespace ApplicationInsights {
1936
2323
 
1937
2324
  interface ICorrelationConfig {
1938
2325
  enableCorsCorrelation: boolean;
2326
+ /**
2327
+ * [Optional] Domains to be excluded from correlation headers.
2328
+ * To override or discard the default, add an array with all domains to be excluded or
2329
+ * an empty array to the configuration.
2330
+ *
2331
+ * @example
2332
+ * ```ts
2333
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
2334
+ * const appInsights = new ApplicationInsights({
2335
+ * config: {
2336
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
2337
+ * extensionConfig: {
2338
+ * AjaxDependencyPlugin: {
2339
+ * // Both arrays of strings are used to match the request URL against the
2340
+ * // current host and the request URL to determine if correlation headers
2341
+ * // The strings are converted to RegExp objects by translating
2342
+ * // - `.` to `\\.` (to match a literal dot)
2343
+ * // - `*` to `.*` (to match any character)
2344
+ * // - `\` to `\\` (to match a literal slash)
2345
+ * // All other characters are ignored and passed to the RegExp constructor
2346
+ * correlationHeaderExcludedDomains: ["test", "*.azure.com", "ignore.microsoft.com"],
2347
+ * correlationHeaderDomains: ["azure.com", "prefix.bing.com", "*.microsoft.com", "example.com"]
2348
+ * }
2349
+ * }
2350
+ * });
2351
+ * appInsights.loadAppInsights();
2352
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
2353
+ * ```
2354
+ */
1939
2355
  correlationHeaderExcludedDomains: string[];
2356
+ /**
2357
+ * [Optional] Domains to be included in correlation headers.
2358
+ * To override or discard the default, add an array with all domains to be included or
2359
+ * an empty array to the configuration.
2360
+ *
2361
+ * @example
2362
+ * ```ts
2363
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
2364
+ * const appInsights = new ApplicationInsights({
2365
+ * config: {
2366
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
2367
+ * extensionConfig: {
2368
+ * AjaxDependencyPlugin: {
2369
+ * // Values MUST be RegExp objects
2370
+ * correlationHeaderExcludePatterns: [/*\.azure.com/, /prefix.bing.com/, /.*\.microsoft.com/, /example.com/]
2371
+ * }
2372
+ * }
2373
+ * });
2374
+ * appInsights.loadAppInsights();
2375
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
2376
+ * ```
2377
+ */
1940
2378
  correlationHeaderExcludePatterns?: RegExp[];
1941
2379
  disableCorrelationHeaders: boolean;
2380
+ /**
2381
+ * The distributed tracing mode to use for this configuration.
2382
+ * Defaults to AI_AND_W3C.
2383
+ * This is used to determine which headers are sent with requests and how the
2384
+ * telemetry is correlated across services.
2385
+ * @default AI_AND_W3C
2386
+ * @see {@link eDistributedTracingModes}
2387
+ */
1942
2388
  distributedTracingMode: DistributedTracingModes;
1943
2389
  maxAjaxCallsPerView: number;
1944
2390
  disableAjaxTracking: boolean;
@@ -1966,6 +2412,35 @@ declare namespace ApplicationInsights {
1966
2412
  * Defaults to 25.
1967
2413
  */
1968
2414
  ajaxPerfLookupDelay?: number;
2415
+ /**
2416
+ * [Optional] Domains to be excluded from correlation headers.
2417
+ * To override or discard the default, add an array with all domains to be excluded or
2418
+ * an empty array to the configuration.
2419
+ *
2420
+ * @example
2421
+ * ```ts
2422
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
2423
+ * const appInsights = new ApplicationInsights({
2424
+ * config: {
2425
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
2426
+ * extensionConfig: {
2427
+ * AjaxDependencyPlugin: {
2428
+ * // Both arrays of strings are used to match the request URL against the
2429
+ * // current host and the request URL to determine if correlation headers
2430
+ * // The strings are converted to RegExp objects by translating
2431
+ * // - `.` to `\\.` (to match a literal dot)
2432
+ * // - `*` to `.*` (to match any character)
2433
+ * // - `\` to `\\` (to match a literal slash)
2434
+ * // All other characters are ignored and passed to the RegExp constructor
2435
+ * correlationHeaderExcludedDomains: ["test", "*.azure.com", "ignore.microsoft.com"],
2436
+ * correlationHeaderDomains: ["azure.com", "prefix.bing.com", "*.microsoft.com", "example.com"]
2437
+ * }
2438
+ * }
2439
+ * });
2440
+ * appInsights.loadAppInsights();
2441
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
2442
+ * ```
2443
+ */
1969
2444
  correlationHeaderDomains?: string[];
1970
2445
  /**
1971
2446
  * [Optional] Response and request headers to be excluded from AJAX & Fetch tracking data.
@@ -1985,7 +2460,7 @@ declare namespace ApplicationInsights {
1985
2460
  * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
1986
2461
  * extensions: [dependencyPlugin],
1987
2462
  * extensionConfig: {
1988
- * [dependencyPlugin.identifier]: {
2463
+ * AjaxDependencyPlugin: {
1989
2464
  * ignoreHeaders: [
1990
2465
  * "Authorization",
1991
2466
  * "X-API-Key",
@@ -2108,7 +2583,7 @@ declare namespace ApplicationInsights {
2108
2583
  /**
2109
2584
  * The internal logging queue
2110
2585
  */
2111
- queue: _InternalLogMessage[];
2586
+ queue: IInternalLogMessage[];
2112
2587
  /**
2113
2588
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
2114
2589
  * @param severity - The severity of the log message
@@ -2141,7 +2616,7 @@ declare namespace ApplicationInsights {
2141
2616
  * @param severity - The severity of the log message
2142
2617
  * @param message - The message to log.
2143
2618
  */
2144
- logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
2619
+ logInternalMessage?(severity: LoggingSeverity, message: IInternalLogMessage): void;
2145
2620
  /**
2146
2621
  * Optional Callback hook to allow the diagnostic logger to update it's configuration
2147
2622
  * @param updateState - The new configuration state to apply to the diagnostic logger
@@ -2156,16 +2631,25 @@ declare namespace ApplicationInsights {
2156
2631
  * / Promise to allow any listeners to wait for the operation to complete.
2157
2632
  */
2158
2633
  unload?(isAsync?: boolean): void | IPromise<void>;
2634
+ /**
2635
+ * A flag that indicates whether this logger is in debug (throw real exceptions) mode
2636
+ */
2637
+ readonly dbgMode?: boolean;
2159
2638
  }
2160
2639
 
2161
- interface IDistributedTraceContext {
2640
+ interface IDistributedTraceContext extends IDistributedTraceInit {
2162
2641
  /**
2163
2642
  * Returns the current name of the page
2164
2643
  */
2165
2644
  getName(): string;
2166
2645
  /**
2167
- * Sets the current name of the page
2646
+ * Sets the current name of the page, also updates the name for any parent context.
2647
+ * This is used to identify the page in the telemetry data.
2648
+ * @remarks This function updates the current and ALL parent contexts with the new name,
2649
+ * to just update the name of the current context, use the `pageName` property.
2168
2650
  * @param pageName - The name of the page
2651
+ * @deprecated Use the `pageName` property to avoid the side effect of changing the page name of all
2652
+ * parent contexts.
2169
2653
  */
2170
2654
  setName(pageName: string): void;
2171
2655
  /**
@@ -2178,6 +2662,12 @@ declare namespace ApplicationInsights {
2178
2662
  * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
2179
2663
  * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
2180
2664
  * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
2665
+ *
2666
+ * @remarks Sets the traceId for the current context AND all parent contexts, if you want to set the traceId
2667
+ * for the current context only, use the `traceId` property.
2668
+ * @param newValue - The traceId to set
2669
+ * @deprecated Use the `traceId` property to avoid the side effect of changing the traceId of all
2670
+ * parent contexts.
2181
2671
  */
2182
2672
  setTraceId(newValue: string): void;
2183
2673
  /**
@@ -2189,6 +2679,12 @@ declare namespace ApplicationInsights {
2189
2679
  * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
2190
2680
  * Also know as the parentId, used to link requests together
2191
2681
  * https://www.w3.org/TR/trace-context/#parent-id
2682
+ *
2683
+ * @remarks Sets the spanId for the current context AND all parent contexts, if you want to set the spanId for
2684
+ * the current context only, use the `spanId` property.
2685
+ * @param newValue - The spanId to set
2686
+ * @deprecated Use the `spanId` property to avoid the side effect of changing the spanId of all
2687
+ * parent contexts.
2192
2688
  */
2193
2689
  setSpanId(newValue: string): void;
2194
2690
  /**
@@ -2197,62 +2693,311 @@ declare namespace ApplicationInsights {
2197
2693
  getTraceFlags(): number | undefined;
2198
2694
  /**
2199
2695
  * https://www.w3.org/TR/trace-context/#trace-flags
2696
+ * @remarks Sets the trace flags for the current context and ALL parent contexts, if you want to set the trace
2697
+ * flags for the current context only, use the `traceFlags` property.
2200
2698
  * @param newValue - An integer representation of the W3C TraceContext trace-flags.
2699
+ * @deprecated Use the `traceFlags` property to avoid the side effect of changing the traceFlags of all
2700
+ * parent contexts.
2201
2701
  */
2202
2702
  setTraceFlags(newValue?: number): void;
2203
- }
2204
-
2205
- /**
2206
- * The abstract common base of all domains.
2207
- */
2208
- interface IDomain {
2209
- }
2210
-
2211
- interface IEnvelope extends ISerializable {
2212
- /**
2213
- * Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1.
2214
- */
2215
- ver: number;
2216
- /**
2217
- * Type name of telemetry data item.
2218
- */
2219
- name: string;
2220
2703
  /**
2221
- * Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.
2704
+ * Returns the current name of the page
2705
+ * @remarks This function updates the current context only, to update the name of the current and ALL parent contexts,
2706
+ * use the `setName` method.
2707
+ * @default undefined
2708
+ * @since 3.4.0
2709
+ */
2710
+ pageName: string;
2711
+ /**
2712
+ * The current ID of the trace that this span belongs to. It is worldwide unique
2713
+ * with practically sufficient probability by being made as 16 randomly
2714
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
2715
+ * 128 bits.
2716
+ * @remarks It is NOT recommended that you dynamically change this value after creation and it is actively
2717
+ * being used as this may affect anyone accessing this context (as a parent for instance). You should logically
2718
+ * treat this as readonly after creation.
2719
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2720
+ * if you need to update the current and ALL parent contexts, use the `setTraceId` method which
2721
+ * provides the previous behavior.
2722
+ * @since 3.4.0
2222
2723
  */
2223
- time: string;
2724
+ traceId: string;
2224
2725
  /**
2225
- * Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.
2726
+ * The ID of the Span. It is globally unique with practically sufficient
2727
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
2728
+ * lowercase hex characters corresponding to 64 bits.
2729
+ * If you update this value, it will only update for the current context, not the parent context.
2730
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2731
+ * if you need to update the current and ALL parent contexts, use the `setSpanId` method.
2732
+ * @since 3.4.0
2226
2733
  */
2227
- sampleRate: number;
2734
+ spanId: string;
2228
2735
  /**
2229
- * Sequence field used to track absolute order of uploaded events.
2736
+ * Returns true if the current context was initialized (propagated) from a remote parent.
2737
+ * @since 3.4.0
2738
+ * @default false
2739
+ * @returns True if the context was propagated from a remote parent
2230
2740
  */
2231
- seq: string;
2741
+ readonly isRemote: boolean;
2232
2742
  /**
2233
- * The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive.
2743
+ * Trace flags to propagate.
2744
+ *
2745
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
2746
+ * sampled or not. When set, the least significant bit documents that the
2747
+ * caller may have recorded trace data. A caller who does not record trace
2748
+ * data out-of-band leaves this flag unset.
2749
+ *
2750
+ * see {@link eW3CTraceFlags} for valid flag values.
2751
+ *
2752
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2753
+ * if you need to update the current and ALL parent contexts, use the `setTraceFlags` method.
2754
+ * @since 3.4.0
2234
2755
  */
2235
- iKey: string;
2756
+ traceFlags?: number;
2236
2757
  /**
2237
- * Key/value collection of context properties. See ContextTagKeys for information on available properties.
2758
+ * Returns the current trace state which will be used to propgate context across different services.
2759
+ * Updating (adding / removing keys) of the trace state will modify the current context.IOTelTraceState
2760
+ * @remarks Unlike the OpenTelemetry {@link IOTelTraceState}, this value is a mutable object, so you can
2761
+ * modify it directly you do not need to reassign the new value to this property.
2762
+ * @since 3.4.0
2238
2763
  */
2239
- tags: {
2240
- [name: string]: any;
2241
- };
2764
+ readonly traceState: IW3cTraceState;
2242
2765
  /**
2243
- * Telemetry data item.
2766
+ * Provides access to the parent context of the current context.
2767
+ * @remarks This is a read-only property, you cannot modify the parent context directly, you can only
2768
+ * modify the current context. If you need to modify the parent context, you need to do it through the
2769
+ * current context using the `setTraceId`, `setSpanId`, `setTraceFlags` and `setName` methods.
2770
+ * @default null
2771
+ * @since 3.4.0
2244
2772
  */
2245
- data: any;
2773
+ readonly parentCtx?: IDistributedTraceContext | null;
2246
2774
  }
2247
2775
 
2248
2776
  /**
2249
- * Instances of Event represent structured event records that can be grouped and searched by their properties. Event data item also creates a metric of event count by name.
2777
+ * An object that can be used to populate a new {@link IDistributedTraceContext} instance,
2778
+ * the included {@link IW3cTraceState} or {@link IOTelTraceState} is used as the parent of the
2779
+ * created instances traceState
2250
2780
  */
2251
- interface IEventData extends IDomain {
2781
+ interface IDistributedTraceInit {
2252
2782
  /**
2253
- * Schema version
2783
+ * The unique identifier for the trace that this span belongs to.
2784
+ *
2785
+ * The trace ID is a globally unique identifier that connects all spans within a single
2786
+ * distributed trace. It consists of 16 randomly generated bytes encoded as 32 lowercase
2787
+ * hexadecimal characters, providing 128 bits of entropy to ensure worldwide uniqueness
2788
+ * with practically sufficient probability.
2789
+ *
2790
+ * @remarks
2791
+ * - Must be exactly 32 lowercase hexadecimal characters
2792
+ * - Represents 128 bits (16 bytes) of random data
2793
+ * - Shared by all spans within the same trace
2794
+ * - Used for trace correlation across distributed systems
2795
+ * - Should never be all zeros (invalid trace ID)
2796
+ *
2797
+ * @example
2798
+ * ```typescript
2799
+ * // Example trace ID format
2800
+ * const traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
2801
+ *
2802
+ * // All spans in the same trace share this ID
2803
+ * console.log(parentSpan.spanContext().traceId === childSpan.spanContext().traceId); // true
2804
+ * ```
2254
2805
  */
2255
- ver: number;
2806
+ traceId: string;
2807
+ /**
2808
+ * The unique identifier for this specific span within the trace.
2809
+ *
2810
+ * The span ID uniquely identifies this span within the trace and is used to establish
2811
+ * parent-child relationships between spans. It consists of 8 randomly generated bytes
2812
+ * encoded as 16 lowercase hexadecimal characters, providing 64 bits of entropy to
2813
+ * ensure global uniqueness with practically sufficient probability.
2814
+ *
2815
+ * @remarks
2816
+ * - Must be exactly 16 lowercase hexadecimal characters
2817
+ * - Represents 64 bits (8 bytes) of random data
2818
+ * - Unique within the trace (different spans have different span IDs)
2819
+ * - Used as parent ID when creating child spans
2820
+ * - Should never be all zeros (invalid span ID)
2821
+ *
2822
+ * @example
2823
+ * ```typescript
2824
+ * // Example span ID format
2825
+ * const spanId = "00f067aa0ba902b7";
2826
+ *
2827
+ * // Each span has a unique ID within the trace
2828
+ * const parentId = parentSpan.spanContext().spanId; // "00f067aa0ba902b7"
2829
+ * const childId = childSpan.spanContext().spanId; // "b9c7c989f97918e1"
2830
+ *
2831
+ * // Child span uses parent's span ID as its parent ID
2832
+ * console.log(childSpan.parentSpanId === parentId); // true
2833
+ * ```
2834
+ */
2835
+ spanId: string;
2836
+ /**
2837
+ * Indicates whether this span context was propagated from a remote parent span.
2838
+ *
2839
+ * This flag distinguishes between spans created locally within the same process
2840
+ * and spans that represent operations in remote services. Remote spans are typically
2841
+ * created when trace context is received via HTTP headers, message queues, or other
2842
+ * inter-process communication mechanisms.
2843
+ *
2844
+ * @defaultValue false - spans are considered local unless explicitly marked as remote
2845
+ *
2846
+ * @remarks
2847
+ * - True only when span context was received from another process/service
2848
+ * - Helps distinguish local vs. distributed trace segments
2849
+ * - Used by tracing systems for visualization and analysis
2850
+ * - Local child spans of remote parents are NOT considered remote themselves
2851
+ *
2852
+ * @example
2853
+ * ```typescript
2854
+ * // HTTP service receiving trace context
2855
+ * const incomingSpanContext = extractSpanContextFromHeaders(request.headers);
2856
+ * console.log(incomingSpanContext.isRemote); // true
2857
+ *
2858
+ * // Child span created locally
2859
+ * const localChild = tracer.startSpan('local-operation', {
2860
+ * parent: incomingSpanContext
2861
+ * });
2862
+ * console.log(localChild.spanContext().isRemote); // false
2863
+ * ```
2864
+ */
2865
+ isRemote?: boolean;
2866
+ /**
2867
+ * Trace flags that control trace behavior and indicate sampling decisions.
2868
+ *
2869
+ * The trace flags are represented as a single byte (8-bit bitmap) that carries
2870
+ * trace-level information. The least significant bit (0x01) indicates whether
2871
+ * the trace is sampled. When this bit is set, it documents that the caller
2872
+ * may have recorded trace data. Additional bits are reserved for future use
2873
+ * and should be ignored when not understood.
2874
+ *
2875
+ * @remarks
2876
+ * - Represented as a number (0-255) corresponding to 8 bits
2877
+ * - Bit 0 (0x01): Sampled flag - indicates trace may contain recorded data
2878
+ * - Bits 1-7: Reserved for future use, should be preserved during propagation
2879
+ * - Used by sampling algorithms to make consistent decisions across services
2880
+ * - See {@link eW3CTraceFlags} for standard flag values
2881
+ *
2882
+ * @example
2883
+ * ```typescript
2884
+ * // Check if trace is sampled
2885
+ * const isSampled = (spanContext.traceFlags & 0x01) === 1;
2886
+ *
2887
+ * // Common flag values
2888
+ * const UNSAMPLED = 0x00; // 00000000 - not sampled
2889
+ * const SAMPLED = 0x01; // 00000001 - sampled
2890
+ *
2891
+ * // Preserving unknown flags during propagation
2892
+ * const preservedFlags = spanContext.traceFlags | 0x01; // Set sampled bit while preserving others
2893
+ *
2894
+ * // W3C traceparent header format includes these flags
2895
+ * const traceparent = `00-${traceId}-${spanId}-${traceFlags.toString(16).padStart(2, '0')}`;
2896
+ * ```
2897
+ */
2898
+ traceFlags?: number;
2899
+ /**
2900
+ * Vendor-specific trace state information for cross-system trace correlation.
2901
+ *
2902
+ * The trace state carries tracing-system-specific context in a standardized format
2903
+ * defined by the W3C Trace Context specification. It allows multiple tracing systems
2904
+ * to participate in the same trace by providing a mechanism for each system to add
2905
+ * its own metadata without interfering with others.
2906
+ *
2907
+ * The trace state is formatted as a comma-separated list of key-value pairs, where
2908
+ * each pair represents one tracing system's contribution. Keys should be unique
2909
+ * within the trace state and follow specific naming conventions.
2910
+ *
2911
+ * @remarks
2912
+ * - Maximum of 32 list members allowed
2913
+ * - Each member format: `key=value` separated by commas
2914
+ * - Keys should be namespaced to avoid conflicts (e.g., `vendor@system=value`)
2915
+ * - Total size should not exceed 512 characters for practical header limits
2916
+ * - Spaces around list members are ignored
2917
+ * - Preserves vendor-specific information during trace propagation
2918
+ *
2919
+ * @see {@link https://www.w3.org/TR/trace-context/#tracestate-field | W3C Trace Context Specification}
2920
+ *
2921
+ * @example
2922
+ * ```typescript
2923
+ * // Single tracing system
2924
+ * const singleVendor = {
2925
+ * get: (key: string) => key === 'rojo' ? '00f067aa0ba902b7' : undefined,
2926
+ * set: (key: string, value: string) => { ... },
2927
+ * unset: (key: string) => { ... },
2928
+ * serialize: () => 'rojo=00f067aa0ba902b7'
2929
+ * };
2930
+ *
2931
+ * // Multiple tracing systems
2932
+ * const multiVendor = {
2933
+ * serialize: () => 'rojo=00f067aa0ba902b7,congo=t61rcWkgMzE,vendor@system=custom-value'
2934
+ * };
2935
+ *
2936
+ * // Accessing trace state
2937
+ * const rojoValue = spanContext.traceState?.get('rojo');
2938
+ * const serialized = spanContext.traceState?.serialize();
2939
+ *
2940
+ * // HTTP header format (When the traceState is an IOTelTraceState)
2941
+ * headers['tracestate'] = spanContext.traceState?.serialize() || '';
2942
+ *
2943
+ * // HTTP header format (When the traceState is an IW3cTraceState)
2944
+ * headers['tracestate'] = spanContext.traceState?.hdrs()[0] || '';
2945
+ * ```
2946
+ */
2947
+ traceState?: IW3cTraceState | IOTelTraceState;
2948
+ }
2949
+
2950
+ /**
2951
+ * The abstract common base of all domains.
2952
+ */
2953
+ interface IDomain {
2954
+ }
2955
+
2956
+ interface IEnvelope extends ISerializable {
2957
+ /**
2958
+ * Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1.
2959
+ */
2960
+ ver: number;
2961
+ /**
2962
+ * Type name of telemetry data item.
2963
+ */
2964
+ name: string;
2965
+ /**
2966
+ * Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.
2967
+ */
2968
+ time: string;
2969
+ /**
2970
+ * Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.
2971
+ */
2972
+ sampleRate: number;
2973
+ /**
2974
+ * Sequence field used to track absolute order of uploaded events.
2975
+ */
2976
+ seq: string;
2977
+ /**
2978
+ * The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive.
2979
+ */
2980
+ iKey: string;
2981
+ /**
2982
+ * Key/value collection of context properties. See ContextTagKeys for information on available properties.
2983
+ */
2984
+ tags: {
2985
+ [name: string]: any;
2986
+ };
2987
+ /**
2988
+ * Telemetry data item.
2989
+ */
2990
+ data: any;
2991
+ }
2992
+
2993
+ /**
2994
+ * Instances of Event represent structured event records that can be grouped and searched by their properties. Event data item also creates a metric of event count by name.
2995
+ */
2996
+ interface IEventData extends IDomain {
2997
+ /**
2998
+ * Schema version
2999
+ */
3000
+ ver: number;
2256
3001
  /**
2257
3002
  * Event name. Keep it low cardinality to allow proper grouping and useful metrics.
2258
3003
  */
@@ -2456,7 +3201,7 @@ declare namespace ApplicationInsights {
2456
3201
  * Identifies configuration override values when given feature is enabled
2457
3202
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
2458
3203
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
2459
- * Default: undefined
3204
+ * @default undefined
2460
3205
  */
2461
3206
  onCfg?: {
2462
3207
  [field: string]: any;
@@ -2465,7 +3210,7 @@ declare namespace ApplicationInsights {
2465
3210
  * Identifies configuration override values when given feature is disabled
2466
3211
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
2467
3212
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
2468
- * Default: undefined
3213
+ * @default undefined
2469
3214
  */
2470
3215
  offCfg?: {
2471
3216
  [field: string]: any;
@@ -2501,6 +3246,11 @@ declare namespace ApplicationInsights {
2501
3246
  sdkSrc: string;
2502
3247
  }
2503
3248
 
3249
+ interface IInternalLogMessage {
3250
+ message: string;
3251
+ messageId: _InternalMessageId;
3252
+ }
3253
+
2504
3254
  /**
2505
3255
  * Internal Interface
2506
3256
  */
@@ -2789,36 +3539,1083 @@ declare namespace ApplicationInsights {
2789
3539
  offlineBatchDrop?(cnt: number, reason?: number): void;
2790
3540
  }
2791
3541
 
2792
- class _InternalLogMessage {
2793
- static dataType: string;
3542
+ type _InternalMessageId = number | _eInternalMessageId;
3543
+
3544
+ interface IOfflineListener {
3545
+ isOnline: () => boolean;
3546
+ isListening: () => boolean;
3547
+ unload: () => void;
3548
+ addListener: (callback: OfflineCallback) => IUnloadHook;
3549
+ setOnlineState: (uState: eOfflineValue) => void;
3550
+ }
3551
+
3552
+ /**
3553
+ * This is the interface for the Offline state
3554
+ * runtime state is retrieved from the browser state
3555
+ * user state is set by the user
3556
+ */
3557
+ interface IOfflineState {
3558
+ readonly isOnline: boolean;
3559
+ readonly rState: eOfflineValue;
3560
+ readonly uState: eOfflineValue;
3561
+ }
3562
+
3563
+ interface IOperatingSystem {
3564
+ name: string;
3565
+ }
3566
+
3567
+ /**
3568
+ * The main OpenTelemetry API interface that provides access to all OpenTelemetry functionality.
3569
+ * This interface extends the IOTelTracerProvider and serves as the entry point for OpenTelemetry operations.
3570
+ *
3571
+ * @example
3572
+ * ```typescript
3573
+ * // Get a tracer from the API instance
3574
+ * const tracer = otelApi.getTracer("my-component");
3575
+ *
3576
+ * // Create a span
3577
+ * const span = tracer.startSpan("operation");
3578
+ *
3579
+ * // Access context manager
3580
+ * const currentContext = otelApi.context.active();
3581
+ *
3582
+ * // Access trace API
3583
+ * const activeSpan = otelApi.trace.getActiveSpan();
3584
+ * ```
3585
+ *
3586
+ * @since 3.4.0
3587
+ */
3588
+ interface IOTelApi extends IOTelTracerProvider {
3589
+ /**
3590
+ * The configuration object that contains all OpenTelemetry-specific settings.
3591
+ * This includes tracing configuration, error handlers, and other OpenTelemetry options.
3592
+ *
3593
+ * @remarks
3594
+ * Changes to this configuration after initialization may not take effect until
3595
+ * the next telemetry operation, depending on the implementation.
3596
+ */
3597
+ cfg: IOTelConfig;
3598
+ /**
3599
+ * The current {@link ITraceHost} instance for this IOTelApi instance, this is effectively
3600
+ * the OpenTelemetry ContextAPI instance without the static methods.
3601
+ * @returns The ContextManager instance
3602
+ */
3603
+ host: ITraceHost;
3604
+ /**
3605
+ * The current {@link ITraceApi} instance for this IOTelApi instance, this is
3606
+ * effectively the OpenTelemetry TraceAPI instance without the static methods.
3607
+ * @returns The current {@link ITraceApi} instance
3608
+ */
3609
+ trace: ITraceApi;
3610
+ }
3611
+
3612
+ /**
3613
+ * Configuration interface for OpenTelemetry attribute limits.
3614
+ * These limits help control the size and number of attributes to prevent
3615
+ * excessive memory usage and ensure consistent performance.
3616
+ *
3617
+ * @example
3618
+ * ```typescript
3619
+ * const limits: IOTelAttributeLimits = {
3620
+ * attributeCountLimit: 128, // Maximum 128 attributes
3621
+ * attributeValueLengthLimit: 4096 // Maximum 4KB per attribute value
3622
+ * };
3623
+ * ```
3624
+ *
3625
+ * @remarks
3626
+ * When limits are exceeded:
3627
+ * - Additional attributes beyond `attributeCountLimit` are dropped
3628
+ * - Attribute values longer than `attributeValueLengthLimit` are truncated
3629
+ * - The behavior may vary based on the specific implementation
3630
+ *
3631
+ * @since 3.4.0
3632
+ */
3633
+ interface IOTelAttributeLimits {
3634
+ /**
3635
+ * Maximum allowed length for attribute values in characters.
3636
+ *
3637
+ * @remarks
3638
+ * - Values longer than this limit will be truncated
3639
+ * - Applies to string attribute values only
3640
+ * - Numeric and boolean values are not affected by this limit
3641
+ * - Array values have this limit applied to each individual element
3642
+ *
3643
+ * @defaultValue 4096
3644
+ *
3645
+ * @example
3646
+ * ```typescript
3647
+ * // If attributeValueLengthLimit is 100:
3648
+ * span.setAttribute("description", "a".repeat(200)); // Will be truncated to 100 characters
3649
+ * span.setAttribute("count", 12345); // Not affected (number)
3650
+ * span.setAttribute("enabled", true); // Not affected (boolean)
3651
+ * ```
3652
+ */
3653
+ attributeValueLengthLimit?: number;
3654
+ /**
3655
+ * Maximum number of attributes allowed per telemetry item.
3656
+ *
3657
+ * @remarks
3658
+ * - Attributes added beyond this limit will be dropped
3659
+ * - The order of attributes matters; earlier attributes take precedence
3660
+ * - This limit applies to the total count of attributes, regardless of their type
3661
+ * - Inherited or default attributes count toward this limit
3662
+ *
3663
+ * @defaultValue 128
3664
+ *
3665
+ * @example
3666
+ * ```typescript
3667
+ * // If attributeCountLimit is 5:
3668
+ * span.setAttributes({
3669
+ * "attr1": "value1", // Kept
3670
+ * "attr2": "value2", // Kept
3671
+ * "attr3": "value3", // Kept
3672
+ * "attr4": "value4", // Kept
3673
+ * "attr5": "value5", // Kept
3674
+ * "attr6": "value6" // Dropped (exceeds limit)
3675
+ * });
3676
+ * ```
3677
+ */
3678
+ attributeCountLimit?: number;
3679
+ }
3680
+
3681
+ /**
3682
+ * Attributes is a map from string to attribute values.
3683
+ *
3684
+ * Note: only the own enumerable keys are counted as valid attribute keys.
3685
+ *
3686
+ * @since 3.4.0
3687
+ */
3688
+ interface IOTelAttributes {
3689
+ [key: string]: OTelAttributeValue | undefined;
3690
+ }
3691
+
3692
+ /**
3693
+ * OpenTelemetry configuration interface
3694
+ * Provides configuration specific to the OpenTelemetry extensions
3695
+ */
3696
+ interface IOTelConfig {
3697
+ /**
3698
+ * Configuration interface for OpenTelemetry tracing functionality.
3699
+ * This interface contains all the settings that control how traces are created,
3700
+ * processed, and managed within the OpenTelemetry system.
3701
+ *
3702
+ * @example
3703
+ * ```typescript
3704
+ * const traceCfg: ITraceCfg = {
3705
+ * serviceName: "my-service",
3706
+ * generalLimits: {
3707
+ * attributeCountLimit: 128,
3708
+ * attributeValueLengthLimit: 4096
3709
+ * },
3710
+ * spanLimits: {
3711
+ * attributeCountLimit: 128,
3712
+ * linkCountLimit: 128,
3713
+ * eventCountLimit: 128
3714
+ * }
3715
+ * };
3716
+ * ```
3717
+ *
3718
+ * @since 3.4.0
3719
+ */
3720
+ traceCfg?: ITraceCfg;
3721
+ /**
3722
+ * Error handlers for OpenTelemetry operations.
3723
+ * This interface allows you to specify custom error handling logic for various
3724
+ * OpenTelemetry components, enabling better control over how errors are managed
3725
+ * within the OpenTelemetry system.
3726
+ *
3727
+ * @see {@link IOTelErrorHandlers}
3728
+ *
3729
+ * @example
3730
+ * ```typescript
3731
+ * const errorHandlers: IOTelErrorHandlers = {
3732
+ * attribError: (message, key, value) => {
3733
+ * console.warn(`Attribute error for ${key}:`, message);
3734
+ * }
3735
+ * };
3736
+ * ```
3737
+ */
3738
+ errorHandlers?: IOTelErrorHandlers;
3739
+ }
3740
+
3741
+ /**
3742
+ * Configuration interface for OpenTelemetry error handling callbacks.
3743
+ * Provides hooks to customize how different types of errors and diagnostic
3744
+ * messages are handled within the OpenTelemetry system.
3745
+ *
3746
+ * @example
3747
+ * ```typescript
3748
+ * const errorHandlers: IOTelErrorHandlers = {
3749
+ * attribError: (message, key, value) => {
3750
+ * console.warn(`Attribute error for ${key}:`, message);
3751
+ * },
3752
+ * spanError: (message, spanName) => {
3753
+ * logger.error(`Span ${spanName} error:`, message);
3754
+ * },
3755
+ * warn: (message) => {
3756
+ * logger.warn(message);
3757
+ * },
3758
+ * error: (message) => {
3759
+ * logger.error(message);
3760
+ * }
3761
+ * };
3762
+ * ```
3763
+ *
3764
+ * @remarks
3765
+ * If handlers are not provided, default behavior will be used:
3766
+ * - `attribError`: Throws an `OTelInvalidAttributeError`
3767
+ * - `spanError`: Logs to console or calls warn handler
3768
+ * - `debug`: Logs to console.log
3769
+ * - `warn`: Logs to console.warn
3770
+ * - `error`: Logs to console.error
3771
+ * - `notImplemented`: Logs to console.error
3772
+ *
3773
+ * @since 3.4.0
3774
+ */
3775
+ interface IOTelErrorHandlers {
3776
+ /**
3777
+ * Handles attribute-related errors, such as invalid attribute values or keys.
3778
+ * Called when an attribute operation fails validation or processing.
3779
+ *
3780
+ * @param message - Descriptive error message explaining what went wrong
3781
+ * @param key - The attribute key that caused the error
3782
+ * @param value - The attribute value that caused the error (may be of any type)
3783
+ *
3784
+ * @remarks
3785
+ * Common scenarios that trigger this handler:
3786
+ * - Invalid attribute key format
3787
+ * - Attribute value exceeds length limits
3788
+ * - Unsupported attribute value type
3789
+ * - Attribute count exceeds limits
3790
+ *
3791
+ * @default Throws an `OTelInvalidAttributeError`
3792
+ *
3793
+ * @example
3794
+ * ```typescript
3795
+ * attribError: (message, key, value) => {
3796
+ * metrics.increment('otel.attribute.errors', { key, type: typeof value });
3797
+ * logger.warn(`Attribute ${key} rejected: ${message}`);
3798
+ * }
3799
+ * ```
3800
+ */
3801
+ attribError?: (message: string, key: string, value: any) => void;
3802
+ /**
3803
+ * Handles span-related errors that occur during span operations.
3804
+ * Called when a span operation fails or encounters an unexpected condition.
3805
+ *
3806
+ * @param message - Descriptive error message explaining the span error
3807
+ * @param spanName - The name of the span that encountered the error
3808
+ *
3809
+ * @remarks
3810
+ * Common scenarios that trigger this handler:
3811
+ * - Span operation called on an ended span
3812
+ * - Invalid span configuration
3813
+ * - Span processor errors
3814
+ * - Context propagation failures
3815
+ *
3816
+ * @default Logs to console or calls the warn handler
3817
+ *
3818
+ * @example
3819
+ * ```typescript
3820
+ * spanError: (message, spanName) => {
3821
+ * metrics.increment('otel.span.errors', { span_name: spanName });
3822
+ * logger.error(`Span operation failed for "${spanName}": ${message}`);
3823
+ * }
3824
+ * ```
3825
+ */
3826
+ spanError?: (message: string, spanName: string) => void;
3827
+ /**
3828
+ * Handles debug-level diagnostic messages.
3829
+ * Used for detailed troubleshooting information that is typically
3830
+ * only relevant during development or when diagnosing issues.
3831
+ *
3832
+ * @param message - Debug message to be handled
3833
+ *
3834
+ * @remarks
3835
+ * Debug messages are typically:
3836
+ * - Verbose operational details
3837
+ * - Internal state information
3838
+ * - Performance metrics
3839
+ * - Development-time diagnostics
3840
+ *
3841
+ * @default Logs to console.log
3842
+ *
3843
+ * @example
3844
+ * ```typescript
3845
+ * debug: (message) => {
3846
+ * if (process.env.NODE_ENV === 'development') {
3847
+ * console.debug('[OTel Debug]', message);
3848
+ * }
3849
+ * }
3850
+ * ```
3851
+ */
3852
+ debug?: (message: string) => void;
3853
+ /**
3854
+ * Handles warning-level messages for non-fatal issues.
3855
+ * Used for conditions that are unusual but don't prevent continued operation.
3856
+ *
3857
+ * @param message - Warning message to be handled
3858
+ *
3859
+ * @remarks
3860
+ * Warning scenarios include:
3861
+ * - Configuration issues that fall back to defaults
3862
+ * - Performance degradation
3863
+ * - Deprecated API usage
3864
+ * - Resource limit approaches
3865
+ *
3866
+ * @default Logs to console.warn
3867
+ *
3868
+ * @example
3869
+ * ```typescript
3870
+ * warn: (message) => {
3871
+ * logger.warn('[OTel Warning]', message);
3872
+ * metrics.increment('otel.warnings');
3873
+ * }
3874
+ * ```
3875
+ */
3876
+ warn?: (message: string) => void;
3877
+ /**
3878
+ * Handles general error conditions that may affect functionality.
3879
+ * Used for significant errors that should be investigated but may not be fatal.
3880
+ *
3881
+ * @param message - Error message to be handled
3882
+ *
3883
+ * @remarks
3884
+ * Error scenarios include:
3885
+ * - Failed network requests
3886
+ * - Configuration validation failures
3887
+ * - Resource allocation failures
3888
+ * - Unexpected runtime conditions
3889
+ *
3890
+ * @default Logs to console.error
3891
+ *
3892
+ * @example
3893
+ * ```typescript
3894
+ * error: (message) => {
3895
+ * logger.error('[OTel Error]', message);
3896
+ * errorReporting.captureException(new Error(message));
3897
+ * }
3898
+ * ```
3899
+ */
3900
+ error?: (message: string) => void;
3901
+ /**
3902
+ * Handles errors related to unimplemented functionality.
3903
+ * Called when a method or feature is not yet implemented or is intentionally
3904
+ * disabled in the current configuration.
3905
+ *
3906
+ * @param message - Message describing the unimplemented functionality
3907
+ *
3908
+ * @remarks
3909
+ * Common scenarios:
3910
+ * - Placeholder methods that haven't been implemented
3911
+ * - Features disabled in the current build
3912
+ * - Platform-specific functionality not available
3913
+ * - Optional features not included in the configuration
3914
+ *
3915
+ * @default Logs to console.error
3916
+ *
3917
+ * @example
3918
+ * ```typescript
3919
+ * notImplemented: (message) => {
3920
+ * logger.warn(`[OTel Not Implemented] ${message}`);
3921
+ * if (process.env.NODE_ENV === 'development') {
3922
+ * console.trace('Not implemented method called');
3923
+ * }
3924
+ * }
3925
+ * ```
3926
+ */
3927
+ notImplemented?: (message: string) => void;
3928
+ }
3929
+
3930
+ interface IOTelExceptionWithCode {
3931
+ code: string | number;
3932
+ name?: string;
3933
+ message?: string;
3934
+ stack?: string;
3935
+ }
3936
+
3937
+ interface IOTelExceptionWithMessage {
3938
+ code?: string | number;
2794
3939
  message: string;
2795
- messageId: _InternalMessageId;
2796
- constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
3940
+ name?: string;
3941
+ stack?: string;
2797
3942
  }
2798
3943
 
2799
- type _InternalMessageId = number | _eInternalMessageId;
3944
+ interface IOTelExceptionWithName {
3945
+ code?: string | number;
3946
+ message?: string;
3947
+ name: string;
3948
+ stack?: string;
3949
+ }
3950
+
3951
+ /**
3952
+ * Enhanced high-resolution time interface that extends the base tuple with additional properties.
3953
+ * Provides a more structured way to work with high-resolution timestamps.
3954
+ *
3955
+ * @example
3956
+ * ```typescript
3957
+ * const hrTime: IOTelHrTime = {
3958
+ * 0: 1609459200, // seconds since Unix epoch
3959
+ * 1: 500000000, // nanoseconds (0-999,999,999)
3960
+ * };
3961
+ * ```
3962
+ *
3963
+ * @since 3.4.0
3964
+ */
3965
+ interface IOTelHrTime extends OTelHrTimeBase {
3966
+ /**
3967
+ * Seconds since Unix epoch (January 1, 1970 00:00:00 UTC).
3968
+ * Must be a non-negative integer.
3969
+ */
3970
+ 0: number;
3971
+ /**
3972
+ * Nanoseconds within the second specified by index 0.
3973
+ * Must be in the range [0, 999999999].
3974
+ */
3975
+ 1: number;
3976
+ }
3977
+
3978
+ /**
3979
+ * Provides an OpenTelemetry compatible interface for spans conforming to the OpenTelemetry API specification (v1.9.0).
3980
+ *
3981
+ * A span represents an operation within a trace and is the fundamental unit of work in distributed tracing.
3982
+ * Spans can be thought of as a grouping mechanism for a set of operations that are executed as part of
3983
+ * a single logical unit of work, providing timing information and contextual data about the operation.
3984
+ *
3985
+ * Spans form a tree structure within a trace, with a single root span that may have zero or more child spans,
3986
+ * which in turn may have their own children. This hierarchical structure allows for detailed analysis of
3987
+ * complex, multi-step operations across distributed systems.
3988
+ *
3989
+ * @since 3.4.0
3990
+ *
3991
+ * @remarks
3992
+ * - All spans created by this library implement the ISpan interface and extend the IReadableSpan interface
3993
+ * - Spans should be ended by calling `end()` when the operation completes
3994
+ * - Once ended, spans should generally not be used for further operations
3995
+ * - Spans automatically track timing information from creation to end
3996
+ *
3997
+ * @example
3998
+ * ```typescript
3999
+ * // Basic span usage
4000
+ * const span = tracer.startSpan('user-authentication');
4001
+ * span.setAttribute('user.id', '12345');
4002
+ * span.setAttribute('auth.method', 'oauth2');
4003
+ *
4004
+ * try {
4005
+ * const result = await authenticateUser();
4006
+ * span.setStatus({ code: SpanStatusCode.OK });
4007
+ * span.setAttribute('auth.success', true);
4008
+ * } catch (error) {
4009
+ * span.recordException(error);
4010
+ * span.setStatus({
4011
+ * code: SpanStatusCode.ERROR,
4012
+ * message: 'Authentication failed'
4013
+ * });
4014
+ * } finally {
4015
+ * span.end();
4016
+ * }
4017
+ * ```
4018
+ */
4019
+ interface IOTelSpan {
4020
+ /**
4021
+ * Returns the span context object associated with this span.
4022
+ *
4023
+ * The span context is an immutable, serializable identifier that uniquely identifies
4024
+ * this span within a trace. It contains the trace ID, span ID, and trace flags that
4025
+ * can be used to create new child spans or propagate trace context across process boundaries.
4026
+ *
4027
+ * The returned span context remains valid even after the span has ended, making it
4028
+ * useful for asynchronous operations and cross-service communication.
4029
+ *
4030
+ * @returns The immutable span context associated with this span
4031
+ *
4032
+ * @remarks
4033
+ * - The span context is the primary mechanism for trace propagation
4034
+ * - Context can be serialized and transmitted across network boundaries
4035
+ * - Contains trace ID (unique to the entire trace) and span ID (unique to this span)
4036
+ *
4037
+ * @example
4038
+ * ```typescript
4039
+ * const span = tracer.startSpan('parent-operation');
4040
+ * const spanContext = span.spanContext();
4041
+ *
4042
+ * // Use context to create child spans in other parts of the system
4043
+ * const childSpan = tracer.startSpan('child-operation', {
4044
+ * parent: spanContext
4045
+ * });
4046
+ *
4047
+ * // Context can be serialized for cross-service propagation
4048
+ * const traceId = spanContext.traceId;
4049
+ * const spanId = spanContext.spanId;
4050
+ * ```
4051
+ */
4052
+ spanContext(): IDistributedTraceContext;
4053
+ /**
4054
+ * Sets a single attribute on the span with the specified key and value.
4055
+ *
4056
+ * Attributes provide contextual information about the operation represented by the span.
4057
+ * They are key-value pairs that help with filtering, grouping, and understanding spans
4058
+ * in trace analysis tools. Attributes should represent meaningful properties of the operation.
4059
+ *
4060
+ * @param key - The attribute key, should be descriptive and follow naming conventions
4061
+ * @param value - The attribute value; null or undefined values are invalid and result in undefined behavior
4062
+ *
4063
+ * @returns This span instance for method chaining
4064
+ *
4065
+ * @remarks
4066
+ * - Attribute keys should follow semantic conventions when available
4067
+ * - Common attributes include service.name, http.method, db.statement, etc.
4068
+ * - Setting null or undefined values is invalid and may cause unexpected behavior
4069
+ * - Attributes set after span creation don't affect sampling decisions
4070
+ *
4071
+ * @example
4072
+ * ```typescript
4073
+ * const span = tracer.startSpan('http-request');
4074
+ *
4075
+ * // Set individual attributes with descriptive keys
4076
+ * span.setAttribute('http.method', 'POST')
4077
+ * .setAttribute('http.url', 'https://api.example.com/users')
4078
+ * .setAttribute('http.status_code', 201)
4079
+ * .setAttribute('user.id', '12345')
4080
+ * .setAttribute('request.size', 1024);
4081
+ * ```
4082
+ */
4083
+ setAttribute(key: string, value: OTelAttributeValue): this;
4084
+ /**
4085
+ * Sets multiple attributes on the span at once using an attributes object.
4086
+ *
4087
+ * This method allows efficient batch setting of multiple attributes in a single call.
4088
+ * All attributes in the provided object will be added to the span, supplementing any
4089
+ * existing attributes (duplicate keys will be overwritten).
4090
+ *
4091
+ * @param attributes - An object containing key-value pairs to set as span attributes
4092
+ *
4093
+ * @returns This span instance for method chaining
4094
+ *
4095
+ * @remarks
4096
+ * - Null or undefined attribute values are invalid and will result in undefined behavior
4097
+ * - More efficient than multiple `setAttribute` calls for bulk operations
4098
+ * - Existing attributes with the same keys will be overwritten
4099
+ *
4100
+ * @example
4101
+ * ```typescript
4102
+ * const span = tracer.startSpan('database-query');
4103
+ *
4104
+ * // Set multiple attributes efficiently
4105
+ * span.setAttributes({
4106
+ * 'db.system': 'postgresql',
4107
+ * 'db.name': 'user_database',
4108
+ * 'db.table': 'users',
4109
+ * 'db.operation': 'SELECT',
4110
+ * 'db.rows_affected': 5,
4111
+ * 'query.duration_ms': 15.7
4112
+ * });
4113
+ * ```
4114
+ */
4115
+ setAttributes(attributes: IOTelAttributes): this;
4116
+ /**
4117
+ * The {@link IAttributeContainer | attribute container} associated with this span, providing
4118
+ * advanced attribute management capabilities. Rather than using the {@link IReadableSpan#attributes}
4119
+ * directly which returns a readonly {@link IOTelAttributes} map that is a snapshot of the attributes at
4120
+ * the time of access, the attribute container offers methods to get, set, delete, and iterate over attributes
4121
+ * with fine-grained control.
4122
+ * It is recommended that you only access the {@link IReadableSpan#attributes} property sparingly due to the
4123
+ * performance cost of taking a snapshot of all attributes.
4124
+ */
4125
+ readonly attribContainer: IAttributeContainer;
4126
+ /**
4127
+ * Sets the status of the span to indicate the success or failure of the operation.
4128
+ *
4129
+ * The span status provides a standardized way to indicate whether the operation
4130
+ * completed successfully, encountered an error, or is in an unknown state.
4131
+ * This status is used by observability tools to provide meaningful insights
4132
+ * about system health and operation outcomes.
4133
+ *
4134
+ * @param status - The status object containing code and optional message
4135
+ *
4136
+ * @returns This span instance for method chaining
4137
+ *
4138
+ * @remarks
4139
+ * - Default status is UNSET until explicitly set
4140
+ * - Setting status overrides any previous status values
4141
+ * - ERROR status should be accompanied by a descriptive message when possible
4142
+ * - Status should reflect the final outcome of the operation
4143
+ *
4144
+ * @example
4145
+ * ```typescript
4146
+ * const span = tracer.startSpan('payment-processing');
4147
+ *
4148
+ * try {
4149
+ * const result = await processPayment(paymentData);
4150
+ *
4151
+ * // Indicate successful completion
4152
+ * span.setStatus({
4153
+ * code: SpanStatusCode.OK
4154
+ * });
4155
+ *
4156
+ * } catch (error) {
4157
+ * // Indicate operation failed
4158
+ * span.setStatus({
4159
+ * code: SpanStatusCode.ERROR,
4160
+ * message: 'Payment processing failed: ' + error.message
4161
+ * });
4162
+ *
4163
+ * span.recordException(error);
4164
+ * }
4165
+ * ```
4166
+ */
4167
+ setStatus(status: IOTelSpanStatus): this;
4168
+ /**
4169
+ * Updates the name of the span, overriding the name provided during creation.
4170
+ *
4171
+ * Span names should be descriptive and represent the operation being performed.
4172
+ * Updating the name can be useful when the operation's scope becomes clearer
4173
+ * during execution, or when implementing generic spans that need specific naming
4174
+ * based on runtime conditions.
4175
+ *
4176
+ * @param name - The new name for the span, should be descriptive of the operation
4177
+ *
4178
+ * @returns This span instance for method chaining
4179
+ *
4180
+ * @remarks
4181
+ * - Name updates may affect sampling behavior depending on implementation
4182
+ * - Choose names that are meaningful but not too specific to avoid cardinality issues
4183
+ * - Follow naming conventions consistent with your observability strategy
4184
+ * - Consider the impact on existing traces and dashboards when changing names
4185
+ *
4186
+ * @example
4187
+ * ```typescript
4188
+ * const span = tracer.startSpan('generic-operation');
4189
+ *
4190
+ * // Update name based on runtime determination
4191
+ * if (operationType === 'user-registration') {
4192
+ * span.updateName('user-registration');
4193
+ * span.setAttribute('operation.type', 'registration');
4194
+ * } else if (operationType === 'user-login') {
4195
+ * span.updateName('user-authentication');
4196
+ * span.setAttribute('operation.type', 'authentication');
4197
+ * }
4198
+ * ```
4199
+ */
4200
+ updateName(name: string): this;
4201
+ /**
4202
+ * Marks the end of the span's execution and records the end timestamp.
4203
+ *
4204
+ * This method finalizes the span and makes it available for export to tracing systems.
4205
+ * Once ended, the span should not be used for further operations. The span's duration
4206
+ * is calculated from its start time to the end time provided or current time.
4207
+ *
4208
+ * @param endTime - Optional end time; if not provided, current time is used
4209
+ *
4210
+ * @remarks
4211
+ * - This method does NOT return `this` to discourage chaining after span completion
4212
+ * - Ending a span has no effect on child spans, which may continue running
4213
+ * - Child spans can be ended independently after their parent has ended
4214
+ * - The span becomes eligible for export once ended
4215
+ * - Calling end() multiple times has no additional effect
4216
+ *
4217
+ * @example
4218
+ * ```typescript
4219
+ * const span = tracer.startSpan('file-processing');
4220
+ *
4221
+ * try {
4222
+ * // Perform the operation
4223
+ * const result = await processFile(filePath);
4224
+ *
4225
+ * // Record success
4226
+ * span.setStatus({ code: SpanStatusCode.OK });
4227
+ * span.setAttribute('file.size', result.size);
4228
+ *
4229
+ * } catch (error) {
4230
+ * span.recordException(error);
4231
+ * span.setStatus({
4232
+ * code: SpanStatusCode.ERROR,
4233
+ * message: error.message
4234
+ * });
4235
+ * } finally {
4236
+ * // Always end the span
4237
+ * span.end();
4238
+ * // Don't use span after this point
4239
+ * }
4240
+ *
4241
+ * // Custom end time example
4242
+ * const customEndTime = Date.now() * 1000000; // nanoseconds
4243
+ * span.end(customEndTime);
4244
+ * ```
4245
+ */
4246
+ end(endTime?: OTelTimeInput): void;
4247
+ /**
4248
+ * Returns whether this span is actively recording information.
4249
+ *
4250
+ * A recording span accepts and stores attributes, events, status, and other span data.
4251
+ * Non-recording spans (typically due to sampling decisions) may ignore operations
4252
+ * like setAttribute() to optimize performance. This method allows conditional
4253
+ * logic to avoid expensive operations on non-recording spans.
4254
+ *
4255
+ * @returns True if the span is actively recording information, false otherwise
4256
+ *
4257
+ * @remarks
4258
+ * - Recording status is typically determined at span creation time
4259
+ * - Non-recording spans still provide valid span context for propagation
4260
+ * - Use this check to avoid expensive attribute calculations for non-recording spans
4261
+ * - Recording status remains constant throughout the span's lifetime
4262
+ *
4263
+ * @example
4264
+ * ```typescript
4265
+ * const span = tracer.startSpan('data-processing');
4266
+ *
4267
+ * // Only perform expensive operations if span is recording
4268
+ * if (span.isRecording()) {
4269
+ * const metadata = await expensiveMetadataCalculation();
4270
+ * span.setAttributes({
4271
+ * 'process.metadata': JSON.stringify(metadata),
4272
+ * 'process.complexity': metadata.complexity,
4273
+ * 'process.estimated_duration': metadata.estimatedMs
4274
+ * });
4275
+ * }
4276
+ *
4277
+ * // Always safe to set basic attributes
4278
+ * span.setAttribute('process.started', true);
4279
+ * ```
4280
+ */
4281
+ isRecording(): boolean;
4282
+ /**
4283
+ * Records an exception as a span event with automatic error status handling.
4284
+ *
4285
+ * This method captures exception information and automatically creates a span event
4286
+ * with standardized exception attributes. It's the recommended way to handle errors
4287
+ * within spans, providing consistent error reporting across the application.
4288
+ *
4289
+ * @param exception - The exception to record; accepts string messages or Error objects
4290
+ * @param time - Optional timestamp for when the exception occurred; defaults to current time
4291
+ *
4292
+ * @remarks
4293
+ * - Automatically extracts exception type, message, and stack trace when available
4294
+ * - Creates a standardized span event with exception details
4295
+ * - Does NOT automatically set span status to ERROR - call setStatus() explicitly if needed
4296
+ * - Exception events are useful for debugging and error analysis
4297
+ *
4298
+ * @example
4299
+ * ```typescript
4300
+ * const span = tracer.startSpan('risky-operation');
4301
+ *
4302
+ * try {
4303
+ * await performRiskyOperation();
4304
+ * span.setStatus({ code: SpanStatusCode.OK });
4305
+ *
4306
+ * } catch (error) {
4307
+ * // Record the exception details
4308
+ * span.recordException(error);
4309
+ *
4310
+ * // Explicitly set error status
4311
+ * span.setStatus({
4312
+ * code: SpanStatusCode.ERROR,
4313
+ * message: 'Operation failed due to: ' + error.message
4314
+ * });
4315
+ *
4316
+ * // Re-throw if needed
4317
+ * throw error;
4318
+ * } finally {
4319
+ * span.end();
4320
+ * }
4321
+ *
4322
+ * // Recording string exceptions
4323
+ * span.recordException('Custom error message occurred');
4324
+ *
4325
+ * // Recording with custom timestamp
4326
+ * const errorTime = Date.now() * 1000000; // nanoseconds
4327
+ * span.recordException(error, errorTime);
4328
+ * ```
4329
+ */
4330
+ recordException(exception: OTelException, time?: OTelTimeInput): void;
4331
+ }
4332
+
4333
+ /**
4334
+ * A SpanContext represents the portion of a {@link IOTelSpan} which must be
4335
+ * serialized and propagated along side of a {@link IOTelBaggage}.
4336
+ */
4337
+ interface IOTelSpanContext extends IDistributedTraceInit {
4338
+ /**
4339
+ * Trace flags to propagate.
4340
+ *
4341
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
4342
+ * sampled or not. When set, the least significant bit documents that the
4343
+ * caller may have recorded trace data. A caller who does not record trace
4344
+ * data out-of-band leaves this flag unset.
4345
+ *
4346
+ * see {@link eW3CTraceFlags} for valid flag values.
4347
+ */
4348
+ traceFlags: number;
4349
+ }
4350
+
4351
+ /**
4352
+ * Provides an OpenTelemetry like Interface for the Open Telemetry Api (1.9.0) SpanOptions
4353
+ * type. Where SpanOptions are options that can be used to configure a span.
4354
+ */
4355
+ interface IOTelSpanOptions {
4356
+ /**
4357
+ * The SpanKind of a span of this span, this is used to specify
4358
+ * the relationship between the span and its parent span.
4359
+ * @see {@link eOTelSpanKind} for possible values.
4360
+ * @default eOTelSpanKind.INTERNAL
4361
+ */
4362
+ kind?: OTelSpanKind;
4363
+ /**
4364
+ * A span's attributes
4365
+ */
4366
+ attributes?: IOTelAttributes;
4367
+ /** A manually specified start time for the created `Span` object. */
4368
+ startTime?: OTelTimeInput;
4369
+ /** The new span should be a root span. (Ignore parent from context). */
4370
+ root?: boolean;
4371
+ /** Specify whether the span should be a recording span, default is true */
4372
+ recording?: boolean;
4373
+ }
4374
+
4375
+ interface IOTelSpanStatus {
4376
+ /**
4377
+ * The status code of this message.
4378
+ */
4379
+ code: eOTelSpanStatusCode;
4380
+ /**
4381
+ * A developer-facing error message.
4382
+ */
4383
+ message?: string;
4384
+ }
4385
+
4386
+ /**
4387
+ * OpenTelemetry tracer interface for creating and managing spans within a trace.
4388
+ *
4389
+ * A tracer is responsible for creating spans that represent units of work within a distributed system.
4390
+ * Each tracer is typically associated with a specific instrumentation library or component,
4391
+ * allowing for fine-grained control over how different parts of an application generate telemetry.
4392
+ *
4393
+ * @example
4394
+ * ```typescript
4395
+ * // Get a tracer instance
4396
+ * const tracer = otelApi.getTracer('my-service');
4397
+ *
4398
+ * // Create a simple span
4399
+ * const span = tracer.startSpan('database-query');
4400
+ * span.setAttribute('db.operation', 'SELECT');
4401
+ * span.end();
4402
+ *
4403
+ * // Create an active span with automatic context management
4404
+ * tracer.startActiveSpan('process-request', (span) => {
4405
+ * span.setAttribute('request.id', '12345');
4406
+ *
4407
+ * // Any spans created within this block will be children of this span
4408
+ * processRequest();
4409
+ *
4410
+ * span.end();
4411
+ * });
4412
+ * ```
4413
+ *
4414
+ * @see {@link IReadableSpan} - Interface for individual spans
4415
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
4416
+ *
4417
+ * @since 3.4.0
4418
+ */
4419
+ interface IOTelTracer {
4420
+ /**
4421
+ * Creates and starts a new span without setting it as the active span in the current context.
4422
+ *
4423
+ * This method creates a span but does NOT modify the current execution context.
4424
+ * The caller is responsible for managing the span's lifecycle, including calling `end()`
4425
+ * when the operation completes.
4426
+ *
4427
+ * @param name - The name of the span, should be descriptive of the operation being traced
4428
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
4429
+ *
4430
+ * @returns The newly created span, or null if span creation failed
4431
+ *
4432
+ * @remarks
4433
+ * - The returned span must be manually ended by calling `span.end()`
4434
+ * - This span will not automatically become the parent for spans created in nested operations
4435
+ * - Use `startActiveSpan` if you want automatic context management
4436
+ *
4437
+ * @example
4438
+ * ```typescript
4439
+ * const span = tracer.startSpan('database-operation');
4440
+ * if (span) {
4441
+ * try {
4442
+ * span.setAttribute('db.table', 'users');
4443
+ * span.setAttribute('db.operation', 'SELECT');
4444
+ *
4445
+ * // Perform database operation
4446
+ * const result = await db.query('SELECT * FROM users');
4447
+ *
4448
+ * span.setAttributes({
4449
+ * 'db.rows_affected': result.length,
4450
+ * 'operation.success': true
4451
+ * });
4452
+ * } catch (error) {
4453
+ * span.setStatus({
4454
+ * code: SpanStatusCode.ERROR,
4455
+ * message: error.message
4456
+ * });
4457
+ * span.recordException(error);
4458
+ * } finally {
4459
+ * span.end(); // Always end the span
4460
+ * }
4461
+ * }
4462
+ * ```
4463
+ */
4464
+ startSpan(name: string, options?: IOTelSpanOptions): IReadableSpan | null;
4465
+ /**
4466
+ * Creates and starts a new span, sets it as the active span in the current context,
4467
+ * and executes a provided function within this context.
4468
+ *
4469
+ * This method creates a span, makes it active during the execution of the provided
4470
+ * function, and automatically ends the span when the function completes (or throws).
4471
+ * This provides automatic span lifecycle management and context propagation.
4472
+ *
4473
+ * @param name - The name of the span, should be descriptive of the operation being traced
4474
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
4475
+ * @param fn - The function to execute within the span's active context
4476
+ *
4477
+ * @returns The result of executing the provided function
4478
+ *
4479
+ * @remarks
4480
+ * - The span is automatically ended when the function completes or throws an exception
4481
+ * - The span becomes the active parent for any spans created within the function
4482
+ * - If the function throws an error, the span status is automatically set to ERROR
4483
+ * - This is the recommended method for most tracing scenarios due to automatic lifecycle management
4484
+ * - Multiple overloads available for different parameter combinations
4485
+ *
4486
+ * @example
4487
+ * ```typescript
4488
+ * // Synchronous operation with just name and function
4489
+ * const result = tracer.startActiveSpan('user-service', (span) => {
4490
+ * span.setAttribute('operation', 'get-user-details');
4491
+ * return { user: getUserData(), timestamp: new Date().toISOString() };
4492
+ * });
4493
+ *
4494
+ * // With options
4495
+ * const result2 = tracer.startActiveSpan('database-query',
4496
+ * { attributes: { 'db.table': 'users' } },
4497
+ * (span) => {
4498
+ * span.setAttribute('db.operation', 'SELECT');
4499
+ * return database.getUser('123');
4500
+ * }
4501
+ * );
4502
+ *
4503
+ * // With full context control
4504
+ * const result3 = tracer.startActiveSpan('external-api',
4505
+ * { attributes: { 'service.name': 'payment-api' } },
4506
+ * currentContext,
4507
+ * async (span) => {
4508
+ * try {
4509
+ * const response = await fetch('/api/payment');
4510
+ * span.setAttributes({
4511
+ * 'http.status_code': response.status,
4512
+ * 'operation.success': response.ok
4513
+ * });
4514
+ * return response.json();
4515
+ * } catch (error) {
4516
+ * span.setAttribute('error.type', error.constructor.name);
4517
+ * throw error; // Error automatically recorded
4518
+ * }
4519
+ * }
4520
+ * );
4521
+ * ```
4522
+ */
4523
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, fn: F): ReturnType<F>;
4524
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, options: IOTelSpanOptions, fn: F): ReturnType<F>;
4525
+ }
2800
4526
 
2801
- interface IOfflineListener {
2802
- isOnline: () => boolean;
2803
- isListening: () => boolean;
2804
- unload: () => void;
2805
- addListener: (callback: OfflineCallback) => IUnloadHook;
2806
- setOnlineState: (uState: eOfflineValue) => void;
4527
+ interface IOTelTracerOptions {
4528
+ /**
4529
+ * The schemaUrl of the tracer or instrumentation library
4530
+ */
4531
+ schemaUrl?: string;
2807
4532
  }
2808
4533
 
2809
4534
  /**
2810
- * This is the interface for the Offline state
2811
- * runtime state is retrieved from the browser state
2812
- * user state is set by the user
4535
+ * OpenTelemetry Trace API for getting tracers.
4536
+ * This provides the standard OpenTelemetry trace API entry point.
2813
4537
  */
2814
- interface IOfflineState {
2815
- readonly isOnline: boolean;
2816
- readonly rState: eOfflineValue;
2817
- readonly uState: eOfflineValue;
4538
+ interface IOTelTracerProvider {
4539
+ /**
4540
+ * Returns a Tracer, creating one if one with the given name and version is
4541
+ * not already created. This may return
4542
+ * - The same Tracer instance if one has already been created with the same name and version
4543
+ * - A new Tracer instance if one has not already been created with the same name and version
4544
+ * - A non-operational Tracer if the provider is not operational
4545
+ *
4546
+ * @param name - The name of the tracer or instrumentation library.
4547
+ * @param version - The version of the tracer or instrumentation library.
4548
+ * @param options - The options of the tracer or instrumentation library.
4549
+ * @returns Tracer A Tracer with the given name and version
4550
+ */
4551
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
4552
+ /**
4553
+ * Forces the tracer provider to flush any buffered data.
4554
+ * @returns A promise that resolves when the flush is complete.
4555
+ */
4556
+ forceFlush?: () => IPromise<void> | void;
4557
+ /**
4558
+ * Shuts down the tracer provider and releases any resources.
4559
+ * @returns A promise that resolves when the shutdown is complete.
4560
+ */
4561
+ shutdown?: () => IPromise<void> | void;
2818
4562
  }
2819
4563
 
2820
- interface IOperatingSystem {
2821
- name: string;
4564
+ /**
4565
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Api (1.9.0) TraceState type.
4566
+ *
4567
+ * The TraceState is a list of key/value pairs that are used to propagate
4568
+ * vendor-specific trace information across different distributed tracing systems.
4569
+ * The TraceState is used to store the state of a trace across different
4570
+ * distributed tracing systems, and it is used to ensure that the trace information
4571
+ * is consistent across different systems.
4572
+ *
4573
+ * Instances of TraceState are immutable, and the methods on this interface
4574
+ * return a new instance of TraceState with the updated values.
4575
+ */
4576
+ interface IOTelTraceState {
4577
+ /**
4578
+ * Create a new TraceState which inherits from this TraceState and has the
4579
+ * given key set.
4580
+ * The new entry will always be added in the front of the list of states.
4581
+ *
4582
+ * @param key - key of the TraceState entry.
4583
+ * @param value - value of the TraceState entry.
4584
+ */
4585
+ set(key: string, value: string): IOTelTraceState;
4586
+ /**
4587
+ * Return a new TraceState which inherits from this TraceState but does not
4588
+ * contain the given key.
4589
+ *
4590
+ * @param key - the key for the TraceState entry to be removed.
4591
+ */
4592
+ unset(key: string): IOTelTraceState;
4593
+ /**
4594
+ * Returns the value to which the specified key is mapped, or `undefined` if
4595
+ * this map contains no mapping for the key.
4596
+ *
4597
+ * @param key - with which the specified value is to be associated.
4598
+ * @returns the value to which the specified key is mapped, or `undefined` if
4599
+ * this map contains no mapping for the key.
4600
+ */
4601
+ get(key: string): string | undefined;
4602
+ /**
4603
+ * Serializes the TraceState to a `list` as defined below. The `list` is a series of `list-members`
4604
+ * separated by commas `,`, and a list-member is a key/value pair separated by an equals sign `=`.
4605
+ * Spaces and horizontal tabs surrounding `list-members` are ignored. There can be a maximum of 32
4606
+ * `list-members` in a `list`.
4607
+ *
4608
+ * If the resulting serialization is limited to no longer than 512 bytes, if the combination of
4609
+ * keys and values exceeds this limit, the serialization will be truncated to the last key/value pair
4610
+ * that fits within the limit. The serialization will be returned as a string.
4611
+ *
4612
+ * This is different from the {@link IW3cTraceState} serialization which returns an array of strings where each
4613
+ * string is limited to 512 bytes and the array is limited to 32 strings. Thus the OpenTelemetry serialization
4614
+ * will only return the first single string that fits within the limie.
4615
+ *
4616
+ * @returns the serialized string.
4617
+ */
4618
+ serialize(): string;
2822
4619
  }
2823
4620
 
2824
4621
  /**
@@ -3401,6 +5198,44 @@ declare namespace ApplicationInsights {
3401
5198
  readonly context: ITelemetryContext;
3402
5199
  }
3403
5200
 
5201
+ /**
5202
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Sdk-Trace-Base (1.8.0 and 2.0.0) ReadableSpan type.
5203
+ *
5204
+ * The IReadableSpan interface is used to represent a span that can be read and exported, while the OpenTelemetry
5205
+ * specification defines a ReadableSpan as a Span that has been ended and is ready to be exported. By default all
5206
+ * spans created by this library implement the IReadableSpan interface which also extends the {@link IOTelSpan} interface.
5207
+ *
5208
+ * This interface is defined to provide compatibility with exporters defined by the OpenTelemetry Trace SDK.
5209
+ * @since 3.4.0
5210
+ */
5211
+ interface IReadableSpan extends IOTelSpan {
5212
+ /**
5213
+ * The span's unique identifier.
5214
+ */
5215
+ readonly name: string;
5216
+ /**
5217
+ * Identifies the type (or kind) that this span is representing.
5218
+ */
5219
+ readonly kind: OTelSpanKind;
5220
+ readonly spanContext: () => IDistributedTraceContext;
5221
+ readonly parentSpanId?: string;
5222
+ readonly parentSpanContext?: IDistributedTraceContext;
5223
+ readonly startTime: IOTelHrTime;
5224
+ readonly endTime: IOTelHrTime;
5225
+ readonly status: IOTelSpanStatus;
5226
+ /**
5227
+ * Provides a snapshot of the span's attributes at the time this span was ended.
5228
+ * @returns A read-only snapshot of the span's attributes
5229
+ * @remarks
5230
+ * It is recommended that you only access this property sparingly due to the
5231
+ * performance cost of taking a snapshot of all attributes.
5232
+ */
5233
+ readonly attributes: IOTelAttributes;
5234
+ readonly duration: IOTelHrTime;
5235
+ readonly ended: boolean;
5236
+ readonly droppedAttributesCount: number;
5237
+ }
5238
+
3404
5239
  /**
3405
5240
  * An instance of Remote Dependency represents an interaction of the monitored component with a remote component/service like SQL or an HTTP endpoint.
3406
5241
  */
@@ -3496,6 +5331,40 @@ declare namespace ApplicationInsights {
3496
5331
  requestContextHeaderLowerCase: string;
3497
5332
  }
3498
5333
 
5334
+ /**
5335
+ * This defines the contract for request telemetry items that are passed to Application Insights API (track)
5336
+ */
5337
+ interface IRequestTelemetry extends IPartC {
5338
+ /**
5339
+ * Identifier of a request call instance. Used for correlation between request and other telemetry items.
5340
+ */
5341
+ id: string;
5342
+ /**
5343
+ * Name of the request. Represents code path taken to process request. Low cardinality value to allow better grouping of requests. For HTTP requests it represents the HTTP method and URL path template like 'GET /values/\{id\}'.
5344
+ */
5345
+ name?: string;
5346
+ /**
5347
+ * Request duration in milliseconds.
5348
+ */
5349
+ duration: number;
5350
+ /**
5351
+ * Indication of successful or unsuccessful call.
5352
+ */
5353
+ success: boolean;
5354
+ /**
5355
+ * Result of a request execution. HTTP status code for HTTP requests.
5356
+ */
5357
+ responseCode: number;
5358
+ /**
5359
+ * Source of the request. Examples are the instrumentation key of the caller or the ip address of the caller.
5360
+ */
5361
+ source?: string;
5362
+ /**
5363
+ * Request URL with all query string parameters.
5364
+ */
5365
+ url?: string;
5366
+ }
5367
+
3499
5368
  interface ISample {
3500
5369
  /**
3501
5370
  * Sample rate
@@ -3505,7 +5374,9 @@ declare namespace ApplicationInsights {
3505
5374
  }
3506
5375
 
3507
5376
  /**
3508
- * Checks if HTML5 Beacons are supported in the current environment.
5377
+ * Checks if HTML5 Beacons are supported in the current environment. There is a side effect (for testing)
5378
+ * when `useCached` is set to `false`, it will reset the cached value causing all future calls to
5379
+ * use the new re-evaluated value for all future calls.
3509
5380
  * @param useCached - [Optional] used for testing to bypass the cached lookup, when `true` this will
3510
5381
  * cause the cached global to be reset.
3511
5382
  * @returns True if supported, false otherwise.
@@ -3520,7 +5391,9 @@ declare namespace ApplicationInsights {
3520
5391
  * This defines the serialization order and a value of true/false
3521
5392
  * for each field defines whether the field is required or not.
3522
5393
  */
3523
- aiDataContract: any;
5394
+ aiDataContract: {
5395
+ [key: string]: FieldType | (() => FieldType);
5396
+ };
3524
5397
  }
3525
5398
 
3526
5399
  interface ISession {
@@ -3565,6 +5438,35 @@ declare namespace ApplicationInsights {
3565
5438
 
3566
5439
  function isInternalApplicationInsightsEndpoint(endpointUrl: string): boolean;
3567
5440
 
5441
+ /**
5442
+ * Represents the execution scope for a span, combining the trace instance and the active span.
5443
+ * This interface is used as the context for executing functions within a span's scope.
5444
+ *
5445
+ * @since 3.4.0
5446
+ */
5447
+ interface ISpanScope<T extends ITraceHost = ITraceHost> {
5448
+ /**
5449
+ * The trace host (core or AISKU instance).
5450
+ * @since 3.4.0
5451
+ */
5452
+ readonly host: T;
5453
+ /**
5454
+ * The active span for this execution scope.
5455
+ * @since 3.4.0
5456
+ */
5457
+ readonly span: IReadableSpan;
5458
+ /**
5459
+ * The previously active span before this scope was created, if any.
5460
+ * @since 3.4.0
5461
+ */
5462
+ readonly prvSpan?: IReadableSpan;
5463
+ /**
5464
+ * Restores the previous active span in the trace instance.
5465
+ * @since 3.4.0
5466
+ */
5467
+ restore(): void;
5468
+ }
5469
+
3568
5470
  /**
3569
5471
  * Is the parsed traceParent indicating that the trace is currently sampled.
3570
5472
  * @param value - The parsed traceParent value
@@ -3664,6 +5566,8 @@ declare namespace ApplicationInsights {
3664
5566
  readonly location: ILocation;
3665
5567
  /**
3666
5568
  * The object describing a operation tracked by this object.
5569
+ * @deprecated Use the core getTraceCtx method instead to get / set the current trace context, this is required to
5570
+ * support distributed tracing and allows the core to manage the trace context.
3667
5571
  */
3668
5572
  readonly telemetryTrace: ITelemetryTrace;
3669
5573
  /**
@@ -3804,6 +5708,11 @@ declare namespace ApplicationInsights {
3804
5708
  update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
3805
5709
  }
3806
5710
 
5711
+ /**
5712
+ * Interface for telemetry trace context.
5713
+ * @deprecated Use the core getTraceCtx method instead to get / set the current trace context, this is required to
5714
+ * support distributed tracing and allows the core to manage the trace context.
5715
+ */
3807
5716
  interface ITelemetryTrace {
3808
5717
  /**
3809
5718
  * Trace id
@@ -3813,11 +5722,6 @@ declare namespace ApplicationInsights {
3813
5722
  * Parent id
3814
5723
  */
3815
5724
  parentID?: string;
3816
- /**
3817
- * @deprecated Never Used
3818
- * Trace state
3819
- */
3820
- traceState?: ITraceState;
3821
5725
  /**
3822
5726
  * An integer representation of the W3C TraceContext trace-flags. https://www.w3.org/TR/trace-context/#trace-flags
3823
5727
  */
@@ -4074,6 +5978,165 @@ declare namespace ApplicationInsights {
4074
5978
  enabled: boolean;
4075
5979
  }
4076
5980
 
5981
+ /**
5982
+ * ITraceApi provides an interface definition which is simular to the OpenTelemetry TraceAPI
5983
+ */
5984
+ interface ITraceApi {
5985
+ /**
5986
+ * Returns a Tracer, creating one if one with the given name and version
5987
+ * if one has not already created.
5988
+ *
5989
+ * @param name - The name of the tracer or instrumentation library.
5990
+ * @param version - The version of the tracer or instrumentation library.
5991
+ * @param options - The options of the tracer or instrumentation library.
5992
+ * @returns Tracer A Tracer with the given name and version
5993
+ */
5994
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
5995
+ /**
5996
+ * Wrap the given {@link IDistributedTraceContext} in a new non-recording {@link IReadableSpan}
5997
+ *
5998
+ * @param spanContext - The {@link IDistributedTraceContext} to be wrapped
5999
+ * @returns a new non-recording {@link IReadableSpan} with the provided context
6000
+ */
6001
+ wrapSpanContext(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): IReadableSpan;
6002
+ /**
6003
+ * Returns true if this {@link IDistributedTraceContext} is valid.
6004
+ * @return true if this {@link IDistributedTraceContext} is valid.
6005
+ */
6006
+ isSpanContextValid(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): boolean;
6007
+ /**
6008
+ * Gets the span from the current context, if one exists.
6009
+ */
6010
+ getActiveSpan(): IReadableSpan | undefined | null;
6011
+ /**
6012
+ * Set or clear the current active span.
6013
+ * @param span - The span to set as the active span, or null/undefined to clear the active span.
6014
+ * @return An ISpanScope instance returned by the host, or void if there is no defined host.
6015
+ */
6016
+ setActiveSpan(span: IReadableSpan | undefined | null): ISpanScope | undefined | null;
6017
+ }
6018
+
6019
+ /**
6020
+ * Configuration interface for OpenTelemetry compatible tracing functionality.
6021
+ * This interface contains all the settings that control how traces are created,
6022
+ * processed, and managed within the OpenTelemetry system.
6023
+ *
6024
+ * @example
6025
+ * ```typescript
6026
+ * const traceCfg: ITraceCfg = {
6027
+ * serviceName: "my-service",
6028
+ * generalLimits: {
6029
+ * attributeCountLimit: 128,
6030
+ * attributeValueLengthLimit: 4096
6031
+ * },
6032
+ * spanLimits: {
6033
+ * attributeCountLimit: 128,
6034
+ * linkCountLimit: 128,
6035
+ * eventCountLimit: 128
6036
+ * }
6037
+ * };
6038
+ * ```
6039
+ *
6040
+ * @since 3.4.0
6041
+ */
6042
+ interface ITraceCfg {
6043
+ /**
6044
+ * Global attribute limits that apply to all telemetry items.
6045
+ * These limits help prevent excessive memory usage and ensure consistent
6046
+ * behavior across different telemetry types.
6047
+ *
6048
+ * @remarks
6049
+ * These limits are inherited by more specific configurations unless overridden.
6050
+ * For example, spans will use these limits unless `spanLimits` specifies different values.
6051
+ */
6052
+ generalLimits?: IOTelAttributeLimits;
6053
+ /**
6054
+ * The name of the service generating telemetry data.
6055
+ * This name will be included in all telemetry items as a resource attribute.
6056
+ *
6057
+ * @remarks
6058
+ * The service name is crucial for identifying and filtering telemetry data
6059
+ * in observability systems. It should be consistent across all instances
6060
+ * of the same service.
6061
+ *
6062
+ * @example
6063
+ * ```typescript
6064
+ * serviceName: "user-authentication-service"
6065
+ * ```
6066
+ */
6067
+ serviceName?: string;
6068
+ /**
6069
+ * A flag that indicates whether the tracing (creating of a "trace" event) should be suppressed
6070
+ * when a {@link IOTelSpan} ends and the span {@link IOTelSpan#isRecording | isRecording} is true.
6071
+ * This value is also inherited by spans when they are created.
6072
+ */
6073
+ suppressTracing?: boolean;
6074
+ }
6075
+
6076
+ /**
6077
+ * Interface for OpenTelemetry trace operations.
6078
+ * This interface provides span creation, context management, and trace provider operations
6079
+ * that are common across different SDK implementations (Core, AISKU, etc.).
6080
+ *
6081
+ * @since 3.4.0
6082
+ */
6083
+ interface ITraceHost<CfgType extends IConfiguration = IConfiguration> {
6084
+ readonly config: CfgType;
6085
+ /**
6086
+ * Gets the current distributed trace active context for this instance
6087
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true. By default this
6088
+ * will use any located parent as defined by the {@link IConfiguration.traceHdrMode} configuration for each new instance created.
6089
+ */
6090
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
6091
+ /**
6092
+ * Sets the current distributed trace context for this instance if available
6093
+ */
6094
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
6095
+ /**
6096
+ * Start a new span with the given name and optional parent context.
6097
+ *
6098
+ * Note: This method only creates and returns the span. It does not automatically
6099
+ * set the span as the active trace context. Context management should be handled
6100
+ * separately using setTraceCtx() if needed.
6101
+ *
6102
+ * @param name - The name of the span
6103
+ * @param options - Options for creating the span (kind, attributes, startTime)
6104
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
6105
+ * @returns A new span instance, or null if no trace provider is available
6106
+ * @since 3.4.0
6107
+ *
6108
+ * @see {@link IReadableSpan} - Interface for individual spans
6109
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
6110
+ */
6111
+ startSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan | null;
6112
+ /**
6113
+ * Return the current active span, if no trace provider is available null will be returned
6114
+ * but when a trace provider is available a span instance will always be returned, even if
6115
+ * there is no active span (in which case a non-recording span will be returned).
6116
+ * @param createNew - Optional flag to create a non-recording span if no active span exists, defaults to true.
6117
+ * When false, returns the existing active span or null without creating a non-recording span, which can improve
6118
+ * performance when only checking if an active span exists.
6119
+ * @returns The current active span or null if no trace provider is available or if createNew is false and no active span exists
6120
+ * @since 3.4.0
6121
+ */
6122
+ getActiveSpan(createNew?: boolean): IReadableSpan | null;
6123
+ /**
6124
+ * Set the current Active Span, if no trace provider is available the span will be not be set as the active span.
6125
+ * @param span - The span to set as the active span
6126
+ * @returns An ISpanScope instance that provides the current scope, the span will always be the span passed in
6127
+ * even when no trace provider is available
6128
+ * @since 3.4.0
6129
+ */
6130
+ setActiveSpan(span: IReadableSpan): ISpanScope;
6131
+ /**
6132
+ * Get the current trace provider.
6133
+ *
6134
+ * @returns The current trace provider, or null if none is set
6135
+ * @since 3.4.0
6136
+ */
6137
+ getTraceProvider(): ITraceProvider | null;
6138
+ }
6139
+
4077
6140
  /**
4078
6141
  * This interface represents the components of a W3C traceparent header
4079
6142
  */
@@ -4107,7 +6170,44 @@ declare namespace ApplicationInsights {
4107
6170
  traceFlags: number;
4108
6171
  }
4109
6172
 
4110
- interface ITraceState {
6173
+ /**
6174
+ * A trace provider interface that enables different SKUs to provide their own
6175
+ * span implementations while being managed by the core SDK.
6176
+ *
6177
+ * This follows the OpenTelemetry TraceProvider pattern, allowing the core to
6178
+ * delegate span creation to the appropriate implementation based on the SDK variant.
6179
+ *
6180
+ * @since 3.4.0
6181
+ */
6182
+ interface ITraceProvider {
6183
+ /**
6184
+ * The OpenTelemetry API instance associated with this trace provider.
6185
+ * This provides access to the tracer provider and other OpenTelemetry functionality.
6186
+ * @since 3.4.0
6187
+ */
6188
+ readonly api: IOTelApi;
6189
+ /**
6190
+ * Creates a new span with the given name and options.
6191
+ *
6192
+ * @param name - The name of the span
6193
+ * @param options - Options for creating the span (kind, attributes, startTime)
6194
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
6195
+ * @returns A new span instance specific to this provider's implementation
6196
+ * @since 3.4.0
6197
+ */
6198
+ createSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan;
6199
+ /**
6200
+ * Gets the provider identifier for debugging and logging purposes.
6201
+ * @returns A string identifying this trace provider implementation
6202
+ * @since 3.4.0
6203
+ */
6204
+ getProviderId(): string;
6205
+ /**
6206
+ * Determines if this provider is available and ready to create spans.
6207
+ * @returns true if the provider can create spans, false otherwise
6208
+ * @since 3.4.0
6209
+ */
6210
+ isAvailable(): boolean;
4111
6211
  }
4112
6212
 
4113
6213
  interface ITraceTelemetry extends IPartC {
@@ -4176,6 +6276,76 @@ declare namespace ApplicationInsights {
4176
6276
  update(userId?: string): void;
4177
6277
  }
4178
6278
 
6279
+ /**
6280
+ * Represents a mutable [W3C trace state list](https://www.w3.org/TR/trace-context/#tracestate-header), this is a
6281
+ * list of key/value pairs that are used to pass trace state information between different tracing systems. The
6282
+ * list is ordered and the order is important as it determines the processing order.
6283
+ *
6284
+ * Importantly instances of this type are mutable, change made to an instance via {@link IW3cTraceState.set} or
6285
+ * {@link IW3cTraceState.del} will be reflected on the instance and any child instances that use it as a parent.
6286
+ * However, any parent instance associated with an instance will not be modified by operations on that particular
6287
+ * instance.
6288
+ *
6289
+ * @since 3.4.0
6290
+ */
6291
+ interface IW3cTraceState {
6292
+ /**
6293
+ * Returns a readonly array of the current keys associated with the trace state, keys are returned in the
6294
+ * required processing order and if this instance has a parent the keys from the parent will be included
6295
+ * unless they have been removed (deleted) from the child instance.
6296
+ * Once created any modifications to the parent will also be reflected in the child, this is different from
6297
+ * the OpenTelemetry implementation which creates a new instance for each call.
6298
+ * @returns A readonly array of the current keys associated with the trace state
6299
+ */
6300
+ readonly keys: string[];
6301
+ /**
6302
+ * Check if the trace state list is empty, meaning it has no keys or values.
6303
+ * This exists to allow for quick checks without needing to create a new array of keys.
6304
+ * @since 3.4.0
6305
+ * @returns true if the trace state list is empty, false otherwise
6306
+ */
6307
+ readonly isEmpty: boolean;
6308
+ /**
6309
+ * Get the value for the specified key that is associated with this instance, either directly or from the parent.
6310
+ * @param key - The key to lookup
6311
+ * @returns The value for the key, or undefined if not found
6312
+ */
6313
+ get(key: string): string | undefined;
6314
+ /**
6315
+ * Set the value for the specified key for this instance, returning its new location within the list.
6316
+ * - 0 is the front of the list
6317
+ * - -1 not set because the key/value pair is invalid
6318
+ * If the key already exists it will be removed from its current location and added to the front of the list. And
6319
+ * if the key was in the parent this will override the value inherited from the parent, more importantly it will
6320
+ * not modify the parent value.
6321
+ * @param key - The key to set
6322
+ * @param value - The value to set
6323
+ * @returns 0 if successful, -1 if not
6324
+ */
6325
+ set(key: string, value: string): number;
6326
+ /**
6327
+ * Delete the specified key from this instance, if the key was in the parent it will be removed (hidden) from
6328
+ * this instance but will still be available directly from the parent.
6329
+ * @param key - The key to delete
6330
+ */
6331
+ del(key: string): void;
6332
+ /**
6333
+ * Format the trace state list into a strings where each string can be used as a header value.
6334
+ * This will return an empty array if the trace state list is empty.
6335
+ * @param maxHeaders - The maximum number of entries to include in the output, once the limit is reached no more entries will be included
6336
+ * @param maxKeys - The maximum number of keys to include in the output, once the limit is reached no more keys will be included
6337
+ * @param maxLen - The maximum length of each header value, once the limit is reached a new header value will be created
6338
+ * @returns An array of strings that can be used for the header values, if the trace state list is empty an empty array will be returned
6339
+ */
6340
+ hdrs(maxHeaders?: number, maxKeys?: number, maxLen?: number): string[];
6341
+ /**
6342
+ * Create a new instance of IW3cTraceState which is a child of this instance, meaning it will inherit the keys
6343
+ * and values from this instance but any changes made to the child will not affect this instance.
6344
+ * @returns A new instance of IW3cTraceState which is a child of this instance
6345
+ */
6346
+ child(): IW3cTraceState;
6347
+ }
6348
+
4179
6349
  interface IWatchDetails<T = IConfiguration> {
4180
6350
  /**
4181
6351
  * The current config object
@@ -4246,7 +6416,13 @@ declare namespace ApplicationInsights {
4246
6416
  type LoggingSeverity = number | eLoggingSeverity;
4247
6417
 
4248
6418
  class Metric implements IMetricData, ISerializable {
6419
+ /**
6420
+ * @deprecated Use the constant MetricEnvelopeType instead.
6421
+ */
4249
6422
  static envelopeType: string;
6423
+ /**
6424
+ * @deprecated Use the constant MetricDataType instead.
6425
+ */
4250
6426
  static dataType: string;
4251
6427
  aiDataContract: {
4252
6428
  ver: FieldType;
@@ -4277,10 +6453,14 @@ declare namespace ApplicationInsights {
4277
6453
  });
4278
6454
  }
4279
6455
 
6456
+ const MetricDataType = "MetricData";
6457
+
6458
+ const MetricEnvelopeType: string;
6459
+
4280
6460
  /**
4281
6461
  * Convert ms to c# time span format
4282
6462
  */
4283
- function msToTimeSpan(totalms: number): string;
6463
+ function msToTimeSpan(totalms: number | string): string;
4284
6464
 
4285
6465
  /**
4286
6466
  * this is the callback that will be called when the network status changes
@@ -4288,8 +6468,82 @@ declare namespace ApplicationInsights {
4288
6468
  */
4289
6469
  type OfflineCallback = (onlineState: IOfflineState) => void;
4290
6470
 
6471
+ /**
6472
+ * Attribute values may be any non-nullish primitive value except an object.
6473
+ *
6474
+ * null or undefined attribute values are invalid and will result in undefined behavior.
6475
+ *
6476
+ * @since 3.4.0
6477
+ */
6478
+ type OTelAttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
6479
+
6480
+ /**
6481
+ * Defines Exception.
6482
+ *
6483
+ * string or an object with one of (message or name or code) and optional stack
6484
+ *
6485
+ * @since 3.4.0
6486
+ */
6487
+ type OTelException = IOTelExceptionWithCode | IOTelExceptionWithMessage | IOTelExceptionWithName | string;
6488
+
6489
+ /**
6490
+ * High-resolution time represented as a tuple of [seconds, nanoseconds].
6491
+ * This is the base type for all OpenTelemetry high-resolution time values.
6492
+ *
6493
+ * @remarks
6494
+ * The first element represents seconds since Unix epoch, and the second element
6495
+ * represents nanoseconds (0-999,999,999) within that second.
6496
+ *
6497
+ * @example
6498
+ * ```typescript
6499
+ * const hrTime: OTelHrTimeBase = [1609459200, 500000000]; // 2021-01-01 00:00:00.5 UTC
6500
+ * ```
6501
+ *
6502
+ * @since 3.4.0
6503
+ */
6504
+ type OTelHrTimeBase = [number, number];
6505
+
6506
+ /**
6507
+ * Creates an enum style object for the OTelSpanKind enum, providing the enum
6508
+ * values as properties of the object as both string and number types.
6509
+ * This allows for easy access to the enum values in a more readable format.
6510
+ */
6511
+ const OTelSpanKind: EnumValue<typeof eOTelSpanKind>;
6512
+
6513
+ type OTelSpanKind = number | eOTelSpanKind;
6514
+
6515
+ /**
6516
+ * Union type representing all valid time input formats accepted by OpenTelemetry APIs.
6517
+ *
6518
+ * @remarks
6519
+ * - `IOTelHrTime`: High-resolution time with nanosecond precision
6520
+ * - `number`: Milliseconds since Unix epoch (JavaScript Date.now() format)
6521
+ * - `Date`: JavaScript Date object
6522
+ *
6523
+ * @example
6524
+ * ```typescript
6525
+ * // All of these are valid time inputs:
6526
+ * const hrTime: OTelTimeInput = [1609459200, 500000000];
6527
+ * const msTime: OTelTimeInput = Date.now();
6528
+ * const dateTime: OTelTimeInput = new Date();
6529
+ *
6530
+ * span.addEvent("event", {}, hrTime);
6531
+ * span.addEvent("event", {}, msTime);
6532
+ * span.addEvent("event", {}, dateTime);
6533
+ * ```
6534
+ *
6535
+ * @since 3.4.0
6536
+ */
6537
+ type OTelTimeInput = IOTelHrTime | number | Date;
6538
+
4291
6539
  class PageView implements IPageViewData, ISerializable {
6540
+ /**
6541
+ * @deprecated Use the constant PageViewEnvelopeType instead.
6542
+ */
4292
6543
  static envelopeType: string;
6544
+ /**
6545
+ * @deprecated Use the constant PageViewDataType instead.
6546
+ */
4293
6547
  static dataType: string;
4294
6548
  aiDataContract: {
4295
6549
  ver: FieldType;
@@ -4338,8 +6592,18 @@ declare namespace ApplicationInsights {
4338
6592
  }, id?: string);
4339
6593
  }
4340
6594
 
6595
+ const PageViewDataType = "PageviewData";
6596
+
6597
+ const PageViewEnvelopeType: string;
6598
+
4341
6599
  class PageViewPerformance implements IPageViewPerfData, ISerializable {
6600
+ /**
6601
+ * @deprecated Use the constant PageViewPerformanceEnvelopeType instead.
6602
+ */
4342
6603
  static envelopeType: string;
6604
+ /**
6605
+ * @deprecated Use the constant PageViewPerformanceDataType instead.
6606
+ */
4343
6607
  static dataType: string;
4344
6608
  aiDataContract: {
4345
6609
  ver: FieldType;
@@ -4412,6 +6676,10 @@ declare namespace ApplicationInsights {
4412
6676
  }, cs4BaseData?: IPageViewPerformanceTelemetry);
4413
6677
  }
4414
6678
 
6679
+ const PageViewPerformanceDataType = "PageviewPerformanceData";
6680
+
6681
+ const PageViewPerformanceEnvelopeType: string;
6682
+
4415
6683
  function parseConnectionString(connectionString?: string): ConnectionString;
4416
6684
 
4417
6685
  /**
@@ -4434,8 +6702,18 @@ declare namespace ApplicationInsights {
4434
6702
  */
4435
6703
  type RejectedPromiseHandler<T = never> = (((reason: any) => T | IPromise<T> | PromiseLike<T>) | undefined | null);
4436
6704
 
6705
+ /**
6706
+ * @deprecated - will be removed in future releases as this was only used by the applicationinsights-channel-js package.
6707
+ * And it no longer uses this class.
6708
+ */
4437
6709
  class RemoteDependencyData implements IRemoteDependencyData, ISerializable {
6710
+ /**
6711
+ * @deprecated Use the constant RemoteDependencyEnvelopeType instead.
6712
+ */
4438
6713
  static envelopeType: string;
6714
+ /**
6715
+ * @deprecated Use the constant RemoteDependencyDataType instead.
6716
+ */
4439
6717
  static dataType: string;
4440
6718
  aiDataContract: {
4441
6719
  id: FieldType;
@@ -4510,6 +6788,14 @@ declare namespace ApplicationInsights {
4510
6788
  constructor(logger: IDiagnosticLogger, id: string, absoluteUrl: string, commandName: string, value: number, success: boolean, resultCode: number, method?: string, requestAPI?: string, correlationContext?: string, properties?: Object, measurements?: Object);
4511
6789
  }
4512
6790
 
6791
+ const RemoteDependencyDataType = "RemoteDependencyData";
6792
+
6793
+ const RemoteDependencyEnvelopeType: string;
6794
+
6795
+ const RequestDataType = "RequestData";
6796
+
6797
+ const RequestEnvelopeType: string;
6798
+
4513
6799
  const RequestHeaders: IRequestHeaders & {
4514
6800
  requestContextHeader: "Request-Context";
4515
6801
  requestContextTargetKey: "appId";
@@ -4682,7 +6968,13 @@ declare namespace ApplicationInsights {
4682
6968
  }
4683
6969
 
4684
6970
  class Trace implements IMessageData, ISerializable {
6971
+ /**
6972
+ * @deprecated Use the constant TraceEnvelopeType instead.
6973
+ */
4685
6974
  static envelopeType: string;
6975
+ /**
6976
+ * @deprecated Use the constant TraceDataType instead.
6977
+ */
4686
6978
  static dataType: string;
4687
6979
  aiDataContract: {
4688
6980
  ver: FieldType;
@@ -4718,6 +7010,10 @@ declare namespace ApplicationInsights {
4718
7010
  });
4719
7011
  }
4720
7012
 
7013
+ const TraceDataType = "MessageData";
7014
+
7015
+ const TraceEnvelopeType: string;
7016
+
4721
7017
  type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
4722
7018
 
4723
7019
  function urlGetAbsoluteUrl(url: string): string;