@microsoft/applicationinsights-osplugin-js 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 (48) hide show
  1. package/browser/es5/{ai.osplugin.3.3.12-nightly3.2602-20.js → ai.osplugin.3.4.0-beta.cjs.js} +119 -194
  2. package/browser/es5/ai.osplugin.3.4.0-beta.cjs.js.map +1 -0
  3. package/browser/es5/ai.osplugin.3.4.0-beta.cjs.min.js +6 -0
  4. package/browser/es5/ai.osplugin.3.4.0-beta.cjs.min.js.map +1 -0
  5. package/browser/es5/{ai.osplugin.3.3.12-nightly3.2602-20.gbl.js → ai.osplugin.3.4.0-beta.gbl.js} +121 -169
  6. package/browser/es5/ai.osplugin.3.4.0-beta.gbl.js.map +1 -0
  7. package/browser/es5/ai.osplugin.3.4.0-beta.gbl.min.js +6 -0
  8. package/browser/es5/ai.osplugin.3.4.0-beta.gbl.min.js.map +1 -0
  9. package/browser/es5/ai.osplugin.3.4.0-beta.integrity.json +66 -0
  10. package/browser/es5/{ai.osplugin.3.3.12-nightly3.2602-20.cjs.js → ai.osplugin.3.4.0-beta.js} +146 -167
  11. package/browser/es5/ai.osplugin.3.4.0-beta.js.map +1 -0
  12. package/browser/es5/ai.osplugin.3.4.0-beta.min.js +6 -0
  13. package/browser/es5/ai.osplugin.3.4.0-beta.min.js.map +1 -0
  14. package/browser/es5/ai.osplugin.3.cjs.js +118 -166
  15. package/browser/es5/ai.osplugin.3.cjs.js.map +1 -1
  16. package/browser/es5/ai.osplugin.3.cjs.min.js +2 -2
  17. package/browser/es5/ai.osplugin.3.cjs.min.js.map +1 -1
  18. package/browser/es5/ai.osplugin.3.gbl.js +120 -168
  19. package/browser/es5/ai.osplugin.3.gbl.js.map +1 -1
  20. package/browser/es5/ai.osplugin.3.gbl.min.js +2 -2
  21. package/browser/es5/ai.osplugin.3.gbl.min.js.map +1 -1
  22. package/browser/es5/ai.osplugin.3.integrity.json +25 -25
  23. package/browser/es5/ai.osplugin.3.js +120 -168
  24. package/browser/es5/ai.osplugin.3.js.map +1 -1
  25. package/browser/es5/ai.osplugin.3.min.js +2 -2
  26. package/browser/es5/ai.osplugin.3.min.js.map +1 -1
  27. package/dist/es5/applicationinsights-osplugin-js.js +118 -166
  28. package/dist/es5/applicationinsights-osplugin-js.js.map +1 -1
  29. package/dist/es5/applicationinsights-osplugin-js.min.js +2 -2
  30. package/dist/es5/applicationinsights-osplugin-js.min.js.map +1 -1
  31. package/dist-es5/DataModels.js +1 -1
  32. package/dist-es5/OsPlugin.js +3 -4
  33. package/dist-es5/OsPlugin.js.map +1 -1
  34. package/dist-es5/__DynamicConstants.js +1 -1
  35. package/dist-es5/applicationinsights-osplugin-js.js +1 -1
  36. package/package.json +60 -61
  37. package/types/applicationinsights-osplugin-js.d.ts +2 -2
  38. package/types/applicationinsights-osplugin-js.namespaced.d.ts +2134 -47
  39. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.cjs.js.map +0 -1
  40. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.cjs.min.js +0 -6
  41. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.cjs.min.js.map +0 -1
  42. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.gbl.js.map +0 -1
  43. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.gbl.min.js +0 -6
  44. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.gbl.min.js.map +0 -1
  45. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.integrity.json +0 -66
  46. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.js.map +0 -1
  47. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.min.js +0 -6
  48. package/browser/es5/ai.osplugin.3.3.12-nightly3.2602-20.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights osplugin plugin, 3.3.12-nightly3.2602-20
2
+ * Microsoft Application Insights osplugin plugin, 3.4.0-beta
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -130,19 +130,125 @@ declare namespace ApplicationInsights {
130
130
  PENDING = 3
131
131
  }
132
132
 
133
+ /**
134
+ * Const enum for attribute change operation types
135
+ */
136
+ const enum eAttributeChangeOp {
137
+ /**
138
+ * Clear operation - clearing all attributes
139
+ */
140
+ Clear = 0,
141
+ /**
142
+ * Set operation - setting an attribute value (generic)
143
+ */
144
+ Set = 1,
145
+ /**
146
+ * Add operation - adding a new attribute that didn't exist before
147
+ */
148
+ Add = 2,
149
+ /**
150
+ * Delete operation - deleting an attribute
151
+ */
152
+ Delete = 3,
153
+ /**
154
+ * Dropped attributes - attributes that were dropped due to size limits
155
+ */
156
+ DroppedAttributes = 4
157
+ }
158
+
159
+ /**
160
+ * Identifies the source of an attribute value in iterator operations
161
+ * @since 3.4.0
162
+ */
163
+ const enum eAttributeFilter {
164
+ /**
165
+ * The attribute exists local to the current container instance
166
+ */
167
+ Local = 0,
168
+ /**
169
+ * The attribute does not exist locally and is inherited from a parent container or attributes object
170
+ */
171
+ Inherited = 1,
172
+ /**
173
+ * The attribute exists or has been deleted locally (only) to the current container instance
174
+ */
175
+ LocalOrDeleted = 2
176
+ }
177
+
133
178
  const enum eDistributedTracingModes {
134
179
  /**
135
- * (Default) Send Application Insights correlation headers
180
+ * Send only the legacy Application Insights correlation headers
181
+ *
182
+ * Headers Sent:
183
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
184
+ *
185
+ * Config Decimal Value: `0` (Zero)
136
186
  */
137
187
  AI = 0,
138
188
  /**
139
- * Send both W3C Trace Context headers and back-compatibility Application Insights headers
189
+ * (Default) Send both W3C Trace parent header and back-compatibility Application Insights headers
190
+ * - `Request-Id`
191
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
192
+ *
193
+ * Config Decimal Value: `1` (One)
140
194
  */
141
195
  AI_AND_W3C = 1,
142
196
  /**
143
- * Send W3C Trace Context headers
197
+ * Send Only the W3C Trace parent header
198
+ *
199
+ * Headers Sent:
200
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
201
+ *
202
+ * Config Decimal Value: `2` (Two)
203
+ */
204
+ W3C = 2,
205
+ /**
206
+ * @internal
207
+ * Bitwise mask used to separate the base distributed tracing mode from the additional optional
208
+ * tracing modes.
209
+ * @since 3.4.0
210
+ */
211
+ _BaseMask = 15,
212
+ /**
213
+ * @internal
214
+ * Enabling this bit will send the W3C Trace State header, it is not intended to be used directly
215
+ * or on its own. The code may assume that if this bit is set, then the W3C Trace Context headers
216
+ * will also be included.
217
+ *
218
+ * Config Decimal Value: `16` (Sixteen in decimal)
219
+ * @since 3.4.0
220
+ */
221
+ _W3CTraceState = 16,
222
+ /**
223
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers and back-compatibility
224
+ * Application Insights headers.
225
+ *
226
+ * Currently sent headers:
227
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
228
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
229
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
230
+ *
231
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
232
+ * to include additional headers.
233
+ *
234
+ * Config Decimal Value: `17` (Seventeen in decimal)
235
+ * @since 3.4.0
236
+ */
237
+ AI_AND_W3C_TRACE = 17,
238
+ /**
239
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers.
240
+ *
241
+ * Currently sent headers:
242
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
243
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
244
+ *
245
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
246
+ * to include additional headers.
247
+ *
248
+ * Config Decimal Value: `18` (Eighteen in decimal)
249
+ * @since 3.4.0
144
250
  */
145
- W3C = 2
251
+ W3C_TRACE = 18
146
252
  }
147
253
 
148
254
  const enum _eInternalMessageId {
@@ -237,7 +343,12 @@ declare namespace ApplicationInsights {
237
343
  SdkLdrUpdate = 111,
238
344
  InitPromiseException = 112,
239
345
  StatsBeatManagerException = 113,
240
- StatsBeatException = 114
346
+ StatsBeatException = 114,
347
+ AttributeError = 115,
348
+ SpanError = 116,
349
+ TraceError = 117,
350
+ NotImplementedError = 118,
351
+ VersionMismatch = 119
241
352
  }
242
353
 
243
354
  const enum eLoggingSeverity {
@@ -275,6 +386,81 @@ declare namespace ApplicationInsights {
275
386
 
276
387
  type EnumValue<E = any> = EnumCls<E>;
277
388
 
389
+ /**
390
+ * The defined set of Span Kinds as defined by the OpenTelemetry.
391
+ */
392
+ const enum eOTelSpanKind {
393
+ /** Default value. Indicates that the span is used internally. */
394
+ INTERNAL = 0,
395
+ /**
396
+ * Indicates that the span covers server-side handling of an RPC or other
397
+ * remote request.
398
+ */
399
+ SERVER = 1,
400
+ /**
401
+ * Indicates that the span covers the client-side wrapper around an RPC or
402
+ * other remote request.
403
+ */
404
+ CLIENT = 2,
405
+ /**
406
+ * Indicates that the span describes producer sending a message to a
407
+ * broker. Unlike client and server, there is no direct critical path latency
408
+ * relationship between producer and consumer spans.
409
+ */
410
+ PRODUCER = 3,
411
+ /**
412
+ * Indicates that the span describes consumer receiving a message from a
413
+ * broker. Unlike client and server, there is no direct critical path latency
414
+ * relationship between producer and consumer spans.
415
+ */
416
+ CONSUMER = 4
417
+ }
418
+
419
+ /**
420
+ * An enumeration of status codes, matching the OpenTelemetry specification.
421
+ *
422
+ * @since 3.4.0
423
+ */
424
+ const enum eOTelSpanStatusCode {
425
+ /**
426
+ * The default status.
427
+ */
428
+ UNSET = 0,
429
+ /**
430
+ * The operation has been validated by an Application developer or
431
+ * Operator to have completed successfully.
432
+ */
433
+ OK = 1,
434
+ /**
435
+ * The operation contains an error.
436
+ */
437
+ ERROR = 2
438
+ }
439
+
440
+ /**
441
+ * Controls how the SDK should look for trace headers (traceparent/tracestate) from the initial page load
442
+ * The values are bitwise OR'd together to allow for multiple values to be set at once.
443
+ * @since 3.4.0
444
+ */
445
+ const enum eTraceHeadersMode {
446
+ /**
447
+ * Don't look for any trace headers
448
+ */
449
+ None = 0,
450
+ /**
451
+ * Look for traceparent header/meta tag
452
+ */
453
+ TraceParent = 1,
454
+ /**
455
+ * Look for tracestate header/meta tag
456
+ */
457
+ TraceState = 2,
458
+ /**
459
+ * Look for both traceparent and tracestate headers/meta tags
460
+ */
461
+ All = 3
462
+ }
463
+
278
464
  const enum FeatureOptInMode {
279
465
  /**
280
466
  * not set, completely depends on cdn cfg
@@ -295,8 +481,7 @@ declare namespace ApplicationInsights {
295
481
  */
296
482
  type FinallyPromiseHandler = (() => void) | undefined | null;
297
483
 
298
- interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
299
- readonly config: CfgType;
484
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider, ITraceHost<CfgType> {
300
485
  /**
301
486
  * The current logger instance for this instance.
302
487
  */
@@ -417,14 +602,13 @@ declare namespace ApplicationInsights {
417
602
  */
418
603
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
419
604
  /**
420
- * Gets the current distributed trace context for this instance if available
421
- * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
422
- */
423
- getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
424
- /**
425
- * Sets the current distributed trace context for this instance if available
605
+ * Set the trace provider for creating spans.
606
+ * This allows different SKUs to provide their own span implementations.
607
+ *
608
+ * @param provider - The trace provider to use for span creation
609
+ * @since 3.4.0
426
610
  */
427
- setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
611
+ setTraceProvider(provider: ICachedValue<ITraceProvider>): void;
428
612
  /**
429
613
  * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
430
614
  * handler will be recalled.
@@ -452,6 +636,150 @@ declare namespace ApplicationInsights {
452
636
  _setPendingStatus?: () => void;
453
637
  }
454
638
 
639
+ /**
640
+ * Information about what changed in an attribute container
641
+ */
642
+ interface IAttributeChangeInfo<V extends OTelAttributeValue = OTelAttributeValue> {
643
+ /**
644
+ * The Id of the container that is initiated the change (not the immediate sender -- which is always the parent)
645
+ * As children only receive listener notifications from their parent in reaction to both changes
646
+ * they make and any changes they receive from their parent
647
+ */
648
+ frm: string;
649
+ /**
650
+ * Operation type that occurred
651
+ */
652
+ op: eAttributeChangeOp;
653
+ /**
654
+ * The key that was changed (only present for 'set' operations)
655
+ */
656
+ k?: string;
657
+ /**
658
+ * The old value (only present for 'set' operations when replacing existing value)
659
+ */
660
+ prev?: V;
661
+ /**
662
+ * The new value (only present for 'set' operations)
663
+ */
664
+ val?: V;
665
+ }
666
+
667
+ /**
668
+ * Interface for an attribute container
669
+ * @since 3.4.0
670
+ */
671
+ interface IAttributeContainer<V extends OTelAttributeValue = OTelAttributeValue> {
672
+ /**
673
+ * Unique identifier for the attribute container
674
+ */
675
+ readonly id: string;
676
+ /**
677
+ * The number of attributes that have been set
678
+ * @returns The number of attributes that have been set
679
+ */
680
+ readonly size: number;
681
+ /**
682
+ * The number of attributes that were dropped due to the attribute limit being reached
683
+ * @returns The number of attributes that were dropped due to the attribute limit being reached
684
+ */
685
+ readonly droppedAttributes: number;
686
+ /**
687
+ * Return a snapshot of the current attributes, including inherited ones.
688
+ * This value is read-only and reflects the state of the attributes at the time of access,
689
+ * and the returned instance will not change if any attributes are modified later, you will need
690
+ * to access the attributes property again to get the latest state.
691
+ *
692
+ * Note: As this causes a snapshot to be taken, it is an expensive operation as it enumerates all
693
+ * attributes, so you SHOULD use this property sparingly.
694
+ * @returns A read-only snapshot of the current attributes
695
+ */
696
+ readonly attributes: IOTelAttributes;
697
+ /**
698
+ * Clear all existing attributes from the container, this will also remove any inherited attributes
699
+ * from this instance only (it will not change the inherited attributes / container(s))
700
+ */
701
+ clear: () => void;
702
+ /**
703
+ * Get the value of an attribute by key
704
+ * @param key - The attribute key to retrieve
705
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
706
+ * @returns The attribute value if found, undefined otherwise
707
+ */
708
+ get: (key: string, source?: eAttributeFilter) => V | undefined;
709
+ /**
710
+ * Check if an attribute exists by key
711
+ * @param key - The attribute key to check
712
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
713
+ * @returns True if the attribute exists, false otherwise
714
+ */
715
+ has: (key: string, source?: eAttributeFilter) => boolean;
716
+ /**
717
+ * Set the value of an attribute by key on this instance.
718
+ * @param key - The attribute key to set
719
+ * @param value - The value to assign to the named attribute
720
+ * @returns true if the value was successfully set / replaced
721
+ */
722
+ set: (key: string, value: V) => boolean;
723
+ /**
724
+ * Delete an existing attribute, if the key doesn't exist this will return false. If the key does
725
+ * exist then it will be removed from this instance and any inherited value will be hidden (even if
726
+ * the inherited value changes)
727
+ * @param key - The attribute key to delete
728
+ * @returns True if the attribute was deleted, false if it didn't exist (which includes if it has already been deleted)
729
+ */
730
+ del: (key: string) => boolean;
731
+ /**
732
+ * The keys() method returns a new iterator object that contains the existing keys for each element
733
+ * in this attribute container. It will return all locally set keys first and then the inherited keys.
734
+ * When a key exists in both the local and inherited attributes, only the local key will be returned.
735
+ * If the key has been deleted locally, it will not be included in the iterator.
736
+ * @returns An iterator over the keys of the attribute container
737
+ */
738
+ keys: () => Iterator<string>;
739
+ /**
740
+ * The entries() method of returns a new iterator object that contains the [key, value, source?] tuples for
741
+ * each attribute, it returns all existing attributes of this instance including all inherited ones. If the
742
+ * same key exists in both the local and inherited attributes, only the first (non-deleted) tuple will be returned.
743
+ * If the key has been deleted, it will not be included in the iterator.
744
+ *
745
+ * The source value of the tuple identifies the origin of the attribute (Local or Inherited).
746
+ * @returns An iterator over the entries of the attribute container
747
+ */
748
+ entries: () => Iterator<[string, V, eAttributeFilter]>;
749
+ /**
750
+ * The forEach() method of executes a provided function once per each key/value pair in this attribute container,
751
+ * it will process all local attributes first, then the inherited attributes. If the same key exists in both the
752
+ * local and inherited attributes, only the first (non-deleted) key/value pair will be processed.
753
+ * If a key has been deleted, it will not be included in the set of processed key/value pairs.
754
+ * @param callback - The function to execute for each key/value pair
755
+ * @param thisArg - Optional value to use as `this` when executing `callback`
756
+ */
757
+ forEach: (callback: (key: string, value: V, source?: eAttributeFilter) => void, thisArg?: any) => void;
758
+ /**
759
+ * The values() method returns a new iterator instance that contains the values for each element in this
760
+ * attribute container. It will return all locally set values first and then the inherited values. If the
761
+ * same key is present in both the local or inherited attributes only the first (non-deleted) value will be
762
+ * returned. If a key has been deleted, it will not be included in the iterator.
763
+ * @returns An iterator over the values of the attribute container
764
+ */
765
+ values: () => Iterator<V>;
766
+ /**
767
+ * Register a callback listener for any attribute changes, this will include local and inherited changes.
768
+ * @param callback - Function to be called when attributes change, receives change information
769
+ * @returns IUnloadHook instance with rm() function to remove this listener, once called it will never be invoked again
770
+ */
771
+ listen: (callback: (changeInfo: IAttributeChangeInfo<V>) => void) => IUnloadHook;
772
+ /**
773
+ * Create a child attribute container that inherits from this one, optionally taking a snapshot
774
+ * so that any future changes to the parent container do not affect the child container.
775
+ * The child will use all of the configuration from the parent container.
776
+ * @param name - Optional name for the child container
777
+ * @param snapshot - If true, the child container will be a snapshot of the current state
778
+ * @returns A new attribute container instance
779
+ */
780
+ child: (name?: string, snapshot?: boolean) => IAttributeContainer;
781
+ }
782
+
455
783
  interface IBaseProcessingContext {
456
784
  /**
457
785
  * The current core instance for the request
@@ -466,9 +794,12 @@ declare namespace ApplicationInsights {
466
794
  */
467
795
  getCfg: () => IConfiguration;
468
796
  /**
469
- * Gets the named extension config
797
+ * Gets the named extension configuration
798
+ * @param identifier - The named extension identifier
799
+ * @param defaultValue - The default value(s) to return if no defined config exists
800
+ * @param rootOnly - If true, only the look for the configuration in the top level and not in the "extensionConfig"
470
801
  */
471
- getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
802
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>, rootOnly?: boolean) => T;
472
803
  /**
473
804
  * Gets the named config from either the named identifier extension or core config if neither exist then the
474
805
  * default value is returned
@@ -513,6 +844,30 @@ declare namespace ApplicationInsights {
513
844
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
514
845
  }
515
846
 
847
+ /**
848
+ * A generic interface for holding a cached value
849
+ * @since 0.10.5
850
+ * @group Helpers
851
+ * @group Cache
852
+ * @typeParam T - The type of the value to be cached
853
+ * @example
854
+ * ```ts
855
+ * let cachedValue: ICachedValue<string> = {
856
+ * v: "some value"
857
+ * };
858
+ * ```
859
+ */
860
+ interface ICachedValue<T> {
861
+ /**
862
+ * Returns the current cached value
863
+ */
864
+ v: T;
865
+ /**
866
+ * Returns the current cached value
867
+ */
868
+ toJSON(): T;
869
+ }
870
+
516
871
  /**
517
872
  * Provides data transmission capabilities
518
873
  */
@@ -957,7 +1312,7 @@ declare namespace ApplicationInsights {
957
1312
  /**
958
1313
  * Configuration provided to SDK core
959
1314
  */
960
- interface IConfiguration {
1315
+ interface IConfiguration extends IOTelConfig {
961
1316
  /**
962
1317
  * Instrumentation key of resource. Either this or connectionString must be specified.
963
1318
  */
@@ -1159,6 +1514,12 @@ declare namespace ApplicationInsights {
1159
1514
  * @example ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature","auth_token", "api_key", "private_data"]
1160
1515
  */
1161
1516
  redactQueryParams?: string[];
1517
+ /**
1518
+ * [Optional] Controls if the SDK should look for the `traceparent` and/or `tracestate` values from
1519
+ * the service timing headers or meta tags from the initial page load.
1520
+ * @defaultValue eTraceHeadersMode.All
1521
+ */
1522
+ traceHdrMode?: eTraceHeadersMode;
1162
1523
  }
1163
1524
 
1164
1525
  interface ICookieMgr {
@@ -1291,7 +1652,7 @@ declare namespace ApplicationInsights {
1291
1652
  /**
1292
1653
  * The internal logging queue
1293
1654
  */
1294
- queue: _InternalLogMessage[];
1655
+ queue: IInternalLogMessage[];
1295
1656
  /**
1296
1657
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1297
1658
  * @param severity - The severity of the log message
@@ -1324,7 +1685,7 @@ declare namespace ApplicationInsights {
1324
1685
  * @param severity - The severity of the log message
1325
1686
  * @param message - The message to log.
1326
1687
  */
1327
- logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1688
+ logInternalMessage?(severity: LoggingSeverity, message: IInternalLogMessage): void;
1328
1689
  /**
1329
1690
  * Optional Callback hook to allow the diagnostic logger to update it's configuration
1330
1691
  * @param updateState - The new configuration state to apply to the diagnostic logger
@@ -1339,16 +1700,25 @@ declare namespace ApplicationInsights {
1339
1700
  * / Promise to allow any listeners to wait for the operation to complete.
1340
1701
  */
1341
1702
  unload?(isAsync?: boolean): void | IPromise<void>;
1703
+ /**
1704
+ * A flag that indicates whether this logger is in debug (throw real exceptions) mode
1705
+ */
1706
+ readonly dbgMode?: boolean;
1342
1707
  }
1343
1708
 
1344
- interface IDistributedTraceContext {
1709
+ interface IDistributedTraceContext extends IDistributedTraceInit {
1345
1710
  /**
1346
1711
  * Returns the current name of the page
1347
1712
  */
1348
1713
  getName(): string;
1349
1714
  /**
1350
- * Sets the current name of the page
1715
+ * Sets the current name of the page, also updates the name for any parent context.
1716
+ * This is used to identify the page in the telemetry data.
1717
+ * @remarks This function updates the current and ALL parent contexts with the new name,
1718
+ * to just update the name of the current context, use the `pageName` property.
1351
1719
  * @param pageName - The name of the page
1720
+ * @deprecated Use the `pageName` property to avoid the side effect of changing the page name of all
1721
+ * parent contexts.
1352
1722
  */
1353
1723
  setName(pageName: string): void;
1354
1724
  /**
@@ -1361,6 +1731,12 @@ declare namespace ApplicationInsights {
1361
1731
  * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1362
1732
  * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1363
1733
  * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1734
+ *
1735
+ * @remarks Sets the traceId for the current context AND all parent contexts, if you want to set the traceId
1736
+ * for the current context only, use the `traceId` property.
1737
+ * @param newValue - The traceId to set
1738
+ * @deprecated Use the `traceId` property to avoid the side effect of changing the traceId of all
1739
+ * parent contexts.
1364
1740
  */
1365
1741
  setTraceId(newValue: string): void;
1366
1742
  /**
@@ -1372,6 +1748,12 @@ declare namespace ApplicationInsights {
1372
1748
  * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1373
1749
  * Also know as the parentId, used to link requests together
1374
1750
  * https://www.w3.org/TR/trace-context/#parent-id
1751
+ *
1752
+ * @remarks Sets the spanId for the current context AND all parent contexts, if you want to set the spanId for
1753
+ * the current context only, use the `spanId` property.
1754
+ * @param newValue - The spanId to set
1755
+ * @deprecated Use the `spanId` property to avoid the side effect of changing the spanId of all
1756
+ * parent contexts.
1375
1757
  */
1376
1758
  setSpanId(newValue: string): void;
1377
1759
  /**
@@ -1380,9 +1762,258 @@ declare namespace ApplicationInsights {
1380
1762
  getTraceFlags(): number | undefined;
1381
1763
  /**
1382
1764
  * https://www.w3.org/TR/trace-context/#trace-flags
1765
+ * @remarks Sets the trace flags for the current context and ALL parent contexts, if you want to set the trace
1766
+ * flags for the current context only, use the `traceFlags` property.
1383
1767
  * @param newValue - An integer representation of the W3C TraceContext trace-flags.
1768
+ * @deprecated Use the `traceFlags` property to avoid the side effect of changing the traceFlags of all
1769
+ * parent contexts.
1384
1770
  */
1385
1771
  setTraceFlags(newValue?: number): void;
1772
+ /**
1773
+ * Returns the current name of the page
1774
+ * @remarks This function updates the current context only, to update the name of the current and ALL parent contexts,
1775
+ * use the `setName` method.
1776
+ * @default undefined
1777
+ * @since 3.4.0
1778
+ */
1779
+ pageName: string;
1780
+ /**
1781
+ * The current ID of the trace that this span belongs to. It is worldwide unique
1782
+ * with practically sufficient probability by being made as 16 randomly
1783
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1784
+ * 128 bits.
1785
+ * @remarks It is NOT recommended that you dynamically change this value after creation and it is actively
1786
+ * being used as this may affect anyone accessing this context (as a parent for instance). You should logically
1787
+ * treat this as readonly after creation.
1788
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1789
+ * if you need to update the current and ALL parent contexts, use the `setTraceId` method which
1790
+ * provides the previous behavior.
1791
+ * @since 3.4.0
1792
+ */
1793
+ traceId: string;
1794
+ /**
1795
+ * The ID of the Span. It is globally unique with practically sufficient
1796
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1797
+ * lowercase hex characters corresponding to 64 bits.
1798
+ * If you update this value, it will only update for the current context, not the parent context.
1799
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1800
+ * if you need to update the current and ALL parent contexts, use the `setSpanId` method.
1801
+ * @since 3.4.0
1802
+ */
1803
+ spanId: string;
1804
+ /**
1805
+ * Returns true if the current context was initialized (propagated) from a remote parent.
1806
+ * @since 3.4.0
1807
+ * @default false
1808
+ * @returns True if the context was propagated from a remote parent
1809
+ */
1810
+ readonly isRemote: boolean;
1811
+ /**
1812
+ * Trace flags to propagate.
1813
+ *
1814
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
1815
+ * sampled or not. When set, the least significant bit documents that the
1816
+ * caller may have recorded trace data. A caller who does not record trace
1817
+ * data out-of-band leaves this flag unset.
1818
+ *
1819
+ * see {@link eW3CTraceFlags} for valid flag values.
1820
+ *
1821
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1822
+ * if you need to update the current and ALL parent contexts, use the `setTraceFlags` method.
1823
+ * @since 3.4.0
1824
+ */
1825
+ traceFlags?: number;
1826
+ /**
1827
+ * Returns the current trace state which will be used to propgate context across different services.
1828
+ * Updating (adding / removing keys) of the trace state will modify the current context.IOTelTraceState
1829
+ * @remarks Unlike the OpenTelemetry {@link IOTelTraceState}, this value is a mutable object, so you can
1830
+ * modify it directly you do not need to reassign the new value to this property.
1831
+ * @since 3.4.0
1832
+ */
1833
+ readonly traceState: IW3cTraceState;
1834
+ /**
1835
+ * Provides access to the parent context of the current context.
1836
+ * @remarks This is a read-only property, you cannot modify the parent context directly, you can only
1837
+ * modify the current context. If you need to modify the parent context, you need to do it through the
1838
+ * current context using the `setTraceId`, `setSpanId`, `setTraceFlags` and `setName` methods.
1839
+ * @default null
1840
+ * @since 3.4.0
1841
+ */
1842
+ readonly parentCtx?: IDistributedTraceContext | null;
1843
+ }
1844
+
1845
+ /**
1846
+ * An object that can be used to populate a new {@link IDistributedTraceContext} instance,
1847
+ * the included {@link IW3cTraceState} or {@link IOTelTraceState} is used as the parent of the
1848
+ * created instances traceState
1849
+ */
1850
+ interface IDistributedTraceInit {
1851
+ /**
1852
+ * The unique identifier for the trace that this span belongs to.
1853
+ *
1854
+ * The trace ID is a globally unique identifier that connects all spans within a single
1855
+ * distributed trace. It consists of 16 randomly generated bytes encoded as 32 lowercase
1856
+ * hexadecimal characters, providing 128 bits of entropy to ensure worldwide uniqueness
1857
+ * with practically sufficient probability.
1858
+ *
1859
+ * @remarks
1860
+ * - Must be exactly 32 lowercase hexadecimal characters
1861
+ * - Represents 128 bits (16 bytes) of random data
1862
+ * - Shared by all spans within the same trace
1863
+ * - Used for trace correlation across distributed systems
1864
+ * - Should never be all zeros (invalid trace ID)
1865
+ *
1866
+ * @example
1867
+ * ```typescript
1868
+ * // Example trace ID format
1869
+ * const traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
1870
+ *
1871
+ * // All spans in the same trace share this ID
1872
+ * console.log(parentSpan.spanContext().traceId === childSpan.spanContext().traceId); // true
1873
+ * ```
1874
+ */
1875
+ traceId: string;
1876
+ /**
1877
+ * The unique identifier for this specific span within the trace.
1878
+ *
1879
+ * The span ID uniquely identifies this span within the trace and is used to establish
1880
+ * parent-child relationships between spans. It consists of 8 randomly generated bytes
1881
+ * encoded as 16 lowercase hexadecimal characters, providing 64 bits of entropy to
1882
+ * ensure global uniqueness with practically sufficient probability.
1883
+ *
1884
+ * @remarks
1885
+ * - Must be exactly 16 lowercase hexadecimal characters
1886
+ * - Represents 64 bits (8 bytes) of random data
1887
+ * - Unique within the trace (different spans have different span IDs)
1888
+ * - Used as parent ID when creating child spans
1889
+ * - Should never be all zeros (invalid span ID)
1890
+ *
1891
+ * @example
1892
+ * ```typescript
1893
+ * // Example span ID format
1894
+ * const spanId = "00f067aa0ba902b7";
1895
+ *
1896
+ * // Each span has a unique ID within the trace
1897
+ * const parentId = parentSpan.spanContext().spanId; // "00f067aa0ba902b7"
1898
+ * const childId = childSpan.spanContext().spanId; // "b9c7c989f97918e1"
1899
+ *
1900
+ * // Child span uses parent's span ID as its parent ID
1901
+ * console.log(childSpan.parentSpanId === parentId); // true
1902
+ * ```
1903
+ */
1904
+ spanId: string;
1905
+ /**
1906
+ * Indicates whether this span context was propagated from a remote parent span.
1907
+ *
1908
+ * This flag distinguishes between spans created locally within the same process
1909
+ * and spans that represent operations in remote services. Remote spans are typically
1910
+ * created when trace context is received via HTTP headers, message queues, or other
1911
+ * inter-process communication mechanisms.
1912
+ *
1913
+ * @defaultValue false - spans are considered local unless explicitly marked as remote
1914
+ *
1915
+ * @remarks
1916
+ * - True only when span context was received from another process/service
1917
+ * - Helps distinguish local vs. distributed trace segments
1918
+ * - Used by tracing systems for visualization and analysis
1919
+ * - Local child spans of remote parents are NOT considered remote themselves
1920
+ *
1921
+ * @example
1922
+ * ```typescript
1923
+ * // HTTP service receiving trace context
1924
+ * const incomingSpanContext = extractSpanContextFromHeaders(request.headers);
1925
+ * console.log(incomingSpanContext.isRemote); // true
1926
+ *
1927
+ * // Child span created locally
1928
+ * const localChild = tracer.startSpan('local-operation', {
1929
+ * parent: incomingSpanContext
1930
+ * });
1931
+ * console.log(localChild.spanContext().isRemote); // false
1932
+ * ```
1933
+ */
1934
+ isRemote?: boolean;
1935
+ /**
1936
+ * Trace flags that control trace behavior and indicate sampling decisions.
1937
+ *
1938
+ * The trace flags are represented as a single byte (8-bit bitmap) that carries
1939
+ * trace-level information. The least significant bit (0x01) indicates whether
1940
+ * the trace is sampled. When this bit is set, it documents that the caller
1941
+ * may have recorded trace data. Additional bits are reserved for future use
1942
+ * and should be ignored when not understood.
1943
+ *
1944
+ * @remarks
1945
+ * - Represented as a number (0-255) corresponding to 8 bits
1946
+ * - Bit 0 (0x01): Sampled flag - indicates trace may contain recorded data
1947
+ * - Bits 1-7: Reserved for future use, should be preserved during propagation
1948
+ * - Used by sampling algorithms to make consistent decisions across services
1949
+ * - See {@link eW3CTraceFlags} for standard flag values
1950
+ *
1951
+ * @example
1952
+ * ```typescript
1953
+ * // Check if trace is sampled
1954
+ * const isSampled = (spanContext.traceFlags & 0x01) === 1;
1955
+ *
1956
+ * // Common flag values
1957
+ * const UNSAMPLED = 0x00; // 00000000 - not sampled
1958
+ * const SAMPLED = 0x01; // 00000001 - sampled
1959
+ *
1960
+ * // Preserving unknown flags during propagation
1961
+ * const preservedFlags = spanContext.traceFlags | 0x01; // Set sampled bit while preserving others
1962
+ *
1963
+ * // W3C traceparent header format includes these flags
1964
+ * const traceparent = `00-${traceId}-${spanId}-${traceFlags.toString(16).padStart(2, '0')}`;
1965
+ * ```
1966
+ */
1967
+ traceFlags?: number;
1968
+ /**
1969
+ * Vendor-specific trace state information for cross-system trace correlation.
1970
+ *
1971
+ * The trace state carries tracing-system-specific context in a standardized format
1972
+ * defined by the W3C Trace Context specification. It allows multiple tracing systems
1973
+ * to participate in the same trace by providing a mechanism for each system to add
1974
+ * its own metadata without interfering with others.
1975
+ *
1976
+ * The trace state is formatted as a comma-separated list of key-value pairs, where
1977
+ * each pair represents one tracing system's contribution. Keys should be unique
1978
+ * within the trace state and follow specific naming conventions.
1979
+ *
1980
+ * @remarks
1981
+ * - Maximum of 32 list members allowed
1982
+ * - Each member format: `key=value` separated by commas
1983
+ * - Keys should be namespaced to avoid conflicts (e.g., `vendor@system=value`)
1984
+ * - Total size should not exceed 512 characters for practical header limits
1985
+ * - Spaces around list members are ignored
1986
+ * - Preserves vendor-specific information during trace propagation
1987
+ *
1988
+ * @see {@link https://www.w3.org/TR/trace-context/#tracestate-field | W3C Trace Context Specification}
1989
+ *
1990
+ * @example
1991
+ * ```typescript
1992
+ * // Single tracing system
1993
+ * const singleVendor = {
1994
+ * get: (key: string) => key === 'rojo' ? '00f067aa0ba902b7' : undefined,
1995
+ * set: (key: string, value: string) => { ... },
1996
+ * unset: (key: string) => { ... },
1997
+ * serialize: () => 'rojo=00f067aa0ba902b7'
1998
+ * };
1999
+ *
2000
+ * // Multiple tracing systems
2001
+ * const multiVendor = {
2002
+ * serialize: () => 'rojo=00f067aa0ba902b7,congo=t61rcWkgMzE,vendor@system=custom-value'
2003
+ * };
2004
+ *
2005
+ * // Accessing trace state
2006
+ * const rojoValue = spanContext.traceState?.get('rojo');
2007
+ * const serialized = spanContext.traceState?.serialize();
2008
+ *
2009
+ * // HTTP header format (When the traceState is an IOTelTraceState)
2010
+ * headers['tracestate'] = spanContext.traceState?.serialize() || '';
2011
+ *
2012
+ * // HTTP header format (When the traceState is an IW3cTraceState)
2013
+ * headers['tracestate'] = spanContext.traceState?.hdrs()[0] || '';
2014
+ * ```
2015
+ */
2016
+ traceState?: IW3cTraceState | IOTelTraceState;
1386
2017
  }
1387
2018
 
1388
2019
  /**
@@ -1449,7 +2080,7 @@ declare namespace ApplicationInsights {
1449
2080
  * Identifies configuration override values when given feature is enabled
1450
2081
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1451
2082
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1452
- * Default: undefined
2083
+ * @default undefined
1453
2084
  */
1454
2085
  onCfg?: {
1455
2086
  [field: string]: any;
@@ -1458,7 +2089,7 @@ declare namespace ApplicationInsights {
1458
2089
  * Identifies configuration override values when given feature is disabled
1459
2090
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1460
2091
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1461
- * Default: undefined
2092
+ * @default undefined
1462
2093
  */
1463
2094
  offCfg?: {
1464
2095
  [field: string]: any;
@@ -1470,6 +2101,11 @@ declare namespace ApplicationInsights {
1470
2101
  blockCdnCfg?: boolean;
1471
2102
  }
1472
2103
 
2104
+ interface IInternalLogMessage {
2105
+ message: string;
2106
+ messageId: _InternalMessageId;
2107
+ }
2108
+
1473
2109
  /**
1474
2110
  * Internal Interface
1475
2111
  */
@@ -1669,13 +2305,6 @@ declare namespace ApplicationInsights {
1669
2305
  offlineBatchDrop?(cnt: number, reason?: number): void;
1670
2306
  }
1671
2307
 
1672
- class _InternalLogMessage {
1673
- static dataType: string;
1674
- message: string;
1675
- messageId: _InternalMessageId;
1676
- constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1677
- }
1678
-
1679
2308
  type _InternalMessageId = number | _eInternalMessageId;
1680
2309
 
1681
2310
  /**
@@ -1702,25 +2331,1079 @@ declare namespace ApplicationInsights {
1702
2331
  mergeOsNameVersion?: boolean;
1703
2332
  }
1704
2333
 
1705
- /** IPayloadData describes interface of payload sent via POST channel */
1706
- interface IPayloadData {
1707
- urlString: string;
1708
- data: Uint8Array | string;
1709
- headers?: {
1710
- [name: string]: string;
1711
- };
1712
- timeout?: number;
1713
- disableXhrSync?: boolean;
1714
- disableFetchKeepAlive?: boolean;
1715
- sendReason?: SendRequestReason;
1716
- }
1717
-
1718
2334
  /**
1719
- * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
2335
+ * The main OpenTelemetry API interface that provides access to all OpenTelemetry functionality.
2336
+ * This interface extends the IOTelTracerProvider and serves as the entry point for OpenTelemetry operations.
2337
+ *
2338
+ * @example
2339
+ * ```typescript
2340
+ * // Get a tracer from the API instance
2341
+ * const tracer = otelApi.getTracer("my-component");
2342
+ *
2343
+ * // Create a span
2344
+ * const span = tracer.startSpan("operation");
2345
+ *
2346
+ * // Access context manager
2347
+ * const currentContext = otelApi.context.active();
2348
+ *
2349
+ * // Access trace API
2350
+ * const activeSpan = otelApi.trace.getActiveSpan();
2351
+ * ```
2352
+ *
2353
+ * @since 3.4.0
1720
2354
  */
1721
- interface IPerfEvent {
2355
+ interface IOTelApi extends IOTelTracerProvider {
1722
2356
  /**
1723
- * The name of the performance event
2357
+ * The configuration object that contains all OpenTelemetry-specific settings.
2358
+ * This includes tracing configuration, error handlers, and other OpenTelemetry options.
2359
+ *
2360
+ * @remarks
2361
+ * Changes to this configuration after initialization may not take effect until
2362
+ * the next telemetry operation, depending on the implementation.
2363
+ */
2364
+ cfg: IOTelConfig;
2365
+ /**
2366
+ * The current {@link ITraceHost} instance for this IOTelApi instance, this is effectively
2367
+ * the OpenTelemetry ContextAPI instance without the static methods.
2368
+ * @returns The ContextManager instance
2369
+ */
2370
+ host: ITraceHost;
2371
+ /**
2372
+ * The current {@link ITraceApi} instance for this IOTelApi instance, this is
2373
+ * effectively the OpenTelemetry TraceAPI instance without the static methods.
2374
+ * @returns The current {@link ITraceApi} instance
2375
+ */
2376
+ trace: ITraceApi;
2377
+ }
2378
+
2379
+ /**
2380
+ * Configuration interface for OpenTelemetry attribute limits.
2381
+ * These limits help control the size and number of attributes to prevent
2382
+ * excessive memory usage and ensure consistent performance.
2383
+ *
2384
+ * @example
2385
+ * ```typescript
2386
+ * const limits: IOTelAttributeLimits = {
2387
+ * attributeCountLimit: 128, // Maximum 128 attributes
2388
+ * attributeValueLengthLimit: 4096 // Maximum 4KB per attribute value
2389
+ * };
2390
+ * ```
2391
+ *
2392
+ * @remarks
2393
+ * When limits are exceeded:
2394
+ * - Additional attributes beyond `attributeCountLimit` are dropped
2395
+ * - Attribute values longer than `attributeValueLengthLimit` are truncated
2396
+ * - The behavior may vary based on the specific implementation
2397
+ *
2398
+ * @since 3.4.0
2399
+ */
2400
+ interface IOTelAttributeLimits {
2401
+ /**
2402
+ * Maximum allowed length for attribute values in characters.
2403
+ *
2404
+ * @remarks
2405
+ * - Values longer than this limit will be truncated
2406
+ * - Applies to string attribute values only
2407
+ * - Numeric and boolean values are not affected by this limit
2408
+ * - Array values have this limit applied to each individual element
2409
+ *
2410
+ * @defaultValue 4096
2411
+ *
2412
+ * @example
2413
+ * ```typescript
2414
+ * // If attributeValueLengthLimit is 100:
2415
+ * span.setAttribute("description", "a".repeat(200)); // Will be truncated to 100 characters
2416
+ * span.setAttribute("count", 12345); // Not affected (number)
2417
+ * span.setAttribute("enabled", true); // Not affected (boolean)
2418
+ * ```
2419
+ */
2420
+ attributeValueLengthLimit?: number;
2421
+ /**
2422
+ * Maximum number of attributes allowed per telemetry item.
2423
+ *
2424
+ * @remarks
2425
+ * - Attributes added beyond this limit will be dropped
2426
+ * - The order of attributes matters; earlier attributes take precedence
2427
+ * - This limit applies to the total count of attributes, regardless of their type
2428
+ * - Inherited or default attributes count toward this limit
2429
+ *
2430
+ * @defaultValue 128
2431
+ *
2432
+ * @example
2433
+ * ```typescript
2434
+ * // If attributeCountLimit is 5:
2435
+ * span.setAttributes({
2436
+ * "attr1": "value1", // Kept
2437
+ * "attr2": "value2", // Kept
2438
+ * "attr3": "value3", // Kept
2439
+ * "attr4": "value4", // Kept
2440
+ * "attr5": "value5", // Kept
2441
+ * "attr6": "value6" // Dropped (exceeds limit)
2442
+ * });
2443
+ * ```
2444
+ */
2445
+ attributeCountLimit?: number;
2446
+ }
2447
+
2448
+ /**
2449
+ * Attributes is a map from string to attribute values.
2450
+ *
2451
+ * Note: only the own enumerable keys are counted as valid attribute keys.
2452
+ *
2453
+ * @since 3.4.0
2454
+ */
2455
+ interface IOTelAttributes {
2456
+ [key: string]: OTelAttributeValue | undefined;
2457
+ }
2458
+
2459
+ /**
2460
+ * OpenTelemetry configuration interface
2461
+ * Provides configuration specific to the OpenTelemetry extensions
2462
+ */
2463
+ interface IOTelConfig {
2464
+ /**
2465
+ * Configuration interface for OpenTelemetry tracing functionality.
2466
+ * This interface contains all the settings that control how traces are created,
2467
+ * processed, and managed within the OpenTelemetry system.
2468
+ *
2469
+ * @example
2470
+ * ```typescript
2471
+ * const traceCfg: ITraceCfg = {
2472
+ * serviceName: "my-service",
2473
+ * generalLimits: {
2474
+ * attributeCountLimit: 128,
2475
+ * attributeValueLengthLimit: 4096
2476
+ * },
2477
+ * spanLimits: {
2478
+ * attributeCountLimit: 128,
2479
+ * linkCountLimit: 128,
2480
+ * eventCountLimit: 128
2481
+ * }
2482
+ * };
2483
+ * ```
2484
+ *
2485
+ * @since 3.4.0
2486
+ */
2487
+ traceCfg?: ITraceCfg;
2488
+ /**
2489
+ * Error handlers for OpenTelemetry operations.
2490
+ * This interface allows you to specify custom error handling logic for various
2491
+ * OpenTelemetry components, enabling better control over how errors are managed
2492
+ * within the OpenTelemetry system.
2493
+ *
2494
+ * @see {@link IOTelErrorHandlers}
2495
+ *
2496
+ * @example
2497
+ * ```typescript
2498
+ * const errorHandlers: IOTelErrorHandlers = {
2499
+ * attribError: (message, key, value) => {
2500
+ * console.warn(`Attribute error for ${key}:`, message);
2501
+ * }
2502
+ * };
2503
+ * ```
2504
+ */
2505
+ errorHandlers?: IOTelErrorHandlers;
2506
+ }
2507
+
2508
+ /**
2509
+ * Configuration interface for OpenTelemetry error handling callbacks.
2510
+ * Provides hooks to customize how different types of errors and diagnostic
2511
+ * messages are handled within the OpenTelemetry system.
2512
+ *
2513
+ * @example
2514
+ * ```typescript
2515
+ * const errorHandlers: IOTelErrorHandlers = {
2516
+ * attribError: (message, key, value) => {
2517
+ * console.warn(`Attribute error for ${key}:`, message);
2518
+ * },
2519
+ * spanError: (message, spanName) => {
2520
+ * logger.error(`Span ${spanName} error:`, message);
2521
+ * },
2522
+ * warn: (message) => {
2523
+ * logger.warn(message);
2524
+ * },
2525
+ * error: (message) => {
2526
+ * logger.error(message);
2527
+ * }
2528
+ * };
2529
+ * ```
2530
+ *
2531
+ * @remarks
2532
+ * If handlers are not provided, default behavior will be used:
2533
+ * - `attribError`: Throws an `OTelInvalidAttributeError`
2534
+ * - `spanError`: Logs to console or calls warn handler
2535
+ * - `debug`: Logs to console.log
2536
+ * - `warn`: Logs to console.warn
2537
+ * - `error`: Logs to console.error
2538
+ * - `notImplemented`: Logs to console.error
2539
+ *
2540
+ * @since 3.4.0
2541
+ */
2542
+ interface IOTelErrorHandlers {
2543
+ /**
2544
+ * Handles attribute-related errors, such as invalid attribute values or keys.
2545
+ * Called when an attribute operation fails validation or processing.
2546
+ *
2547
+ * @param message - Descriptive error message explaining what went wrong
2548
+ * @param key - The attribute key that caused the error
2549
+ * @param value - The attribute value that caused the error (may be of any type)
2550
+ *
2551
+ * @remarks
2552
+ * Common scenarios that trigger this handler:
2553
+ * - Invalid attribute key format
2554
+ * - Attribute value exceeds length limits
2555
+ * - Unsupported attribute value type
2556
+ * - Attribute count exceeds limits
2557
+ *
2558
+ * @default Throws an `OTelInvalidAttributeError`
2559
+ *
2560
+ * @example
2561
+ * ```typescript
2562
+ * attribError: (message, key, value) => {
2563
+ * metrics.increment('otel.attribute.errors', { key, type: typeof value });
2564
+ * logger.warn(`Attribute ${key} rejected: ${message}`);
2565
+ * }
2566
+ * ```
2567
+ */
2568
+ attribError?: (message: string, key: string, value: any) => void;
2569
+ /**
2570
+ * Handles span-related errors that occur during span operations.
2571
+ * Called when a span operation fails or encounters an unexpected condition.
2572
+ *
2573
+ * @param message - Descriptive error message explaining the span error
2574
+ * @param spanName - The name of the span that encountered the error
2575
+ *
2576
+ * @remarks
2577
+ * Common scenarios that trigger this handler:
2578
+ * - Span operation called on an ended span
2579
+ * - Invalid span configuration
2580
+ * - Span processor errors
2581
+ * - Context propagation failures
2582
+ *
2583
+ * @default Logs to console or calls the warn handler
2584
+ *
2585
+ * @example
2586
+ * ```typescript
2587
+ * spanError: (message, spanName) => {
2588
+ * metrics.increment('otel.span.errors', { span_name: spanName });
2589
+ * logger.error(`Span operation failed for "${spanName}": ${message}`);
2590
+ * }
2591
+ * ```
2592
+ */
2593
+ spanError?: (message: string, spanName: string) => void;
2594
+ /**
2595
+ * Handles debug-level diagnostic messages.
2596
+ * Used for detailed troubleshooting information that is typically
2597
+ * only relevant during development or when diagnosing issues.
2598
+ *
2599
+ * @param message - Debug message to be handled
2600
+ *
2601
+ * @remarks
2602
+ * Debug messages are typically:
2603
+ * - Verbose operational details
2604
+ * - Internal state information
2605
+ * - Performance metrics
2606
+ * - Development-time diagnostics
2607
+ *
2608
+ * @default Logs to console.log
2609
+ *
2610
+ * @example
2611
+ * ```typescript
2612
+ * debug: (message) => {
2613
+ * if (process.env.NODE_ENV === 'development') {
2614
+ * console.debug('[OTel Debug]', message);
2615
+ * }
2616
+ * }
2617
+ * ```
2618
+ */
2619
+ debug?: (message: string) => void;
2620
+ /**
2621
+ * Handles warning-level messages for non-fatal issues.
2622
+ * Used for conditions that are unusual but don't prevent continued operation.
2623
+ *
2624
+ * @param message - Warning message to be handled
2625
+ *
2626
+ * @remarks
2627
+ * Warning scenarios include:
2628
+ * - Configuration issues that fall back to defaults
2629
+ * - Performance degradation
2630
+ * - Deprecated API usage
2631
+ * - Resource limit approaches
2632
+ *
2633
+ * @default Logs to console.warn
2634
+ *
2635
+ * @example
2636
+ * ```typescript
2637
+ * warn: (message) => {
2638
+ * logger.warn('[OTel Warning]', message);
2639
+ * metrics.increment('otel.warnings');
2640
+ * }
2641
+ * ```
2642
+ */
2643
+ warn?: (message: string) => void;
2644
+ /**
2645
+ * Handles general error conditions that may affect functionality.
2646
+ * Used for significant errors that should be investigated but may not be fatal.
2647
+ *
2648
+ * @param message - Error message to be handled
2649
+ *
2650
+ * @remarks
2651
+ * Error scenarios include:
2652
+ * - Failed network requests
2653
+ * - Configuration validation failures
2654
+ * - Resource allocation failures
2655
+ * - Unexpected runtime conditions
2656
+ *
2657
+ * @default Logs to console.error
2658
+ *
2659
+ * @example
2660
+ * ```typescript
2661
+ * error: (message) => {
2662
+ * logger.error('[OTel Error]', message);
2663
+ * errorReporting.captureException(new Error(message));
2664
+ * }
2665
+ * ```
2666
+ */
2667
+ error?: (message: string) => void;
2668
+ /**
2669
+ * Handles errors related to unimplemented functionality.
2670
+ * Called when a method or feature is not yet implemented or is intentionally
2671
+ * disabled in the current configuration.
2672
+ *
2673
+ * @param message - Message describing the unimplemented functionality
2674
+ *
2675
+ * @remarks
2676
+ * Common scenarios:
2677
+ * - Placeholder methods that haven't been implemented
2678
+ * - Features disabled in the current build
2679
+ * - Platform-specific functionality not available
2680
+ * - Optional features not included in the configuration
2681
+ *
2682
+ * @default Logs to console.error
2683
+ *
2684
+ * @example
2685
+ * ```typescript
2686
+ * notImplemented: (message) => {
2687
+ * logger.warn(`[OTel Not Implemented] ${message}`);
2688
+ * if (process.env.NODE_ENV === 'development') {
2689
+ * console.trace('Not implemented method called');
2690
+ * }
2691
+ * }
2692
+ * ```
2693
+ */
2694
+ notImplemented?: (message: string) => void;
2695
+ }
2696
+
2697
+ interface IOTelExceptionWithCode {
2698
+ code: string | number;
2699
+ name?: string;
2700
+ message?: string;
2701
+ stack?: string;
2702
+ }
2703
+
2704
+ interface IOTelExceptionWithMessage {
2705
+ code?: string | number;
2706
+ message: string;
2707
+ name?: string;
2708
+ stack?: string;
2709
+ }
2710
+
2711
+ interface IOTelExceptionWithName {
2712
+ code?: string | number;
2713
+ message?: string;
2714
+ name: string;
2715
+ stack?: string;
2716
+ }
2717
+
2718
+ /**
2719
+ * Enhanced high-resolution time interface that extends the base tuple with additional properties.
2720
+ * Provides a more structured way to work with high-resolution timestamps.
2721
+ *
2722
+ * @example
2723
+ * ```typescript
2724
+ * const hrTime: IOTelHrTime = {
2725
+ * 0: 1609459200, // seconds since Unix epoch
2726
+ * 1: 500000000, // nanoseconds (0-999,999,999)
2727
+ * };
2728
+ * ```
2729
+ *
2730
+ * @since 3.4.0
2731
+ */
2732
+ interface IOTelHrTime extends OTelHrTimeBase {
2733
+ /**
2734
+ * Seconds since Unix epoch (January 1, 1970 00:00:00 UTC).
2735
+ * Must be a non-negative integer.
2736
+ */
2737
+ 0: number;
2738
+ /**
2739
+ * Nanoseconds within the second specified by index 0.
2740
+ * Must be in the range [0, 999999999].
2741
+ */
2742
+ 1: number;
2743
+ }
2744
+
2745
+ /**
2746
+ * Provides an OpenTelemetry compatible interface for spans conforming to the OpenTelemetry API specification (v1.9.0).
2747
+ *
2748
+ * A span represents an operation within a trace and is the fundamental unit of work in distributed tracing.
2749
+ * Spans can be thought of as a grouping mechanism for a set of operations that are executed as part of
2750
+ * a single logical unit of work, providing timing information and contextual data about the operation.
2751
+ *
2752
+ * Spans form a tree structure within a trace, with a single root span that may have zero or more child spans,
2753
+ * which in turn may have their own children. This hierarchical structure allows for detailed analysis of
2754
+ * complex, multi-step operations across distributed systems.
2755
+ *
2756
+ * @since 3.4.0
2757
+ *
2758
+ * @remarks
2759
+ * - All spans created by this library implement the ISpan interface and extend the IReadableSpan interface
2760
+ * - Spans should be ended by calling `end()` when the operation completes
2761
+ * - Once ended, spans should generally not be used for further operations
2762
+ * - Spans automatically track timing information from creation to end
2763
+ *
2764
+ * @example
2765
+ * ```typescript
2766
+ * // Basic span usage
2767
+ * const span = tracer.startSpan('user-authentication');
2768
+ * span.setAttribute('user.id', '12345');
2769
+ * span.setAttribute('auth.method', 'oauth2');
2770
+ *
2771
+ * try {
2772
+ * const result = await authenticateUser();
2773
+ * span.setStatus({ code: SpanStatusCode.OK });
2774
+ * span.setAttribute('auth.success', true);
2775
+ * } catch (error) {
2776
+ * span.recordException(error);
2777
+ * span.setStatus({
2778
+ * code: SpanStatusCode.ERROR,
2779
+ * message: 'Authentication failed'
2780
+ * });
2781
+ * } finally {
2782
+ * span.end();
2783
+ * }
2784
+ * ```
2785
+ */
2786
+ interface IOTelSpan {
2787
+ /**
2788
+ * Returns the span context object associated with this span.
2789
+ *
2790
+ * The span context is an immutable, serializable identifier that uniquely identifies
2791
+ * this span within a trace. It contains the trace ID, span ID, and trace flags that
2792
+ * can be used to create new child spans or propagate trace context across process boundaries.
2793
+ *
2794
+ * The returned span context remains valid even after the span has ended, making it
2795
+ * useful for asynchronous operations and cross-service communication.
2796
+ *
2797
+ * @returns The immutable span context associated with this span
2798
+ *
2799
+ * @remarks
2800
+ * - The span context is the primary mechanism for trace propagation
2801
+ * - Context can be serialized and transmitted across network boundaries
2802
+ * - Contains trace ID (unique to the entire trace) and span ID (unique to this span)
2803
+ *
2804
+ * @example
2805
+ * ```typescript
2806
+ * const span = tracer.startSpan('parent-operation');
2807
+ * const spanContext = span.spanContext();
2808
+ *
2809
+ * // Use context to create child spans in other parts of the system
2810
+ * const childSpan = tracer.startSpan('child-operation', {
2811
+ * parent: spanContext
2812
+ * });
2813
+ *
2814
+ * // Context can be serialized for cross-service propagation
2815
+ * const traceId = spanContext.traceId;
2816
+ * const spanId = spanContext.spanId;
2817
+ * ```
2818
+ */
2819
+ spanContext(): IDistributedTraceContext;
2820
+ /**
2821
+ * Sets a single attribute on the span with the specified key and value.
2822
+ *
2823
+ * Attributes provide contextual information about the operation represented by the span.
2824
+ * They are key-value pairs that help with filtering, grouping, and understanding spans
2825
+ * in trace analysis tools. Attributes should represent meaningful properties of the operation.
2826
+ *
2827
+ * @param key - The attribute key, should be descriptive and follow naming conventions
2828
+ * @param value - The attribute value; null or undefined values are invalid and result in undefined behavior
2829
+ *
2830
+ * @returns This span instance for method chaining
2831
+ *
2832
+ * @remarks
2833
+ * - Attribute keys should follow semantic conventions when available
2834
+ * - Common attributes include service.name, http.method, db.statement, etc.
2835
+ * - Setting null or undefined values is invalid and may cause unexpected behavior
2836
+ * - Attributes set after span creation don't affect sampling decisions
2837
+ *
2838
+ * @example
2839
+ * ```typescript
2840
+ * const span = tracer.startSpan('http-request');
2841
+ *
2842
+ * // Set individual attributes with descriptive keys
2843
+ * span.setAttribute('http.method', 'POST')
2844
+ * .setAttribute('http.url', 'https://api.example.com/users')
2845
+ * .setAttribute('http.status_code', 201)
2846
+ * .setAttribute('user.id', '12345')
2847
+ * .setAttribute('request.size', 1024);
2848
+ * ```
2849
+ */
2850
+ setAttribute(key: string, value: OTelAttributeValue): this;
2851
+ /**
2852
+ * Sets multiple attributes on the span at once using an attributes object.
2853
+ *
2854
+ * This method allows efficient batch setting of multiple attributes in a single call.
2855
+ * All attributes in the provided object will be added to the span, supplementing any
2856
+ * existing attributes (duplicate keys will be overwritten).
2857
+ *
2858
+ * @param attributes - An object containing key-value pairs to set as span attributes
2859
+ *
2860
+ * @returns This span instance for method chaining
2861
+ *
2862
+ * @remarks
2863
+ * - Null or undefined attribute values are invalid and will result in undefined behavior
2864
+ * - More efficient than multiple `setAttribute` calls for bulk operations
2865
+ * - Existing attributes with the same keys will be overwritten
2866
+ *
2867
+ * @example
2868
+ * ```typescript
2869
+ * const span = tracer.startSpan('database-query');
2870
+ *
2871
+ * // Set multiple attributes efficiently
2872
+ * span.setAttributes({
2873
+ * 'db.system': 'postgresql',
2874
+ * 'db.name': 'user_database',
2875
+ * 'db.table': 'users',
2876
+ * 'db.operation': 'SELECT',
2877
+ * 'db.rows_affected': 5,
2878
+ * 'query.duration_ms': 15.7
2879
+ * });
2880
+ * ```
2881
+ */
2882
+ setAttributes(attributes: IOTelAttributes): this;
2883
+ /**
2884
+ * The {@link IAttributeContainer | attribute container} associated with this span, providing
2885
+ * advanced attribute management capabilities. Rather than using the {@link IReadableSpan#attributes}
2886
+ * directly which returns a readonly {@link IOTelAttributes} map that is a snapshot of the attributes at
2887
+ * the time of access, the attribute container offers methods to get, set, delete, and iterate over attributes
2888
+ * with fine-grained control.
2889
+ * It is recommended that you only access the {@link IReadableSpan#attributes} property sparingly due to the
2890
+ * performance cost of taking a snapshot of all attributes.
2891
+ */
2892
+ readonly attribContainer: IAttributeContainer;
2893
+ /**
2894
+ * Sets the status of the span to indicate the success or failure of the operation.
2895
+ *
2896
+ * The span status provides a standardized way to indicate whether the operation
2897
+ * completed successfully, encountered an error, or is in an unknown state.
2898
+ * This status is used by observability tools to provide meaningful insights
2899
+ * about system health and operation outcomes.
2900
+ *
2901
+ * @param status - The status object containing code and optional message
2902
+ *
2903
+ * @returns This span instance for method chaining
2904
+ *
2905
+ * @remarks
2906
+ * - Default status is UNSET until explicitly set
2907
+ * - Setting status overrides any previous status values
2908
+ * - ERROR status should be accompanied by a descriptive message when possible
2909
+ * - Status should reflect the final outcome of the operation
2910
+ *
2911
+ * @example
2912
+ * ```typescript
2913
+ * const span = tracer.startSpan('payment-processing');
2914
+ *
2915
+ * try {
2916
+ * const result = await processPayment(paymentData);
2917
+ *
2918
+ * // Indicate successful completion
2919
+ * span.setStatus({
2920
+ * code: SpanStatusCode.OK
2921
+ * });
2922
+ *
2923
+ * } catch (error) {
2924
+ * // Indicate operation failed
2925
+ * span.setStatus({
2926
+ * code: SpanStatusCode.ERROR,
2927
+ * message: 'Payment processing failed: ' + error.message
2928
+ * });
2929
+ *
2930
+ * span.recordException(error);
2931
+ * }
2932
+ * ```
2933
+ */
2934
+ setStatus(status: IOTelSpanStatus): this;
2935
+ /**
2936
+ * Updates the name of the span, overriding the name provided during creation.
2937
+ *
2938
+ * Span names should be descriptive and represent the operation being performed.
2939
+ * Updating the name can be useful when the operation's scope becomes clearer
2940
+ * during execution, or when implementing generic spans that need specific naming
2941
+ * based on runtime conditions.
2942
+ *
2943
+ * @param name - The new name for the span, should be descriptive of the operation
2944
+ *
2945
+ * @returns This span instance for method chaining
2946
+ *
2947
+ * @remarks
2948
+ * - Name updates may affect sampling behavior depending on implementation
2949
+ * - Choose names that are meaningful but not too specific to avoid cardinality issues
2950
+ * - Follow naming conventions consistent with your observability strategy
2951
+ * - Consider the impact on existing traces and dashboards when changing names
2952
+ *
2953
+ * @example
2954
+ * ```typescript
2955
+ * const span = tracer.startSpan('generic-operation');
2956
+ *
2957
+ * // Update name based on runtime determination
2958
+ * if (operationType === 'user-registration') {
2959
+ * span.updateName('user-registration');
2960
+ * span.setAttribute('operation.type', 'registration');
2961
+ * } else if (operationType === 'user-login') {
2962
+ * span.updateName('user-authentication');
2963
+ * span.setAttribute('operation.type', 'authentication');
2964
+ * }
2965
+ * ```
2966
+ */
2967
+ updateName(name: string): this;
2968
+ /**
2969
+ * Marks the end of the span's execution and records the end timestamp.
2970
+ *
2971
+ * This method finalizes the span and makes it available for export to tracing systems.
2972
+ * Once ended, the span should not be used for further operations. The span's duration
2973
+ * is calculated from its start time to the end time provided or current time.
2974
+ *
2975
+ * @param endTime - Optional end time; if not provided, current time is used
2976
+ *
2977
+ * @remarks
2978
+ * - This method does NOT return `this` to discourage chaining after span completion
2979
+ * - Ending a span has no effect on child spans, which may continue running
2980
+ * - Child spans can be ended independently after their parent has ended
2981
+ * - The span becomes eligible for export once ended
2982
+ * - Calling end() multiple times has no additional effect
2983
+ *
2984
+ * @example
2985
+ * ```typescript
2986
+ * const span = tracer.startSpan('file-processing');
2987
+ *
2988
+ * try {
2989
+ * // Perform the operation
2990
+ * const result = await processFile(filePath);
2991
+ *
2992
+ * // Record success
2993
+ * span.setStatus({ code: SpanStatusCode.OK });
2994
+ * span.setAttribute('file.size', result.size);
2995
+ *
2996
+ * } catch (error) {
2997
+ * span.recordException(error);
2998
+ * span.setStatus({
2999
+ * code: SpanStatusCode.ERROR,
3000
+ * message: error.message
3001
+ * });
3002
+ * } finally {
3003
+ * // Always end the span
3004
+ * span.end();
3005
+ * // Don't use span after this point
3006
+ * }
3007
+ *
3008
+ * // Custom end time example
3009
+ * const customEndTime = Date.now() * 1000000; // nanoseconds
3010
+ * span.end(customEndTime);
3011
+ * ```
3012
+ */
3013
+ end(endTime?: OTelTimeInput): void;
3014
+ /**
3015
+ * Returns whether this span is actively recording information.
3016
+ *
3017
+ * A recording span accepts and stores attributes, events, status, and other span data.
3018
+ * Non-recording spans (typically due to sampling decisions) may ignore operations
3019
+ * like setAttribute() to optimize performance. This method allows conditional
3020
+ * logic to avoid expensive operations on non-recording spans.
3021
+ *
3022
+ * @returns True if the span is actively recording information, false otherwise
3023
+ *
3024
+ * @remarks
3025
+ * - Recording status is typically determined at span creation time
3026
+ * - Non-recording spans still provide valid span context for propagation
3027
+ * - Use this check to avoid expensive attribute calculations for non-recording spans
3028
+ * - Recording status remains constant throughout the span's lifetime
3029
+ *
3030
+ * @example
3031
+ * ```typescript
3032
+ * const span = tracer.startSpan('data-processing');
3033
+ *
3034
+ * // Only perform expensive operations if span is recording
3035
+ * if (span.isRecording()) {
3036
+ * const metadata = await expensiveMetadataCalculation();
3037
+ * span.setAttributes({
3038
+ * 'process.metadata': JSON.stringify(metadata),
3039
+ * 'process.complexity': metadata.complexity,
3040
+ * 'process.estimated_duration': metadata.estimatedMs
3041
+ * });
3042
+ * }
3043
+ *
3044
+ * // Always safe to set basic attributes
3045
+ * span.setAttribute('process.started', true);
3046
+ * ```
3047
+ */
3048
+ isRecording(): boolean;
3049
+ /**
3050
+ * Records an exception as a span event with automatic error status handling.
3051
+ *
3052
+ * This method captures exception information and automatically creates a span event
3053
+ * with standardized exception attributes. It's the recommended way to handle errors
3054
+ * within spans, providing consistent error reporting across the application.
3055
+ *
3056
+ * @param exception - The exception to record; accepts string messages or Error objects
3057
+ * @param time - Optional timestamp for when the exception occurred; defaults to current time
3058
+ *
3059
+ * @remarks
3060
+ * - Automatically extracts exception type, message, and stack trace when available
3061
+ * - Creates a standardized span event with exception details
3062
+ * - Does NOT automatically set span status to ERROR - call setStatus() explicitly if needed
3063
+ * - Exception events are useful for debugging and error analysis
3064
+ *
3065
+ * @example
3066
+ * ```typescript
3067
+ * const span = tracer.startSpan('risky-operation');
3068
+ *
3069
+ * try {
3070
+ * await performRiskyOperation();
3071
+ * span.setStatus({ code: SpanStatusCode.OK });
3072
+ *
3073
+ * } catch (error) {
3074
+ * // Record the exception details
3075
+ * span.recordException(error);
3076
+ *
3077
+ * // Explicitly set error status
3078
+ * span.setStatus({
3079
+ * code: SpanStatusCode.ERROR,
3080
+ * message: 'Operation failed due to: ' + error.message
3081
+ * });
3082
+ *
3083
+ * // Re-throw if needed
3084
+ * throw error;
3085
+ * } finally {
3086
+ * span.end();
3087
+ * }
3088
+ *
3089
+ * // Recording string exceptions
3090
+ * span.recordException('Custom error message occurred');
3091
+ *
3092
+ * // Recording with custom timestamp
3093
+ * const errorTime = Date.now() * 1000000; // nanoseconds
3094
+ * span.recordException(error, errorTime);
3095
+ * ```
3096
+ */
3097
+ recordException(exception: OTelException, time?: OTelTimeInput): void;
3098
+ }
3099
+
3100
+ /**
3101
+ * A SpanContext represents the portion of a {@link IOTelSpan} which must be
3102
+ * serialized and propagated along side of a {@link IOTelBaggage}.
3103
+ */
3104
+ interface IOTelSpanContext extends IDistributedTraceInit {
3105
+ /**
3106
+ * Trace flags to propagate.
3107
+ *
3108
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
3109
+ * sampled or not. When set, the least significant bit documents that the
3110
+ * caller may have recorded trace data. A caller who does not record trace
3111
+ * data out-of-band leaves this flag unset.
3112
+ *
3113
+ * see {@link eW3CTraceFlags} for valid flag values.
3114
+ */
3115
+ traceFlags: number;
3116
+ }
3117
+
3118
+ /**
3119
+ * Provides an OpenTelemetry like Interface for the Open Telemetry Api (1.9.0) SpanOptions
3120
+ * type. Where SpanOptions are options that can be used to configure a span.
3121
+ */
3122
+ interface IOTelSpanOptions {
3123
+ /**
3124
+ * The SpanKind of a span of this span, this is used to specify
3125
+ * the relationship between the span and its parent span.
3126
+ * @see {@link eOTelSpanKind} for possible values.
3127
+ * @default eOTelSpanKind.INTERNAL
3128
+ */
3129
+ kind?: OTelSpanKind;
3130
+ /**
3131
+ * A span's attributes
3132
+ */
3133
+ attributes?: IOTelAttributes;
3134
+ /** A manually specified start time for the created `Span` object. */
3135
+ startTime?: OTelTimeInput;
3136
+ /** The new span should be a root span. (Ignore parent from context). */
3137
+ root?: boolean;
3138
+ /** Specify whether the span should be a recording span, default is true */
3139
+ recording?: boolean;
3140
+ }
3141
+
3142
+ interface IOTelSpanStatus {
3143
+ /**
3144
+ * The status code of this message.
3145
+ */
3146
+ code: eOTelSpanStatusCode;
3147
+ /**
3148
+ * A developer-facing error message.
3149
+ */
3150
+ message?: string;
3151
+ }
3152
+
3153
+ /**
3154
+ * OpenTelemetry tracer interface for creating and managing spans within a trace.
3155
+ *
3156
+ * A tracer is responsible for creating spans that represent units of work within a distributed system.
3157
+ * Each tracer is typically associated with a specific instrumentation library or component,
3158
+ * allowing for fine-grained control over how different parts of an application generate telemetry.
3159
+ *
3160
+ * @example
3161
+ * ```typescript
3162
+ * // Get a tracer instance
3163
+ * const tracer = otelApi.getTracer('my-service');
3164
+ *
3165
+ * // Create a simple span
3166
+ * const span = tracer.startSpan('database-query');
3167
+ * span.setAttribute('db.operation', 'SELECT');
3168
+ * span.end();
3169
+ *
3170
+ * // Create an active span with automatic context management
3171
+ * tracer.startActiveSpan('process-request', (span) => {
3172
+ * span.setAttribute('request.id', '12345');
3173
+ *
3174
+ * // Any spans created within this block will be children of this span
3175
+ * processRequest();
3176
+ *
3177
+ * span.end();
3178
+ * });
3179
+ * ```
3180
+ *
3181
+ * @see {@link IReadableSpan} - Interface for individual spans
3182
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
3183
+ *
3184
+ * @since 3.4.0
3185
+ */
3186
+ interface IOTelTracer {
3187
+ /**
3188
+ * Creates and starts a new span without setting it as the active span in the current context.
3189
+ *
3190
+ * This method creates a span but does NOT modify the current execution context.
3191
+ * The caller is responsible for managing the span's lifecycle, including calling `end()`
3192
+ * when the operation completes.
3193
+ *
3194
+ * @param name - The name of the span, should be descriptive of the operation being traced
3195
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
3196
+ *
3197
+ * @returns The newly created span, or null if span creation failed
3198
+ *
3199
+ * @remarks
3200
+ * - The returned span must be manually ended by calling `span.end()`
3201
+ * - This span will not automatically become the parent for spans created in nested operations
3202
+ * - Use `startActiveSpan` if you want automatic context management
3203
+ *
3204
+ * @example
3205
+ * ```typescript
3206
+ * const span = tracer.startSpan('database-operation');
3207
+ * if (span) {
3208
+ * try {
3209
+ * span.setAttribute('db.table', 'users');
3210
+ * span.setAttribute('db.operation', 'SELECT');
3211
+ *
3212
+ * // Perform database operation
3213
+ * const result = await db.query('SELECT * FROM users');
3214
+ *
3215
+ * span.setAttributes({
3216
+ * 'db.rows_affected': result.length,
3217
+ * 'operation.success': true
3218
+ * });
3219
+ * } catch (error) {
3220
+ * span.setStatus({
3221
+ * code: SpanStatusCode.ERROR,
3222
+ * message: error.message
3223
+ * });
3224
+ * span.recordException(error);
3225
+ * } finally {
3226
+ * span.end(); // Always end the span
3227
+ * }
3228
+ * }
3229
+ * ```
3230
+ */
3231
+ startSpan(name: string, options?: IOTelSpanOptions): IReadableSpan | null;
3232
+ /**
3233
+ * Creates and starts a new span, sets it as the active span in the current context,
3234
+ * and executes a provided function within this context.
3235
+ *
3236
+ * This method creates a span, makes it active during the execution of the provided
3237
+ * function, and automatically ends the span when the function completes (or throws).
3238
+ * This provides automatic span lifecycle management and context propagation.
3239
+ *
3240
+ * @param name - The name of the span, should be descriptive of the operation being traced
3241
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
3242
+ * @param fn - The function to execute within the span's active context
3243
+ *
3244
+ * @returns The result of executing the provided function
3245
+ *
3246
+ * @remarks
3247
+ * - The span is automatically ended when the function completes or throws an exception
3248
+ * - The span becomes the active parent for any spans created within the function
3249
+ * - If the function throws an error, the span status is automatically set to ERROR
3250
+ * - This is the recommended method for most tracing scenarios due to automatic lifecycle management
3251
+ * - Multiple overloads available for different parameter combinations
3252
+ *
3253
+ * @example
3254
+ * ```typescript
3255
+ * // Synchronous operation with just name and function
3256
+ * const result = tracer.startActiveSpan('user-service', (span) => {
3257
+ * span.setAttribute('operation', 'get-user-details');
3258
+ * return { user: getUserData(), timestamp: new Date().toISOString() };
3259
+ * });
3260
+ *
3261
+ * // With options
3262
+ * const result2 = tracer.startActiveSpan('database-query',
3263
+ * { attributes: { 'db.table': 'users' } },
3264
+ * (span) => {
3265
+ * span.setAttribute('db.operation', 'SELECT');
3266
+ * return database.getUser('123');
3267
+ * }
3268
+ * );
3269
+ *
3270
+ * // With full context control
3271
+ * const result3 = tracer.startActiveSpan('external-api',
3272
+ * { attributes: { 'service.name': 'payment-api' } },
3273
+ * currentContext,
3274
+ * async (span) => {
3275
+ * try {
3276
+ * const response = await fetch('/api/payment');
3277
+ * span.setAttributes({
3278
+ * 'http.status_code': response.status,
3279
+ * 'operation.success': response.ok
3280
+ * });
3281
+ * return response.json();
3282
+ * } catch (error) {
3283
+ * span.setAttribute('error.type', error.constructor.name);
3284
+ * throw error; // Error automatically recorded
3285
+ * }
3286
+ * }
3287
+ * );
3288
+ * ```
3289
+ */
3290
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, fn: F): ReturnType<F>;
3291
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, options: IOTelSpanOptions, fn: F): ReturnType<F>;
3292
+ }
3293
+
3294
+ interface IOTelTracerOptions {
3295
+ /**
3296
+ * The schemaUrl of the tracer or instrumentation library
3297
+ */
3298
+ schemaUrl?: string;
3299
+ }
3300
+
3301
+ /**
3302
+ * OpenTelemetry Trace API for getting tracers.
3303
+ * This provides the standard OpenTelemetry trace API entry point.
3304
+ */
3305
+ interface IOTelTracerProvider {
3306
+ /**
3307
+ * Returns a Tracer, creating one if one with the given name and version is
3308
+ * not already created. This may return
3309
+ * - The same Tracer instance if one has already been created with the same name and version
3310
+ * - A new Tracer instance if one has not already been created with the same name and version
3311
+ * - A non-operational Tracer if the provider is not operational
3312
+ *
3313
+ * @param name - The name of the tracer or instrumentation library.
3314
+ * @param version - The version of the tracer or instrumentation library.
3315
+ * @param options - The options of the tracer or instrumentation library.
3316
+ * @returns Tracer A Tracer with the given name and version
3317
+ */
3318
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
3319
+ /**
3320
+ * Forces the tracer provider to flush any buffered data.
3321
+ * @returns A promise that resolves when the flush is complete.
3322
+ */
3323
+ forceFlush?: () => IPromise<void> | void;
3324
+ /**
3325
+ * Shuts down the tracer provider and releases any resources.
3326
+ * @returns A promise that resolves when the shutdown is complete.
3327
+ */
3328
+ shutdown?: () => IPromise<void> | void;
3329
+ }
3330
+
3331
+ /**
3332
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Api (1.9.0) TraceState type.
3333
+ *
3334
+ * The TraceState is a list of key/value pairs that are used to propagate
3335
+ * vendor-specific trace information across different distributed tracing systems.
3336
+ * The TraceState is used to store the state of a trace across different
3337
+ * distributed tracing systems, and it is used to ensure that the trace information
3338
+ * is consistent across different systems.
3339
+ *
3340
+ * Instances of TraceState are immutable, and the methods on this interface
3341
+ * return a new instance of TraceState with the updated values.
3342
+ */
3343
+ interface IOTelTraceState {
3344
+ /**
3345
+ * Create a new TraceState which inherits from this TraceState and has the
3346
+ * given key set.
3347
+ * The new entry will always be added in the front of the list of states.
3348
+ *
3349
+ * @param key - key of the TraceState entry.
3350
+ * @param value - value of the TraceState entry.
3351
+ */
3352
+ set(key: string, value: string): IOTelTraceState;
3353
+ /**
3354
+ * Return a new TraceState which inherits from this TraceState but does not
3355
+ * contain the given key.
3356
+ *
3357
+ * @param key - the key for the TraceState entry to be removed.
3358
+ */
3359
+ unset(key: string): IOTelTraceState;
3360
+ /**
3361
+ * Returns the value to which the specified key is mapped, or `undefined` if
3362
+ * this map contains no mapping for the key.
3363
+ *
3364
+ * @param key - with which the specified value is to be associated.
3365
+ * @returns the value to which the specified key is mapped, or `undefined` if
3366
+ * this map contains no mapping for the key.
3367
+ */
3368
+ get(key: string): string | undefined;
3369
+ /**
3370
+ * Serializes the TraceState to a `list` as defined below. The `list` is a series of `list-members`
3371
+ * separated by commas `,`, and a list-member is a key/value pair separated by an equals sign `=`.
3372
+ * Spaces and horizontal tabs surrounding `list-members` are ignored. There can be a maximum of 32
3373
+ * `list-members` in a `list`.
3374
+ *
3375
+ * If the resulting serialization is limited to no longer than 512 bytes, if the combination of
3376
+ * keys and values exceeds this limit, the serialization will be truncated to the last key/value pair
3377
+ * that fits within the limit. The serialization will be returned as a string.
3378
+ *
3379
+ * This is different from the {@link IW3cTraceState} serialization which returns an array of strings where each
3380
+ * string is limited to 512 bytes and the array is limited to 32 strings. Thus the OpenTelemetry serialization
3381
+ * will only return the first single string that fits within the limie.
3382
+ *
3383
+ * @returns the serialized string.
3384
+ */
3385
+ serialize(): string;
3386
+ }
3387
+
3388
+ /** IPayloadData describes interface of payload sent via POST channel */
3389
+ interface IPayloadData {
3390
+ urlString: string;
3391
+ data: Uint8Array | string;
3392
+ headers?: {
3393
+ [name: string]: string;
3394
+ };
3395
+ timeout?: number;
3396
+ disableXhrSync?: boolean;
3397
+ disableFetchKeepAlive?: boolean;
3398
+ sendReason?: SendRequestReason;
3399
+ }
3400
+
3401
+ /**
3402
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
3403
+ */
3404
+ interface IPerfEvent {
3405
+ /**
3406
+ * The name of the performance event
1724
3407
  */
1725
3408
  name: string;
1726
3409
  /**
@@ -2102,6 +3785,44 @@ declare namespace ApplicationInsights {
2102
3785
  finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
2103
3786
  }
2104
3787
 
3788
+ /**
3789
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Sdk-Trace-Base (1.8.0 and 2.0.0) ReadableSpan type.
3790
+ *
3791
+ * The IReadableSpan interface is used to represent a span that can be read and exported, while the OpenTelemetry
3792
+ * specification defines a ReadableSpan as a Span that has been ended and is ready to be exported. By default all
3793
+ * spans created by this library implement the IReadableSpan interface which also extends the {@link IOTelSpan} interface.
3794
+ *
3795
+ * This interface is defined to provide compatibility with exporters defined by the OpenTelemetry Trace SDK.
3796
+ * @since 3.4.0
3797
+ */
3798
+ interface IReadableSpan extends IOTelSpan {
3799
+ /**
3800
+ * The span's unique identifier.
3801
+ */
3802
+ readonly name: string;
3803
+ /**
3804
+ * Identifies the type (or kind) that this span is representing.
3805
+ */
3806
+ readonly kind: OTelSpanKind;
3807
+ readonly spanContext: () => IDistributedTraceContext;
3808
+ readonly parentSpanId?: string;
3809
+ readonly parentSpanContext?: IDistributedTraceContext;
3810
+ readonly startTime: IOTelHrTime;
3811
+ readonly endTime: IOTelHrTime;
3812
+ readonly status: IOTelSpanStatus;
3813
+ /**
3814
+ * Provides a snapshot of the span's attributes at the time this span was ended.
3815
+ * @returns A read-only snapshot of the span's attributes
3816
+ * @remarks
3817
+ * It is recommended that you only access this property sparingly due to the
3818
+ * performance cost of taking a snapshot of all attributes.
3819
+ */
3820
+ readonly attributes: IOTelAttributes;
3821
+ readonly duration: IOTelHrTime;
3822
+ readonly ended: boolean;
3823
+ readonly droppedAttributesCount: number;
3824
+ }
3825
+
2105
3826
  interface IRequestContext {
2106
3827
  status?: number;
2107
3828
  xhr?: XMLHttpRequest;
@@ -2109,6 +3830,35 @@ declare namespace ApplicationInsights {
2109
3830
  response?: Response | string;
2110
3831
  }
2111
3832
 
3833
+ /**
3834
+ * Represents the execution scope for a span, combining the trace instance and the active span.
3835
+ * This interface is used as the context for executing functions within a span's scope.
3836
+ *
3837
+ * @since 3.4.0
3838
+ */
3839
+ interface ISpanScope<T extends ITraceHost = ITraceHost> {
3840
+ /**
3841
+ * The trace host (core or AISKU instance).
3842
+ * @since 3.4.0
3843
+ */
3844
+ readonly host: T;
3845
+ /**
3846
+ * The active span for this execution scope.
3847
+ * @since 3.4.0
3848
+ */
3849
+ readonly span: IReadableSpan;
3850
+ /**
3851
+ * The previously active span before this scope was created, if any.
3852
+ * @since 3.4.0
3853
+ */
3854
+ readonly prvSpan?: IReadableSpan;
3855
+ /**
3856
+ * Restores the previous active span in the trace instance.
3857
+ * @since 3.4.0
3858
+ */
3859
+ restore(): void;
3860
+ }
3861
+
2112
3862
  /**
2113
3863
  * Identifies a simple interface to allow you to override the storage mechanism used
2114
3864
  * to track unsent and unacknowledged events. When provided it must provide both
@@ -2447,6 +4197,205 @@ declare namespace ApplicationInsights {
2447
4197
  enabled: boolean;
2448
4198
  }
2449
4199
 
4200
+ /**
4201
+ * ITraceApi provides an interface definition which is simular to the OpenTelemetry TraceAPI
4202
+ */
4203
+ interface ITraceApi {
4204
+ /**
4205
+ * Returns a Tracer, creating one if one with the given name and version
4206
+ * if one has not already created.
4207
+ *
4208
+ * @param name - The name of the tracer or instrumentation library.
4209
+ * @param version - The version of the tracer or instrumentation library.
4210
+ * @param options - The options of the tracer or instrumentation library.
4211
+ * @returns Tracer A Tracer with the given name and version
4212
+ */
4213
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
4214
+ /**
4215
+ * Wrap the given {@link IDistributedTraceContext} in a new non-recording {@link IReadableSpan}
4216
+ *
4217
+ * @param spanContext - The {@link IDistributedTraceContext} to be wrapped
4218
+ * @returns a new non-recording {@link IReadableSpan} with the provided context
4219
+ */
4220
+ wrapSpanContext(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): IReadableSpan;
4221
+ /**
4222
+ * Returns true if this {@link IDistributedTraceContext} is valid.
4223
+ * @return true if this {@link IDistributedTraceContext} is valid.
4224
+ */
4225
+ isSpanContextValid(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): boolean;
4226
+ /**
4227
+ * Gets the span from the current context, if one exists.
4228
+ */
4229
+ getActiveSpan(): IReadableSpan | undefined | null;
4230
+ /**
4231
+ * Set or clear the current active span.
4232
+ * @param span - The span to set as the active span, or null/undefined to clear the active span.
4233
+ * @return An ISpanScope instance returned by the host, or void if there is no defined host.
4234
+ */
4235
+ setActiveSpan(span: IReadableSpan | undefined | null): ISpanScope | undefined | null;
4236
+ }
4237
+
4238
+ /**
4239
+ * Configuration interface for OpenTelemetry compatible tracing functionality.
4240
+ * This interface contains all the settings that control how traces are created,
4241
+ * processed, and managed within the OpenTelemetry system.
4242
+ *
4243
+ * @example
4244
+ * ```typescript
4245
+ * const traceCfg: ITraceCfg = {
4246
+ * serviceName: "my-service",
4247
+ * generalLimits: {
4248
+ * attributeCountLimit: 128,
4249
+ * attributeValueLengthLimit: 4096
4250
+ * },
4251
+ * spanLimits: {
4252
+ * attributeCountLimit: 128,
4253
+ * linkCountLimit: 128,
4254
+ * eventCountLimit: 128
4255
+ * }
4256
+ * };
4257
+ * ```
4258
+ *
4259
+ * @since 3.4.0
4260
+ */
4261
+ interface ITraceCfg {
4262
+ /**
4263
+ * Global attribute limits that apply to all telemetry items.
4264
+ * These limits help prevent excessive memory usage and ensure consistent
4265
+ * behavior across different telemetry types.
4266
+ *
4267
+ * @remarks
4268
+ * These limits are inherited by more specific configurations unless overridden.
4269
+ * For example, spans will use these limits unless `spanLimits` specifies different values.
4270
+ */
4271
+ generalLimits?: IOTelAttributeLimits;
4272
+ /**
4273
+ * The name of the service generating telemetry data.
4274
+ * This name will be included in all telemetry items as a resource attribute.
4275
+ *
4276
+ * @remarks
4277
+ * The service name is crucial for identifying and filtering telemetry data
4278
+ * in observability systems. It should be consistent across all instances
4279
+ * of the same service.
4280
+ *
4281
+ * @example
4282
+ * ```typescript
4283
+ * serviceName: "user-authentication-service"
4284
+ * ```
4285
+ */
4286
+ serviceName?: string;
4287
+ /**
4288
+ * A flag that indicates whether the tracing (creating of a "trace" event) should be suppressed
4289
+ * when a {@link IOTelSpan} ends and the span {@link IOTelSpan#isRecording | isRecording} is true.
4290
+ * This value is also inherited by spans when they are created.
4291
+ */
4292
+ suppressTracing?: boolean;
4293
+ }
4294
+
4295
+ /**
4296
+ * Interface for OpenTelemetry trace operations.
4297
+ * This interface provides span creation, context management, and trace provider operations
4298
+ * that are common across different SDK implementations (Core, AISKU, etc.).
4299
+ *
4300
+ * @since 3.4.0
4301
+ */
4302
+ interface ITraceHost<CfgType extends IConfiguration = IConfiguration> {
4303
+ readonly config: CfgType;
4304
+ /**
4305
+ * Gets the current distributed trace active context for this instance
4306
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true. By default this
4307
+ * will use any located parent as defined by the {@link IConfiguration.traceHdrMode} configuration for each new instance created.
4308
+ */
4309
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
4310
+ /**
4311
+ * Sets the current distributed trace context for this instance if available
4312
+ */
4313
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
4314
+ /**
4315
+ * Start a new span with the given name and optional parent context.
4316
+ *
4317
+ * Note: This method only creates and returns the span. It does not automatically
4318
+ * set the span as the active trace context. Context management should be handled
4319
+ * separately using setTraceCtx() if needed.
4320
+ *
4321
+ * @param name - The name of the span
4322
+ * @param options - Options for creating the span (kind, attributes, startTime)
4323
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
4324
+ * @returns A new span instance, or null if no trace provider is available
4325
+ * @since 3.4.0
4326
+ *
4327
+ * @see {@link IReadableSpan} - Interface for individual spans
4328
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
4329
+ */
4330
+ startSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan | null;
4331
+ /**
4332
+ * Return the current active span, if no trace provider is available null will be returned
4333
+ * but when a trace provider is available a span instance will always be returned, even if
4334
+ * there is no active span (in which case a non-recording span will be returned).
4335
+ * @param createNew - Optional flag to create a non-recording span if no active span exists, defaults to true.
4336
+ * When false, returns the existing active span or null without creating a non-recording span, which can improve
4337
+ * performance when only checking if an active span exists.
4338
+ * @returns The current active span or null if no trace provider is available or if createNew is false and no active span exists
4339
+ * @since 3.4.0
4340
+ */
4341
+ getActiveSpan(createNew?: boolean): IReadableSpan | null;
4342
+ /**
4343
+ * Set the current Active Span, if no trace provider is available the span will be not be set as the active span.
4344
+ * @param span - The span to set as the active span
4345
+ * @returns An ISpanScope instance that provides the current scope, the span will always be the span passed in
4346
+ * even when no trace provider is available
4347
+ * @since 3.4.0
4348
+ */
4349
+ setActiveSpan(span: IReadableSpan): ISpanScope;
4350
+ /**
4351
+ * Get the current trace provider.
4352
+ *
4353
+ * @returns The current trace provider, or null if none is set
4354
+ * @since 3.4.0
4355
+ */
4356
+ getTraceProvider(): ITraceProvider | null;
4357
+ }
4358
+
4359
+ /**
4360
+ * A trace provider interface that enables different SKUs to provide their own
4361
+ * span implementations while being managed by the core SDK.
4362
+ *
4363
+ * This follows the OpenTelemetry TraceProvider pattern, allowing the core to
4364
+ * delegate span creation to the appropriate implementation based on the SDK variant.
4365
+ *
4366
+ * @since 3.4.0
4367
+ */
4368
+ interface ITraceProvider {
4369
+ /**
4370
+ * The OpenTelemetry API instance associated with this trace provider.
4371
+ * This provides access to the tracer provider and other OpenTelemetry functionality.
4372
+ * @since 3.4.0
4373
+ */
4374
+ readonly api: IOTelApi;
4375
+ /**
4376
+ * Creates a new span with the given name and options.
4377
+ *
4378
+ * @param name - The name of the span
4379
+ * @param options - Options for creating the span (kind, attributes, startTime)
4380
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
4381
+ * @returns A new span instance specific to this provider's implementation
4382
+ * @since 3.4.0
4383
+ */
4384
+ createSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan;
4385
+ /**
4386
+ * Gets the provider identifier for debugging and logging purposes.
4387
+ * @returns A string identifying this trace provider implementation
4388
+ * @since 3.4.0
4389
+ */
4390
+ getProviderId(): string;
4391
+ /**
4392
+ * Determines if this provider is available and ready to create spans.
4393
+ * @returns true if the provider can create spans, false otherwise
4394
+ * @since 3.4.0
4395
+ */
4396
+ isAvailable(): boolean;
4397
+ }
4398
+
2450
4399
  /**
2451
4400
  * An interface which provides automatic removal during unloading of the component
2452
4401
  */
@@ -2466,6 +4415,76 @@ declare namespace ApplicationInsights {
2466
4415
  run: (logger?: IDiagnosticLogger) => void;
2467
4416
  }
2468
4417
 
4418
+ /**
4419
+ * Represents a mutable [W3C trace state list](https://www.w3.org/TR/trace-context/#tracestate-header), this is a
4420
+ * list of key/value pairs that are used to pass trace state information between different tracing systems. The
4421
+ * list is ordered and the order is important as it determines the processing order.
4422
+ *
4423
+ * Importantly instances of this type are mutable, change made to an instance via {@link IW3cTraceState.set} or
4424
+ * {@link IW3cTraceState.del} will be reflected on the instance and any child instances that use it as a parent.
4425
+ * However, any parent instance associated with an instance will not be modified by operations on that particular
4426
+ * instance.
4427
+ *
4428
+ * @since 3.4.0
4429
+ */
4430
+ interface IW3cTraceState {
4431
+ /**
4432
+ * Returns a readonly array of the current keys associated with the trace state, keys are returned in the
4433
+ * required processing order and if this instance has a parent the keys from the parent will be included
4434
+ * unless they have been removed (deleted) from the child instance.
4435
+ * Once created any modifications to the parent will also be reflected in the child, this is different from
4436
+ * the OpenTelemetry implementation which creates a new instance for each call.
4437
+ * @returns A readonly array of the current keys associated with the trace state
4438
+ */
4439
+ readonly keys: string[];
4440
+ /**
4441
+ * Check if the trace state list is empty, meaning it has no keys or values.
4442
+ * This exists to allow for quick checks without needing to create a new array of keys.
4443
+ * @since 3.4.0
4444
+ * @returns true if the trace state list is empty, false otherwise
4445
+ */
4446
+ readonly isEmpty: boolean;
4447
+ /**
4448
+ * Get the value for the specified key that is associated with this instance, either directly or from the parent.
4449
+ * @param key - The key to lookup
4450
+ * @returns The value for the key, or undefined if not found
4451
+ */
4452
+ get(key: string): string | undefined;
4453
+ /**
4454
+ * Set the value for the specified key for this instance, returning its new location within the list.
4455
+ * - 0 is the front of the list
4456
+ * - -1 not set because the key/value pair is invalid
4457
+ * If the key already exists it will be removed from its current location and added to the front of the list. And
4458
+ * if the key was in the parent this will override the value inherited from the parent, more importantly it will
4459
+ * not modify the parent value.
4460
+ * @param key - The key to set
4461
+ * @param value - The value to set
4462
+ * @returns 0 if successful, -1 if not
4463
+ */
4464
+ set(key: string, value: string): number;
4465
+ /**
4466
+ * Delete the specified key from this instance, if the key was in the parent it will be removed (hidden) from
4467
+ * this instance but will still be available directly from the parent.
4468
+ * @param key - The key to delete
4469
+ */
4470
+ del(key: string): void;
4471
+ /**
4472
+ * Format the trace state list into a strings where each string can be used as a header value.
4473
+ * This will return an empty array if the trace state list is empty.
4474
+ * @param maxHeaders - The maximum number of entries to include in the output, once the limit is reached no more entries will be included
4475
+ * @param maxKeys - The maximum number of keys to include in the output, once the limit is reached no more keys will be included
4476
+ * @param maxLen - The maximum length of each header value, once the limit is reached a new header value will be created
4477
+ * @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
4478
+ */
4479
+ hdrs(maxHeaders?: number, maxKeys?: number, maxLen?: number): string[];
4480
+ /**
4481
+ * Create a new instance of IW3cTraceState which is a child of this instance, meaning it will inherit the keys
4482
+ * and values from this instance but any changes made to the child will not affect this instance.
4483
+ * @returns A new instance of IW3cTraceState which is a child of this instance
4484
+ */
4485
+ child(): IW3cTraceState;
4486
+ }
4487
+
2469
4488
  interface IWatchDetails<T = IConfiguration> {
2470
4489
  /**
2471
4490
  * The current config object
@@ -2520,6 +4539,74 @@ declare namespace ApplicationInsights {
2520
4539
  processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
2521
4540
  }
2522
4541
 
4542
+ /**
4543
+ * Attribute values may be any non-nullish primitive value except an object.
4544
+ *
4545
+ * null or undefined attribute values are invalid and will result in undefined behavior.
4546
+ *
4547
+ * @since 3.4.0
4548
+ */
4549
+ type OTelAttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
4550
+
4551
+ /**
4552
+ * Defines Exception.
4553
+ *
4554
+ * string or an object with one of (message or name or code) and optional stack
4555
+ *
4556
+ * @since 3.4.0
4557
+ */
4558
+ type OTelException = IOTelExceptionWithCode | IOTelExceptionWithMessage | IOTelExceptionWithName | string;
4559
+
4560
+ /**
4561
+ * High-resolution time represented as a tuple of [seconds, nanoseconds].
4562
+ * This is the base type for all OpenTelemetry high-resolution time values.
4563
+ *
4564
+ * @remarks
4565
+ * The first element represents seconds since Unix epoch, and the second element
4566
+ * represents nanoseconds (0-999,999,999) within that second.
4567
+ *
4568
+ * @example
4569
+ * ```typescript
4570
+ * const hrTime: OTelHrTimeBase = [1609459200, 500000000]; // 2021-01-01 00:00:00.5 UTC
4571
+ * ```
4572
+ *
4573
+ * @since 3.4.0
4574
+ */
4575
+ type OTelHrTimeBase = [number, number];
4576
+
4577
+ /**
4578
+ * Creates an enum style object for the OTelSpanKind enum, providing the enum
4579
+ * values as properties of the object as both string and number types.
4580
+ * This allows for easy access to the enum values in a more readable format.
4581
+ */
4582
+ const OTelSpanKind: EnumValue<typeof eOTelSpanKind>;
4583
+
4584
+ type OTelSpanKind = number | eOTelSpanKind;
4585
+
4586
+ /**
4587
+ * Union type representing all valid time input formats accepted by OpenTelemetry APIs.
4588
+ *
4589
+ * @remarks
4590
+ * - `IOTelHrTime`: High-resolution time with nanosecond precision
4591
+ * - `number`: Milliseconds since Unix epoch (JavaScript Date.now() format)
4592
+ * - `Date`: JavaScript Date object
4593
+ *
4594
+ * @example
4595
+ * ```typescript
4596
+ * // All of these are valid time inputs:
4597
+ * const hrTime: OTelTimeInput = [1609459200, 500000000];
4598
+ * const msTime: OTelTimeInput = Date.now();
4599
+ * const dateTime: OTelTimeInput = new Date();
4600
+ *
4601
+ * span.addEvent("event", {}, hrTime);
4602
+ * span.addEvent("event", {}, msTime);
4603
+ * span.addEvent("event", {}, dateTime);
4604
+ * ```
4605
+ *
4606
+ * @since 3.4.0
4607
+ */
4608
+ type OTelTimeInput = IOTelHrTime | number | Date;
4609
+
2523
4610
  /**
2524
4611
  * This defines the handler function for when a promise is rejected.
2525
4612
  * @param value - This is the value passed as part of resolving the Promise