@microsoft/applicationinsights-analytics-js 3.3.12-nightly3.2602-18 → 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 (34) hide show
  1. package/browser/es5/applicationinsights-analytics-js.cjs.js +1328 -968
  2. package/browser/es5/applicationinsights-analytics-js.cjs.js.map +1 -1
  3. package/browser/es5/applicationinsights-analytics-js.cjs.min.js +2 -2
  4. package/browser/es5/applicationinsights-analytics-js.cjs.min.js.map +1 -1
  5. package/browser/es5/applicationinsights-analytics-js.gbl.js +1330 -970
  6. package/browser/es5/applicationinsights-analytics-js.gbl.js.map +1 -1
  7. package/browser/es5/applicationinsights-analytics-js.gbl.min.js +2 -2
  8. package/browser/es5/applicationinsights-analytics-js.gbl.min.js.map +1 -1
  9. package/browser/es5/applicationinsights-analytics-js.integrity.json +25 -25
  10. package/browser/es5/applicationinsights-analytics-js.js +1330 -970
  11. package/browser/es5/applicationinsights-analytics-js.js.map +1 -1
  12. package/browser/es5/applicationinsights-analytics-js.min.js +2 -2
  13. package/browser/es5/applicationinsights-analytics-js.min.js.map +1 -1
  14. package/dist/es5/applicationinsights-analytics-js.js +1328 -968
  15. package/dist/es5/applicationinsights-analytics-js.js.map +1 -1
  16. package/dist/es5/applicationinsights-analytics-js.min.js +2 -2
  17. package/dist/es5/applicationinsights-analytics-js.min.js.map +1 -1
  18. package/dist-es5/JavaScriptSDK/AnalyticsPlugin.js +45 -48
  19. package/dist-es5/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
  20. package/dist-es5/JavaScriptSDK/Interfaces/IAnalyticsConfig.js +1 -1
  21. package/dist-es5/JavaScriptSDK/Telemetry/PageViewManager.js +175 -181
  22. package/dist-es5/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
  23. package/dist-es5/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +87 -98
  24. package/dist-es5/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
  25. package/dist-es5/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +86 -94
  26. package/dist-es5/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
  27. package/dist-es5/JavaScriptSDK/Timing.js +19 -17
  28. package/dist-es5/JavaScriptSDK/Timing.js.map +1 -1
  29. package/dist-es5/__DynamicConstants.js +6 -6
  30. package/dist-es5/__DynamicConstants.js.map +1 -1
  31. package/dist-es5/applicationinsights-analytics-js.js +1 -1
  32. package/package.json +71 -72
  33. package/types/applicationinsights-analytics-js.d.ts +42 -12
  34. package/types/applicationinsights-analytics-js.namespaced.d.ts +2151 -34
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights JavaScript SDK - Web Analytics, 3.3.12-nightly3.2602-18
2
+ * Microsoft Application Insights JavaScript SDK - Web Analytics, 3.4.0-beta
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -261,19 +261,125 @@ declare namespace ApplicationInsights {
261
261
  PENDING = 3
262
262
  }
263
263
 
264
+ /**
265
+ * Const enum for attribute change operation types
266
+ */
267
+ const enum eAttributeChangeOp {
268
+ /**
269
+ * Clear operation - clearing all attributes
270
+ */
271
+ Clear = 0,
272
+ /**
273
+ * Set operation - setting an attribute value (generic)
274
+ */
275
+ Set = 1,
276
+ /**
277
+ * Add operation - adding a new attribute that didn't exist before
278
+ */
279
+ Add = 2,
280
+ /**
281
+ * Delete operation - deleting an attribute
282
+ */
283
+ Delete = 3,
284
+ /**
285
+ * Dropped attributes - attributes that were dropped due to size limits
286
+ */
287
+ DroppedAttributes = 4
288
+ }
289
+
290
+ /**
291
+ * Identifies the source of an attribute value in iterator operations
292
+ * @since 3.4.0
293
+ */
294
+ const enum eAttributeFilter {
295
+ /**
296
+ * The attribute exists local to the current container instance
297
+ */
298
+ Local = 0,
299
+ /**
300
+ * The attribute does not exist locally and is inherited from a parent container or attributes object
301
+ */
302
+ Inherited = 1,
303
+ /**
304
+ * The attribute exists or has been deleted locally (only) to the current container instance
305
+ */
306
+ LocalOrDeleted = 2
307
+ }
308
+
264
309
  const enum eDistributedTracingModes {
265
310
  /**
266
- * (Default) Send Application Insights correlation headers
311
+ * Send only the legacy Application Insights correlation headers
312
+ *
313
+ * Headers Sent:
314
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
315
+ *
316
+ * Config Decimal Value: `0` (Zero)
267
317
  */
268
318
  AI = 0,
269
319
  /**
270
- * Send both W3C Trace Context headers and back-compatibility Application Insights headers
320
+ * (Default) Send both W3C Trace parent header and back-compatibility Application Insights headers
321
+ * - `Request-Id`
322
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
323
+ *
324
+ * Config Decimal Value: `1` (One)
271
325
  */
272
326
  AI_AND_W3C = 1,
273
327
  /**
274
- * Send W3C Trace Context headers
328
+ * Send Only the W3C Trace parent header
329
+ *
330
+ * Headers Sent:
331
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
332
+ *
333
+ * Config Decimal Value: `2` (Two)
334
+ */
335
+ W3C = 2,
336
+ /**
337
+ * @internal
338
+ * Bitwise mask used to separate the base distributed tracing mode from the additional optional
339
+ * tracing modes.
340
+ * @since 3.4.0
341
+ */
342
+ _BaseMask = 15,
343
+ /**
344
+ * @internal
345
+ * Enabling this bit will send the W3C Trace State header, it is not intended to be used directly
346
+ * or on its own. The code may assume that if this bit is set, then the W3C Trace Context headers
347
+ * will also be included.
348
+ *
349
+ * Config Decimal Value: `16` (Sixteen in decimal)
350
+ * @since 3.4.0
351
+ */
352
+ _W3CTraceState = 16,
353
+ /**
354
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers and back-compatibility
355
+ * Application Insights headers.
356
+ *
357
+ * Currently sent headers:
358
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
359
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
360
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
361
+ *
362
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
363
+ * to include additional headers.
364
+ *
365
+ * Config Decimal Value: `17` (Seventeen in decimal)
366
+ * @since 3.4.0
367
+ */
368
+ AI_AND_W3C_TRACE = 17,
369
+ /**
370
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers.
371
+ *
372
+ * Currently sent headers:
373
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
374
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
375
+ *
376
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
377
+ * to include additional headers.
378
+ *
379
+ * Config Decimal Value: `18` (Eighteen in decimal)
380
+ * @since 3.4.0
275
381
  */
276
- W3C = 2
382
+ W3C_TRACE = 18
277
383
  }
278
384
 
279
385
  const enum _eInternalMessageId {
@@ -368,7 +474,12 @@ declare namespace ApplicationInsights {
368
474
  SdkLdrUpdate = 111,
369
475
  InitPromiseException = 112,
370
476
  StatsBeatManagerException = 113,
371
- StatsBeatException = 114
477
+ StatsBeatException = 114,
478
+ AttributeError = 115,
479
+ SpanError = 116,
480
+ TraceError = 117,
481
+ NotImplementedError = 118,
482
+ VersionMismatch = 119
372
483
  }
373
484
 
374
485
  const enum eLoggingSeverity {
@@ -406,6 +517,79 @@ declare namespace ApplicationInsights {
406
517
 
407
518
  type EnumValue<E = any> = EnumCls<E>;
408
519
 
520
+ /**
521
+ * The defined set of Span Kinds as defined by the OpenTelemetry.
522
+ */
523
+ const enum eOTelSpanKind {
524
+ /** Default value. Indicates that the span is used internally. */
525
+ INTERNAL = 0,
526
+ /**
527
+ * Indicates that the span covers server-side handling of an RPC or other
528
+ * remote request.
529
+ */
530
+ SERVER = 1,
531
+ /**
532
+ * Indicates that the span covers the client-side wrapper around an RPC or
533
+ * other remote request.
534
+ */
535
+ CLIENT = 2,
536
+ /**
537
+ * Indicates that the span describes producer sending a message to a
538
+ * broker. Unlike client and server, there is no direct critical path latency
539
+ * relationship between producer and consumer spans.
540
+ */
541
+ PRODUCER = 3,
542
+ /**
543
+ * Indicates that the span describes consumer receiving a message from a
544
+ * broker. Unlike client and server, there is no direct critical path latency
545
+ * relationship between producer and consumer spans.
546
+ */
547
+ CONSUMER = 4
548
+ }
549
+
550
+ /**
551
+ * An enumeration of status codes, matching the OpenTelemetry specification.
552
+ *
553
+ * @since 3.4.0
554
+ */
555
+ const enum eOTelSpanStatusCode {
556
+ /**
557
+ * The default status.
558
+ */
559
+ UNSET = 0,
560
+ /**
561
+ * The operation has been validated by an Application developer or
562
+ * Operator to have completed successfully.
563
+ */
564
+ OK = 1,
565
+ /**
566
+ * The operation contains an error.
567
+ */
568
+ ERROR = 2
569
+ }
570
+
571
+ /**
572
+ * Enum values for configuring trace context strategy for SPA route changes.
573
+ * Controls how trace contexts are managed when navigating between pages in a Single Page Application.
574
+ * @since 3.4.0
575
+ */
576
+ const enum eRouteTraceStrategy {
577
+ /**
578
+ * Server strategy: Each page view gets a new, independent trace context.
579
+ * No parent-child relationships are created between page views.
580
+ * Each page will use the original server-provided trace context (if available) as its parent,
581
+ * as defined by the {@link IConfiguration.traceHdrMode} configuration for distributed tracing headers.
582
+ * This is the traditional behavior where each page view is treated as a separate operation.
583
+ */
584
+ Server = 0,
585
+ /**
586
+ * Page strategy: Page views are chained together with parent-child relationships.
587
+ * Each new page view inherits the trace context from the previous page view,
588
+ * creating a connected chain of related operations for better correlation.
589
+ */
590
+ Page = 1
591
+ }
592
+
409
593
  /**
410
594
  * Defines the level of severity for the event.
411
595
  */
@@ -417,6 +601,30 @@ declare namespace ApplicationInsights {
417
601
  Critical = 4
418
602
  }
419
603
 
604
+ /**
605
+ * Controls how the SDK should look for trace headers (traceparent/tracestate) from the initial page load
606
+ * The values are bitwise OR'd together to allow for multiple values to be set at once.
607
+ * @since 3.4.0
608
+ */
609
+ const enum eTraceHeadersMode {
610
+ /**
611
+ * Don't look for any trace headers
612
+ */
613
+ None = 0,
614
+ /**
615
+ * Look for traceparent header/meta tag
616
+ */
617
+ TraceParent = 1,
618
+ /**
619
+ * Look for tracestate header/meta tag
620
+ */
621
+ TraceState = 2,
622
+ /**
623
+ * Look for both traceparent and tracestate headers/meta tags
624
+ */
625
+ All = 3
626
+ }
627
+
420
628
  const enum FeatureOptInMode {
421
629
  /**
422
630
  * not set, completely depends on cdn cfg
@@ -533,6 +741,14 @@ declare namespace ApplicationInsights {
533
741
  * @default { inclScripts: false, expLog: undefined, maxLogs: 50 }
534
742
  */
535
743
  expCfg?: IExceptionConfig;
744
+ /**
745
+ * Controls the trace context strategy for SPA route changes.
746
+ * Determines how trace contexts are managed and correlated across virtual page views
747
+ * in Single Page Applications, affecting telemetry correlation and operation tracking.
748
+ * @default eRouteTraceStrategy.Server
749
+ * @since 3.4.0
750
+ */
751
+ routeTraceStrategy?: eRouteTraceStrategy;
536
752
  }
537
753
 
538
754
  interface IAppInsights {
@@ -574,8 +790,7 @@ declare namespace ApplicationInsights {
574
790
  }): void;
575
791
  }
576
792
 
577
- interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
578
- readonly config: CfgType;
793
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider, ITraceHost<CfgType> {
579
794
  /**
580
795
  * The current logger instance for this instance.
581
796
  */
@@ -696,14 +911,13 @@ declare namespace ApplicationInsights {
696
911
  */
697
912
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
698
913
  /**
699
- * Gets the current distributed trace context for this instance if available
700
- * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
701
- */
702
- getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
703
- /**
704
- * Sets the current distributed trace context for this instance if available
914
+ * Set the trace provider for creating spans.
915
+ * This allows different SKUs to provide their own span implementations.
916
+ *
917
+ * @param provider - The trace provider to use for span creation
918
+ * @since 3.4.0
705
919
  */
706
- setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
920
+ setTraceProvider(provider: ICachedValue<ITraceProvider>): void;
707
921
  /**
708
922
  * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
709
923
  * handler will be recalled.
@@ -739,6 +953,150 @@ declare namespace ApplicationInsights {
739
953
  sendPageViewPerformanceInternal(pageViewPerformance: IPageViewPerformanceTelemetryInternal, properties?: Object, systemProperties?: Object): void;
740
954
  }
741
955
 
956
+ /**
957
+ * Information about what changed in an attribute container
958
+ */
959
+ interface IAttributeChangeInfo<V extends OTelAttributeValue = OTelAttributeValue> {
960
+ /**
961
+ * The Id of the container that is initiated the change (not the immediate sender -- which is always the parent)
962
+ * As children only receive listener notifications from their parent in reaction to both changes
963
+ * they make and any changes they receive from their parent
964
+ */
965
+ frm: string;
966
+ /**
967
+ * Operation type that occurred
968
+ */
969
+ op: eAttributeChangeOp;
970
+ /**
971
+ * The key that was changed (only present for 'set' operations)
972
+ */
973
+ k?: string;
974
+ /**
975
+ * The old value (only present for 'set' operations when replacing existing value)
976
+ */
977
+ prev?: V;
978
+ /**
979
+ * The new value (only present for 'set' operations)
980
+ */
981
+ val?: V;
982
+ }
983
+
984
+ /**
985
+ * Interface for an attribute container
986
+ * @since 3.4.0
987
+ */
988
+ interface IAttributeContainer<V extends OTelAttributeValue = OTelAttributeValue> {
989
+ /**
990
+ * Unique identifier for the attribute container
991
+ */
992
+ readonly id: string;
993
+ /**
994
+ * The number of attributes that have been set
995
+ * @returns The number of attributes that have been set
996
+ */
997
+ readonly size: number;
998
+ /**
999
+ * The number of attributes that were dropped due to the attribute limit being reached
1000
+ * @returns The number of attributes that were dropped due to the attribute limit being reached
1001
+ */
1002
+ readonly droppedAttributes: number;
1003
+ /**
1004
+ * Return a snapshot of the current attributes, including inherited ones.
1005
+ * This value is read-only and reflects the state of the attributes at the time of access,
1006
+ * and the returned instance will not change if any attributes are modified later, you will need
1007
+ * to access the attributes property again to get the latest state.
1008
+ *
1009
+ * Note: As this causes a snapshot to be taken, it is an expensive operation as it enumerates all
1010
+ * attributes, so you SHOULD use this property sparingly.
1011
+ * @returns A read-only snapshot of the current attributes
1012
+ */
1013
+ readonly attributes: IOTelAttributes;
1014
+ /**
1015
+ * Clear all existing attributes from the container, this will also remove any inherited attributes
1016
+ * from this instance only (it will not change the inherited attributes / container(s))
1017
+ */
1018
+ clear: () => void;
1019
+ /**
1020
+ * Get the value of an attribute by key
1021
+ * @param key - The attribute key to retrieve
1022
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
1023
+ * @returns The attribute value if found, undefined otherwise
1024
+ */
1025
+ get: (key: string, source?: eAttributeFilter) => V | undefined;
1026
+ /**
1027
+ * Check if an attribute exists by key
1028
+ * @param key - The attribute key to check
1029
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
1030
+ * @returns True if the attribute exists, false otherwise
1031
+ */
1032
+ has: (key: string, source?: eAttributeFilter) => boolean;
1033
+ /**
1034
+ * Set the value of an attribute by key on this instance.
1035
+ * @param key - The attribute key to set
1036
+ * @param value - The value to assign to the named attribute
1037
+ * @returns true if the value was successfully set / replaced
1038
+ */
1039
+ set: (key: string, value: V) => boolean;
1040
+ /**
1041
+ * Delete an existing attribute, if the key doesn't exist this will return false. If the key does
1042
+ * exist then it will be removed from this instance and any inherited value will be hidden (even if
1043
+ * the inherited value changes)
1044
+ * @param key - The attribute key to delete
1045
+ * @returns True if the attribute was deleted, false if it didn't exist (which includes if it has already been deleted)
1046
+ */
1047
+ del: (key: string) => boolean;
1048
+ /**
1049
+ * The keys() method returns a new iterator object that contains the existing keys for each element
1050
+ * in this attribute container. It will return all locally set keys first and then the inherited keys.
1051
+ * When a key exists in both the local and inherited attributes, only the local key will be returned.
1052
+ * If the key has been deleted locally, it will not be included in the iterator.
1053
+ * @returns An iterator over the keys of the attribute container
1054
+ */
1055
+ keys: () => Iterator<string>;
1056
+ /**
1057
+ * The entries() method of returns a new iterator object that contains the [key, value, source?] tuples for
1058
+ * each attribute, it returns all existing attributes of this instance including all inherited ones. If the
1059
+ * same key exists in both the local and inherited attributes, only the first (non-deleted) tuple will be returned.
1060
+ * If the key has been deleted, it will not be included in the iterator.
1061
+ *
1062
+ * The source value of the tuple identifies the origin of the attribute (Local or Inherited).
1063
+ * @returns An iterator over the entries of the attribute container
1064
+ */
1065
+ entries: () => Iterator<[string, V, eAttributeFilter]>;
1066
+ /**
1067
+ * The forEach() method of executes a provided function once per each key/value pair in this attribute container,
1068
+ * it will process all local attributes first, then the inherited attributes. If the same key exists in both the
1069
+ * local and inherited attributes, only the first (non-deleted) key/value pair will be processed.
1070
+ * If a key has been deleted, it will not be included in the set of processed key/value pairs.
1071
+ * @param callback - The function to execute for each key/value pair
1072
+ * @param thisArg - Optional value to use as `this` when executing `callback`
1073
+ */
1074
+ forEach: (callback: (key: string, value: V, source?: eAttributeFilter) => void, thisArg?: any) => void;
1075
+ /**
1076
+ * The values() method returns a new iterator instance that contains the values for each element in this
1077
+ * attribute container. It will return all locally set values first and then the inherited values. If the
1078
+ * same key is present in both the local or inherited attributes only the first (non-deleted) value will be
1079
+ * returned. If a key has been deleted, it will not be included in the iterator.
1080
+ * @returns An iterator over the values of the attribute container
1081
+ */
1082
+ values: () => Iterator<V>;
1083
+ /**
1084
+ * Register a callback listener for any attribute changes, this will include local and inherited changes.
1085
+ * @param callback - Function to be called when attributes change, receives change information
1086
+ * @returns IUnloadHook instance with rm() function to remove this listener, once called it will never be invoked again
1087
+ */
1088
+ listen: (callback: (changeInfo: IAttributeChangeInfo<V>) => void) => IUnloadHook;
1089
+ /**
1090
+ * Create a child attribute container that inherits from this one, optionally taking a snapshot
1091
+ * so that any future changes to the parent container do not affect the child container.
1092
+ * The child will use all of the configuration from the parent container.
1093
+ * @param name - Optional name for the child container
1094
+ * @param snapshot - If true, the child container will be a snapshot of the current state
1095
+ * @returns A new attribute container instance
1096
+ */
1097
+ child: (name?: string, snapshot?: boolean) => IAttributeContainer;
1098
+ }
1099
+
742
1100
  /**
743
1101
  * @description window.onerror function parameters
744
1102
  * @export
@@ -797,9 +1155,12 @@ declare namespace ApplicationInsights {
797
1155
  */
798
1156
  getCfg: () => IConfiguration;
799
1157
  /**
800
- * Gets the named extension config
1158
+ * Gets the named extension configuration
1159
+ * @param identifier - The named extension identifier
1160
+ * @param defaultValue - The default value(s) to return if no defined config exists
1161
+ * @param rootOnly - If true, only the look for the configuration in the top level and not in the "extensionConfig"
801
1162
  */
802
- getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
1163
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>, rootOnly?: boolean) => T;
803
1164
  /**
804
1165
  * Gets the named config from either the named identifier extension or core config if neither exist then the
805
1166
  * default value is returned
@@ -844,6 +1205,30 @@ declare namespace ApplicationInsights {
844
1205
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
845
1206
  }
846
1207
 
1208
+ /**
1209
+ * A generic interface for holding a cached value
1210
+ * @since 0.10.5
1211
+ * @group Helpers
1212
+ * @group Cache
1213
+ * @typeParam T - The type of the value to be cached
1214
+ * @example
1215
+ * ```ts
1216
+ * let cachedValue: ICachedValue<string> = {
1217
+ * v: "some value"
1218
+ * };
1219
+ * ```
1220
+ */
1221
+ interface ICachedValue<T> {
1222
+ /**
1223
+ * Returns the current cached value
1224
+ */
1225
+ v: T;
1226
+ /**
1227
+ * Returns the current cached value
1228
+ */
1229
+ toJSON(): T;
1230
+ }
1231
+
847
1232
  /**
848
1233
  * Provides data transmission capabilities
849
1234
  */
@@ -1288,7 +1673,7 @@ declare namespace ApplicationInsights {
1288
1673
  /**
1289
1674
  * Configuration provided to SDK core
1290
1675
  */
1291
- interface IConfiguration {
1676
+ interface IConfiguration extends IOTelConfig {
1292
1677
  /**
1293
1678
  * Instrumentation key of resource. Either this or connectionString must be specified.
1294
1679
  */
@@ -1490,6 +1875,12 @@ declare namespace ApplicationInsights {
1490
1875
  * @example ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature","auth_token", "api_key", "private_data"]
1491
1876
  */
1492
1877
  redactQueryParams?: string[];
1878
+ /**
1879
+ * [Optional] Controls if the SDK should look for the `traceparent` and/or `tracestate` values from
1880
+ * the service timing headers or meta tags from the initial page load.
1881
+ * @defaultValue eTraceHeadersMode.All
1882
+ */
1883
+ traceHdrMode?: eTraceHeadersMode;
1493
1884
  }
1494
1885
 
1495
1886
  interface ICookieMgr {
@@ -1622,7 +2013,7 @@ declare namespace ApplicationInsights {
1622
2013
  /**
1623
2014
  * The internal logging queue
1624
2015
  */
1625
- queue: _InternalLogMessage[];
2016
+ queue: IInternalLogMessage[];
1626
2017
  /**
1627
2018
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1628
2019
  * @param severity - The severity of the log message
@@ -1655,7 +2046,7 @@ declare namespace ApplicationInsights {
1655
2046
  * @param severity - The severity of the log message
1656
2047
  * @param message - The message to log.
1657
2048
  */
1658
- logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
2049
+ logInternalMessage?(severity: LoggingSeverity, message: IInternalLogMessage): void;
1659
2050
  /**
1660
2051
  * Optional Callback hook to allow the diagnostic logger to update it's configuration
1661
2052
  * @param updateState - The new configuration state to apply to the diagnostic logger
@@ -1670,16 +2061,25 @@ declare namespace ApplicationInsights {
1670
2061
  * / Promise to allow any listeners to wait for the operation to complete.
1671
2062
  */
1672
2063
  unload?(isAsync?: boolean): void | IPromise<void>;
2064
+ /**
2065
+ * A flag that indicates whether this logger is in debug (throw real exceptions) mode
2066
+ */
2067
+ readonly dbgMode?: boolean;
1673
2068
  }
1674
2069
 
1675
- interface IDistributedTraceContext {
2070
+ interface IDistributedTraceContext extends IDistributedTraceInit {
1676
2071
  /**
1677
2072
  * Returns the current name of the page
1678
2073
  */
1679
2074
  getName(): string;
1680
2075
  /**
1681
- * Sets the current name of the page
2076
+ * Sets the current name of the page, also updates the name for any parent context.
2077
+ * This is used to identify the page in the telemetry data.
2078
+ * @remarks This function updates the current and ALL parent contexts with the new name,
2079
+ * to just update the name of the current context, use the `pageName` property.
1682
2080
  * @param pageName - The name of the page
2081
+ * @deprecated Use the `pageName` property to avoid the side effect of changing the page name of all
2082
+ * parent contexts.
1683
2083
  */
1684
2084
  setName(pageName: string): void;
1685
2085
  /**
@@ -1692,6 +2092,12 @@ declare namespace ApplicationInsights {
1692
2092
  * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1693
2093
  * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1694
2094
  * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
2095
+ *
2096
+ * @remarks Sets the traceId for the current context AND all parent contexts, if you want to set the traceId
2097
+ * for the current context only, use the `traceId` property.
2098
+ * @param newValue - The traceId to set
2099
+ * @deprecated Use the `traceId` property to avoid the side effect of changing the traceId of all
2100
+ * parent contexts.
1695
2101
  */
1696
2102
  setTraceId(newValue: string): void;
1697
2103
  /**
@@ -1703,6 +2109,12 @@ declare namespace ApplicationInsights {
1703
2109
  * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1704
2110
  * Also know as the parentId, used to link requests together
1705
2111
  * https://www.w3.org/TR/trace-context/#parent-id
2112
+ *
2113
+ * @remarks Sets the spanId for the current context AND all parent contexts, if you want to set the spanId for
2114
+ * the current context only, use the `spanId` property.
2115
+ * @param newValue - The spanId to set
2116
+ * @deprecated Use the `spanId` property to avoid the side effect of changing the spanId of all
2117
+ * parent contexts.
1706
2118
  */
1707
2119
  setSpanId(newValue: string): void;
1708
2120
  /**
@@ -1711,9 +2123,258 @@ declare namespace ApplicationInsights {
1711
2123
  getTraceFlags(): number | undefined;
1712
2124
  /**
1713
2125
  * https://www.w3.org/TR/trace-context/#trace-flags
2126
+ * @remarks Sets the trace flags for the current context and ALL parent contexts, if you want to set the trace
2127
+ * flags for the current context only, use the `traceFlags` property.
1714
2128
  * @param newValue - An integer representation of the W3C TraceContext trace-flags.
2129
+ * @deprecated Use the `traceFlags` property to avoid the side effect of changing the traceFlags of all
2130
+ * parent contexts.
1715
2131
  */
1716
2132
  setTraceFlags(newValue?: number): void;
2133
+ /**
2134
+ * Returns the current name of the page
2135
+ * @remarks This function updates the current context only, to update the name of the current and ALL parent contexts,
2136
+ * use the `setName` method.
2137
+ * @default undefined
2138
+ * @since 3.4.0
2139
+ */
2140
+ pageName: string;
2141
+ /**
2142
+ * The current ID of the trace that this span belongs to. It is worldwide unique
2143
+ * with practically sufficient probability by being made as 16 randomly
2144
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
2145
+ * 128 bits.
2146
+ * @remarks It is NOT recommended that you dynamically change this value after creation and it is actively
2147
+ * being used as this may affect anyone accessing this context (as a parent for instance). You should logically
2148
+ * treat this as readonly after creation.
2149
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2150
+ * if you need to update the current and ALL parent contexts, use the `setTraceId` method which
2151
+ * provides the previous behavior.
2152
+ * @since 3.4.0
2153
+ */
2154
+ traceId: string;
2155
+ /**
2156
+ * The ID of the Span. It is globally unique with practically sufficient
2157
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
2158
+ * lowercase hex characters corresponding to 64 bits.
2159
+ * If you update this value, it will only update for the current context, not the parent context.
2160
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2161
+ * if you need to update the current and ALL parent contexts, use the `setSpanId` method.
2162
+ * @since 3.4.0
2163
+ */
2164
+ spanId: string;
2165
+ /**
2166
+ * Returns true if the current context was initialized (propagated) from a remote parent.
2167
+ * @since 3.4.0
2168
+ * @default false
2169
+ * @returns True if the context was propagated from a remote parent
2170
+ */
2171
+ readonly isRemote: boolean;
2172
+ /**
2173
+ * Trace flags to propagate.
2174
+ *
2175
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
2176
+ * sampled or not. When set, the least significant bit documents that the
2177
+ * caller may have recorded trace data. A caller who does not record trace
2178
+ * data out-of-band leaves this flag unset.
2179
+ *
2180
+ * see {@link eW3CTraceFlags} for valid flag values.
2181
+ *
2182
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2183
+ * if you need to update the current and ALL parent contexts, use the `setTraceFlags` method.
2184
+ * @since 3.4.0
2185
+ */
2186
+ traceFlags?: number;
2187
+ /**
2188
+ * Returns the current trace state which will be used to propgate context across different services.
2189
+ * Updating (adding / removing keys) of the trace state will modify the current context.IOTelTraceState
2190
+ * @remarks Unlike the OpenTelemetry {@link IOTelTraceState}, this value is a mutable object, so you can
2191
+ * modify it directly you do not need to reassign the new value to this property.
2192
+ * @since 3.4.0
2193
+ */
2194
+ readonly traceState: IW3cTraceState;
2195
+ /**
2196
+ * Provides access to the parent context of the current context.
2197
+ * @remarks This is a read-only property, you cannot modify the parent context directly, you can only
2198
+ * modify the current context. If you need to modify the parent context, you need to do it through the
2199
+ * current context using the `setTraceId`, `setSpanId`, `setTraceFlags` and `setName` methods.
2200
+ * @default null
2201
+ * @since 3.4.0
2202
+ */
2203
+ readonly parentCtx?: IDistributedTraceContext | null;
2204
+ }
2205
+
2206
+ /**
2207
+ * An object that can be used to populate a new {@link IDistributedTraceContext} instance,
2208
+ * the included {@link IW3cTraceState} or {@link IOTelTraceState} is used as the parent of the
2209
+ * created instances traceState
2210
+ */
2211
+ interface IDistributedTraceInit {
2212
+ /**
2213
+ * The unique identifier for the trace that this span belongs to.
2214
+ *
2215
+ * The trace ID is a globally unique identifier that connects all spans within a single
2216
+ * distributed trace. It consists of 16 randomly generated bytes encoded as 32 lowercase
2217
+ * hexadecimal characters, providing 128 bits of entropy to ensure worldwide uniqueness
2218
+ * with practically sufficient probability.
2219
+ *
2220
+ * @remarks
2221
+ * - Must be exactly 32 lowercase hexadecimal characters
2222
+ * - Represents 128 bits (16 bytes) of random data
2223
+ * - Shared by all spans within the same trace
2224
+ * - Used for trace correlation across distributed systems
2225
+ * - Should never be all zeros (invalid trace ID)
2226
+ *
2227
+ * @example
2228
+ * ```typescript
2229
+ * // Example trace ID format
2230
+ * const traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
2231
+ *
2232
+ * // All spans in the same trace share this ID
2233
+ * console.log(parentSpan.spanContext().traceId === childSpan.spanContext().traceId); // true
2234
+ * ```
2235
+ */
2236
+ traceId: string;
2237
+ /**
2238
+ * The unique identifier for this specific span within the trace.
2239
+ *
2240
+ * The span ID uniquely identifies this span within the trace and is used to establish
2241
+ * parent-child relationships between spans. It consists of 8 randomly generated bytes
2242
+ * encoded as 16 lowercase hexadecimal characters, providing 64 bits of entropy to
2243
+ * ensure global uniqueness with practically sufficient probability.
2244
+ *
2245
+ * @remarks
2246
+ * - Must be exactly 16 lowercase hexadecimal characters
2247
+ * - Represents 64 bits (8 bytes) of random data
2248
+ * - Unique within the trace (different spans have different span IDs)
2249
+ * - Used as parent ID when creating child spans
2250
+ * - Should never be all zeros (invalid span ID)
2251
+ *
2252
+ * @example
2253
+ * ```typescript
2254
+ * // Example span ID format
2255
+ * const spanId = "00f067aa0ba902b7";
2256
+ *
2257
+ * // Each span has a unique ID within the trace
2258
+ * const parentId = parentSpan.spanContext().spanId; // "00f067aa0ba902b7"
2259
+ * const childId = childSpan.spanContext().spanId; // "b9c7c989f97918e1"
2260
+ *
2261
+ * // Child span uses parent's span ID as its parent ID
2262
+ * console.log(childSpan.parentSpanId === parentId); // true
2263
+ * ```
2264
+ */
2265
+ spanId: string;
2266
+ /**
2267
+ * Indicates whether this span context was propagated from a remote parent span.
2268
+ *
2269
+ * This flag distinguishes between spans created locally within the same process
2270
+ * and spans that represent operations in remote services. Remote spans are typically
2271
+ * created when trace context is received via HTTP headers, message queues, or other
2272
+ * inter-process communication mechanisms.
2273
+ *
2274
+ * @defaultValue false - spans are considered local unless explicitly marked as remote
2275
+ *
2276
+ * @remarks
2277
+ * - True only when span context was received from another process/service
2278
+ * - Helps distinguish local vs. distributed trace segments
2279
+ * - Used by tracing systems for visualization and analysis
2280
+ * - Local child spans of remote parents are NOT considered remote themselves
2281
+ *
2282
+ * @example
2283
+ * ```typescript
2284
+ * // HTTP service receiving trace context
2285
+ * const incomingSpanContext = extractSpanContextFromHeaders(request.headers);
2286
+ * console.log(incomingSpanContext.isRemote); // true
2287
+ *
2288
+ * // Child span created locally
2289
+ * const localChild = tracer.startSpan('local-operation', {
2290
+ * parent: incomingSpanContext
2291
+ * });
2292
+ * console.log(localChild.spanContext().isRemote); // false
2293
+ * ```
2294
+ */
2295
+ isRemote?: boolean;
2296
+ /**
2297
+ * Trace flags that control trace behavior and indicate sampling decisions.
2298
+ *
2299
+ * The trace flags are represented as a single byte (8-bit bitmap) that carries
2300
+ * trace-level information. The least significant bit (0x01) indicates whether
2301
+ * the trace is sampled. When this bit is set, it documents that the caller
2302
+ * may have recorded trace data. Additional bits are reserved for future use
2303
+ * and should be ignored when not understood.
2304
+ *
2305
+ * @remarks
2306
+ * - Represented as a number (0-255) corresponding to 8 bits
2307
+ * - Bit 0 (0x01): Sampled flag - indicates trace may contain recorded data
2308
+ * - Bits 1-7: Reserved for future use, should be preserved during propagation
2309
+ * - Used by sampling algorithms to make consistent decisions across services
2310
+ * - See {@link eW3CTraceFlags} for standard flag values
2311
+ *
2312
+ * @example
2313
+ * ```typescript
2314
+ * // Check if trace is sampled
2315
+ * const isSampled = (spanContext.traceFlags & 0x01) === 1;
2316
+ *
2317
+ * // Common flag values
2318
+ * const UNSAMPLED = 0x00; // 00000000 - not sampled
2319
+ * const SAMPLED = 0x01; // 00000001 - sampled
2320
+ *
2321
+ * // Preserving unknown flags during propagation
2322
+ * const preservedFlags = spanContext.traceFlags | 0x01; // Set sampled bit while preserving others
2323
+ *
2324
+ * // W3C traceparent header format includes these flags
2325
+ * const traceparent = `00-${traceId}-${spanId}-${traceFlags.toString(16).padStart(2, '0')}`;
2326
+ * ```
2327
+ */
2328
+ traceFlags?: number;
2329
+ /**
2330
+ * Vendor-specific trace state information for cross-system trace correlation.
2331
+ *
2332
+ * The trace state carries tracing-system-specific context in a standardized format
2333
+ * defined by the W3C Trace Context specification. It allows multiple tracing systems
2334
+ * to participate in the same trace by providing a mechanism for each system to add
2335
+ * its own metadata without interfering with others.
2336
+ *
2337
+ * The trace state is formatted as a comma-separated list of key-value pairs, where
2338
+ * each pair represents one tracing system's contribution. Keys should be unique
2339
+ * within the trace state and follow specific naming conventions.
2340
+ *
2341
+ * @remarks
2342
+ * - Maximum of 32 list members allowed
2343
+ * - Each member format: `key=value` separated by commas
2344
+ * - Keys should be namespaced to avoid conflicts (e.g., `vendor@system=value`)
2345
+ * - Total size should not exceed 512 characters for practical header limits
2346
+ * - Spaces around list members are ignored
2347
+ * - Preserves vendor-specific information during trace propagation
2348
+ *
2349
+ * @see {@link https://www.w3.org/TR/trace-context/#tracestate-field | W3C Trace Context Specification}
2350
+ *
2351
+ * @example
2352
+ * ```typescript
2353
+ * // Single tracing system
2354
+ * const singleVendor = {
2355
+ * get: (key: string) => key === 'rojo' ? '00f067aa0ba902b7' : undefined,
2356
+ * set: (key: string, value: string) => { ... },
2357
+ * unset: (key: string) => { ... },
2358
+ * serialize: () => 'rojo=00f067aa0ba902b7'
2359
+ * };
2360
+ *
2361
+ * // Multiple tracing systems
2362
+ * const multiVendor = {
2363
+ * serialize: () => 'rojo=00f067aa0ba902b7,congo=t61rcWkgMzE,vendor@system=custom-value'
2364
+ * };
2365
+ *
2366
+ * // Accessing trace state
2367
+ * const rojoValue = spanContext.traceState?.get('rojo');
2368
+ * const serialized = spanContext.traceState?.serialize();
2369
+ *
2370
+ * // HTTP header format (When the traceState is an IOTelTraceState)
2371
+ * headers['tracestate'] = spanContext.traceState?.serialize() || '';
2372
+ *
2373
+ * // HTTP header format (When the traceState is an IW3cTraceState)
2374
+ * headers['tracestate'] = spanContext.traceState?.hdrs()[0] || '';
2375
+ * ```
2376
+ */
2377
+ traceState?: IW3cTraceState | IOTelTraceState;
1717
2378
  }
1718
2379
 
1719
2380
  interface IEventTelemetry extends IPartC {
@@ -1817,7 +2478,7 @@ declare namespace ApplicationInsights {
1817
2478
  * Identifies configuration override values when given feature is enabled
1818
2479
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1819
2480
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1820
- * Default: undefined
2481
+ * @default undefined
1821
2482
  */
1822
2483
  onCfg?: {
1823
2484
  [field: string]: any;
@@ -1826,7 +2487,7 @@ declare namespace ApplicationInsights {
1826
2487
  * Identifies configuration override values when given feature is disabled
1827
2488
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1828
2489
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1829
- * Default: undefined
2490
+ * @default undefined
1830
2491
  */
1831
2492
  offCfg?: {
1832
2493
  [field: string]: any;
@@ -1838,6 +2499,11 @@ declare namespace ApplicationInsights {
1838
2499
  blockCdnCfg?: boolean;
1839
2500
  }
1840
2501
 
2502
+ interface IInternalLogMessage {
2503
+ message: string;
2504
+ messageId: _InternalMessageId;
2505
+ }
2506
+
1841
2507
  /**
1842
2508
  * Internal Interface
1843
2509
  */
@@ -2071,20 +2737,1067 @@ declare namespace ApplicationInsights {
2071
2737
  offlineBatchDrop?(cnt: number, reason?: number): void;
2072
2738
  }
2073
2739
 
2074
- class _InternalLogMessage {
2075
- static dataType: string;
2076
- message: string;
2077
- messageId: _InternalMessageId;
2078
- constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
2079
- }
2080
-
2081
2740
  type _InternalMessageId = number | _eInternalMessageId;
2082
2741
 
2083
- interface IPageViewPerformanceTelemetry extends IPartC {
2742
+ /**
2743
+ * The main OpenTelemetry API interface that provides access to all OpenTelemetry functionality.
2744
+ * This interface extends the IOTelTracerProvider and serves as the entry point for OpenTelemetry operations.
2745
+ *
2746
+ * @example
2747
+ * ```typescript
2748
+ * // Get a tracer from the API instance
2749
+ * const tracer = otelApi.getTracer("my-component");
2750
+ *
2751
+ * // Create a span
2752
+ * const span = tracer.startSpan("operation");
2753
+ *
2754
+ * // Access context manager
2755
+ * const currentContext = otelApi.context.active();
2756
+ *
2757
+ * // Access trace API
2758
+ * const activeSpan = otelApi.trace.getActiveSpan();
2759
+ * ```
2760
+ *
2761
+ * @since 3.4.0
2762
+ */
2763
+ interface IOTelApi extends IOTelTracerProvider {
2084
2764
  /**
2085
- * name String - The name of the page. Defaults to the document title.
2765
+ * The configuration object that contains all OpenTelemetry-specific settings.
2766
+ * This includes tracing configuration, error handlers, and other OpenTelemetry options.
2767
+ *
2768
+ * @remarks
2769
+ * Changes to this configuration after initialization may not take effect until
2770
+ * the next telemetry operation, depending on the implementation.
2086
2771
  */
2087
- name?: string;
2772
+ cfg: IOTelConfig;
2773
+ /**
2774
+ * The current {@link ITraceHost} instance for this IOTelApi instance, this is effectively
2775
+ * the OpenTelemetry ContextAPI instance without the static methods.
2776
+ * @returns The ContextManager instance
2777
+ */
2778
+ host: ITraceHost;
2779
+ /**
2780
+ * The current {@link ITraceApi} instance for this IOTelApi instance, this is
2781
+ * effectively the OpenTelemetry TraceAPI instance without the static methods.
2782
+ * @returns The current {@link ITraceApi} instance
2783
+ */
2784
+ trace: ITraceApi;
2785
+ }
2786
+
2787
+ /**
2788
+ * Configuration interface for OpenTelemetry attribute limits.
2789
+ * These limits help control the size and number of attributes to prevent
2790
+ * excessive memory usage and ensure consistent performance.
2791
+ *
2792
+ * @example
2793
+ * ```typescript
2794
+ * const limits: IOTelAttributeLimits = {
2795
+ * attributeCountLimit: 128, // Maximum 128 attributes
2796
+ * attributeValueLengthLimit: 4096 // Maximum 4KB per attribute value
2797
+ * };
2798
+ * ```
2799
+ *
2800
+ * @remarks
2801
+ * When limits are exceeded:
2802
+ * - Additional attributes beyond `attributeCountLimit` are dropped
2803
+ * - Attribute values longer than `attributeValueLengthLimit` are truncated
2804
+ * - The behavior may vary based on the specific implementation
2805
+ *
2806
+ * @since 3.4.0
2807
+ */
2808
+ interface IOTelAttributeLimits {
2809
+ /**
2810
+ * Maximum allowed length for attribute values in characters.
2811
+ *
2812
+ * @remarks
2813
+ * - Values longer than this limit will be truncated
2814
+ * - Applies to string attribute values only
2815
+ * - Numeric and boolean values are not affected by this limit
2816
+ * - Array values have this limit applied to each individual element
2817
+ *
2818
+ * @defaultValue 4096
2819
+ *
2820
+ * @example
2821
+ * ```typescript
2822
+ * // If attributeValueLengthLimit is 100:
2823
+ * span.setAttribute("description", "a".repeat(200)); // Will be truncated to 100 characters
2824
+ * span.setAttribute("count", 12345); // Not affected (number)
2825
+ * span.setAttribute("enabled", true); // Not affected (boolean)
2826
+ * ```
2827
+ */
2828
+ attributeValueLengthLimit?: number;
2829
+ /**
2830
+ * Maximum number of attributes allowed per telemetry item.
2831
+ *
2832
+ * @remarks
2833
+ * - Attributes added beyond this limit will be dropped
2834
+ * - The order of attributes matters; earlier attributes take precedence
2835
+ * - This limit applies to the total count of attributes, regardless of their type
2836
+ * - Inherited or default attributes count toward this limit
2837
+ *
2838
+ * @defaultValue 128
2839
+ *
2840
+ * @example
2841
+ * ```typescript
2842
+ * // If attributeCountLimit is 5:
2843
+ * span.setAttributes({
2844
+ * "attr1": "value1", // Kept
2845
+ * "attr2": "value2", // Kept
2846
+ * "attr3": "value3", // Kept
2847
+ * "attr4": "value4", // Kept
2848
+ * "attr5": "value5", // Kept
2849
+ * "attr6": "value6" // Dropped (exceeds limit)
2850
+ * });
2851
+ * ```
2852
+ */
2853
+ attributeCountLimit?: number;
2854
+ }
2855
+
2856
+ /**
2857
+ * Attributes is a map from string to attribute values.
2858
+ *
2859
+ * Note: only the own enumerable keys are counted as valid attribute keys.
2860
+ *
2861
+ * @since 3.4.0
2862
+ */
2863
+ interface IOTelAttributes {
2864
+ [key: string]: OTelAttributeValue | undefined;
2865
+ }
2866
+
2867
+ /**
2868
+ * OpenTelemetry configuration interface
2869
+ * Provides configuration specific to the OpenTelemetry extensions
2870
+ */
2871
+ interface IOTelConfig {
2872
+ /**
2873
+ * Configuration interface for OpenTelemetry tracing functionality.
2874
+ * This interface contains all the settings that control how traces are created,
2875
+ * processed, and managed within the OpenTelemetry system.
2876
+ *
2877
+ * @example
2878
+ * ```typescript
2879
+ * const traceCfg: ITraceCfg = {
2880
+ * serviceName: "my-service",
2881
+ * generalLimits: {
2882
+ * attributeCountLimit: 128,
2883
+ * attributeValueLengthLimit: 4096
2884
+ * },
2885
+ * spanLimits: {
2886
+ * attributeCountLimit: 128,
2887
+ * linkCountLimit: 128,
2888
+ * eventCountLimit: 128
2889
+ * }
2890
+ * };
2891
+ * ```
2892
+ *
2893
+ * @since 3.4.0
2894
+ */
2895
+ traceCfg?: ITraceCfg;
2896
+ /**
2897
+ * Error handlers for OpenTelemetry operations.
2898
+ * This interface allows you to specify custom error handling logic for various
2899
+ * OpenTelemetry components, enabling better control over how errors are managed
2900
+ * within the OpenTelemetry system.
2901
+ *
2902
+ * @see {@link IOTelErrorHandlers}
2903
+ *
2904
+ * @example
2905
+ * ```typescript
2906
+ * const errorHandlers: IOTelErrorHandlers = {
2907
+ * attribError: (message, key, value) => {
2908
+ * console.warn(`Attribute error for ${key}:`, message);
2909
+ * }
2910
+ * };
2911
+ * ```
2912
+ */
2913
+ errorHandlers?: IOTelErrorHandlers;
2914
+ }
2915
+
2916
+ /**
2917
+ * Configuration interface for OpenTelemetry error handling callbacks.
2918
+ * Provides hooks to customize how different types of errors and diagnostic
2919
+ * messages are handled within the OpenTelemetry system.
2920
+ *
2921
+ * @example
2922
+ * ```typescript
2923
+ * const errorHandlers: IOTelErrorHandlers = {
2924
+ * attribError: (message, key, value) => {
2925
+ * console.warn(`Attribute error for ${key}:`, message);
2926
+ * },
2927
+ * spanError: (message, spanName) => {
2928
+ * logger.error(`Span ${spanName} error:`, message);
2929
+ * },
2930
+ * warn: (message) => {
2931
+ * logger.warn(message);
2932
+ * },
2933
+ * error: (message) => {
2934
+ * logger.error(message);
2935
+ * }
2936
+ * };
2937
+ * ```
2938
+ *
2939
+ * @remarks
2940
+ * If handlers are not provided, default behavior will be used:
2941
+ * - `attribError`: Throws an `OTelInvalidAttributeError`
2942
+ * - `spanError`: Logs to console or calls warn handler
2943
+ * - `debug`: Logs to console.log
2944
+ * - `warn`: Logs to console.warn
2945
+ * - `error`: Logs to console.error
2946
+ * - `notImplemented`: Logs to console.error
2947
+ *
2948
+ * @since 3.4.0
2949
+ */
2950
+ interface IOTelErrorHandlers {
2951
+ /**
2952
+ * Handles attribute-related errors, such as invalid attribute values or keys.
2953
+ * Called when an attribute operation fails validation or processing.
2954
+ *
2955
+ * @param message - Descriptive error message explaining what went wrong
2956
+ * @param key - The attribute key that caused the error
2957
+ * @param value - The attribute value that caused the error (may be of any type)
2958
+ *
2959
+ * @remarks
2960
+ * Common scenarios that trigger this handler:
2961
+ * - Invalid attribute key format
2962
+ * - Attribute value exceeds length limits
2963
+ * - Unsupported attribute value type
2964
+ * - Attribute count exceeds limits
2965
+ *
2966
+ * @default Throws an `OTelInvalidAttributeError`
2967
+ *
2968
+ * @example
2969
+ * ```typescript
2970
+ * attribError: (message, key, value) => {
2971
+ * metrics.increment('otel.attribute.errors', { key, type: typeof value });
2972
+ * logger.warn(`Attribute ${key} rejected: ${message}`);
2973
+ * }
2974
+ * ```
2975
+ */
2976
+ attribError?: (message: string, key: string, value: any) => void;
2977
+ /**
2978
+ * Handles span-related errors that occur during span operations.
2979
+ * Called when a span operation fails or encounters an unexpected condition.
2980
+ *
2981
+ * @param message - Descriptive error message explaining the span error
2982
+ * @param spanName - The name of the span that encountered the error
2983
+ *
2984
+ * @remarks
2985
+ * Common scenarios that trigger this handler:
2986
+ * - Span operation called on an ended span
2987
+ * - Invalid span configuration
2988
+ * - Span processor errors
2989
+ * - Context propagation failures
2990
+ *
2991
+ * @default Logs to console or calls the warn handler
2992
+ *
2993
+ * @example
2994
+ * ```typescript
2995
+ * spanError: (message, spanName) => {
2996
+ * metrics.increment('otel.span.errors', { span_name: spanName });
2997
+ * logger.error(`Span operation failed for "${spanName}": ${message}`);
2998
+ * }
2999
+ * ```
3000
+ */
3001
+ spanError?: (message: string, spanName: string) => void;
3002
+ /**
3003
+ * Handles debug-level diagnostic messages.
3004
+ * Used for detailed troubleshooting information that is typically
3005
+ * only relevant during development or when diagnosing issues.
3006
+ *
3007
+ * @param message - Debug message to be handled
3008
+ *
3009
+ * @remarks
3010
+ * Debug messages are typically:
3011
+ * - Verbose operational details
3012
+ * - Internal state information
3013
+ * - Performance metrics
3014
+ * - Development-time diagnostics
3015
+ *
3016
+ * @default Logs to console.log
3017
+ *
3018
+ * @example
3019
+ * ```typescript
3020
+ * debug: (message) => {
3021
+ * if (process.env.NODE_ENV === 'development') {
3022
+ * console.debug('[OTel Debug]', message);
3023
+ * }
3024
+ * }
3025
+ * ```
3026
+ */
3027
+ debug?: (message: string) => void;
3028
+ /**
3029
+ * Handles warning-level messages for non-fatal issues.
3030
+ * Used for conditions that are unusual but don't prevent continued operation.
3031
+ *
3032
+ * @param message - Warning message to be handled
3033
+ *
3034
+ * @remarks
3035
+ * Warning scenarios include:
3036
+ * - Configuration issues that fall back to defaults
3037
+ * - Performance degradation
3038
+ * - Deprecated API usage
3039
+ * - Resource limit approaches
3040
+ *
3041
+ * @default Logs to console.warn
3042
+ *
3043
+ * @example
3044
+ * ```typescript
3045
+ * warn: (message) => {
3046
+ * logger.warn('[OTel Warning]', message);
3047
+ * metrics.increment('otel.warnings');
3048
+ * }
3049
+ * ```
3050
+ */
3051
+ warn?: (message: string) => void;
3052
+ /**
3053
+ * Handles general error conditions that may affect functionality.
3054
+ * Used for significant errors that should be investigated but may not be fatal.
3055
+ *
3056
+ * @param message - Error message to be handled
3057
+ *
3058
+ * @remarks
3059
+ * Error scenarios include:
3060
+ * - Failed network requests
3061
+ * - Configuration validation failures
3062
+ * - Resource allocation failures
3063
+ * - Unexpected runtime conditions
3064
+ *
3065
+ * @default Logs to console.error
3066
+ *
3067
+ * @example
3068
+ * ```typescript
3069
+ * error: (message) => {
3070
+ * logger.error('[OTel Error]', message);
3071
+ * errorReporting.captureException(new Error(message));
3072
+ * }
3073
+ * ```
3074
+ */
3075
+ error?: (message: string) => void;
3076
+ /**
3077
+ * Handles errors related to unimplemented functionality.
3078
+ * Called when a method or feature is not yet implemented or is intentionally
3079
+ * disabled in the current configuration.
3080
+ *
3081
+ * @param message - Message describing the unimplemented functionality
3082
+ *
3083
+ * @remarks
3084
+ * Common scenarios:
3085
+ * - Placeholder methods that haven't been implemented
3086
+ * - Features disabled in the current build
3087
+ * - Platform-specific functionality not available
3088
+ * - Optional features not included in the configuration
3089
+ *
3090
+ * @default Logs to console.error
3091
+ *
3092
+ * @example
3093
+ * ```typescript
3094
+ * notImplemented: (message) => {
3095
+ * logger.warn(`[OTel Not Implemented] ${message}`);
3096
+ * if (process.env.NODE_ENV === 'development') {
3097
+ * console.trace('Not implemented method called');
3098
+ * }
3099
+ * }
3100
+ * ```
3101
+ */
3102
+ notImplemented?: (message: string) => void;
3103
+ }
3104
+
3105
+ interface IOTelExceptionWithCode {
3106
+ code: string | number;
3107
+ name?: string;
3108
+ message?: string;
3109
+ stack?: string;
3110
+ }
3111
+
3112
+ interface IOTelExceptionWithMessage {
3113
+ code?: string | number;
3114
+ message: string;
3115
+ name?: string;
3116
+ stack?: string;
3117
+ }
3118
+
3119
+ interface IOTelExceptionWithName {
3120
+ code?: string | number;
3121
+ message?: string;
3122
+ name: string;
3123
+ stack?: string;
3124
+ }
3125
+
3126
+ /**
3127
+ * Enhanced high-resolution time interface that extends the base tuple with additional properties.
3128
+ * Provides a more structured way to work with high-resolution timestamps.
3129
+ *
3130
+ * @example
3131
+ * ```typescript
3132
+ * const hrTime: IOTelHrTime = {
3133
+ * 0: 1609459200, // seconds since Unix epoch
3134
+ * 1: 500000000, // nanoseconds (0-999,999,999)
3135
+ * };
3136
+ * ```
3137
+ *
3138
+ * @since 3.4.0
3139
+ */
3140
+ interface IOTelHrTime extends OTelHrTimeBase {
3141
+ /**
3142
+ * Seconds since Unix epoch (January 1, 1970 00:00:00 UTC).
3143
+ * Must be a non-negative integer.
3144
+ */
3145
+ 0: number;
3146
+ /**
3147
+ * Nanoseconds within the second specified by index 0.
3148
+ * Must be in the range [0, 999999999].
3149
+ */
3150
+ 1: number;
3151
+ }
3152
+
3153
+ /**
3154
+ * Provides an OpenTelemetry compatible interface for spans conforming to the OpenTelemetry API specification (v1.9.0).
3155
+ *
3156
+ * A span represents an operation within a trace and is the fundamental unit of work in distributed tracing.
3157
+ * Spans can be thought of as a grouping mechanism for a set of operations that are executed as part of
3158
+ * a single logical unit of work, providing timing information and contextual data about the operation.
3159
+ *
3160
+ * Spans form a tree structure within a trace, with a single root span that may have zero or more child spans,
3161
+ * which in turn may have their own children. This hierarchical structure allows for detailed analysis of
3162
+ * complex, multi-step operations across distributed systems.
3163
+ *
3164
+ * @since 3.4.0
3165
+ *
3166
+ * @remarks
3167
+ * - All spans created by this library implement the ISpan interface and extend the IReadableSpan interface
3168
+ * - Spans should be ended by calling `end()` when the operation completes
3169
+ * - Once ended, spans should generally not be used for further operations
3170
+ * - Spans automatically track timing information from creation to end
3171
+ *
3172
+ * @example
3173
+ * ```typescript
3174
+ * // Basic span usage
3175
+ * const span = tracer.startSpan('user-authentication');
3176
+ * span.setAttribute('user.id', '12345');
3177
+ * span.setAttribute('auth.method', 'oauth2');
3178
+ *
3179
+ * try {
3180
+ * const result = await authenticateUser();
3181
+ * span.setStatus({ code: SpanStatusCode.OK });
3182
+ * span.setAttribute('auth.success', true);
3183
+ * } catch (error) {
3184
+ * span.recordException(error);
3185
+ * span.setStatus({
3186
+ * code: SpanStatusCode.ERROR,
3187
+ * message: 'Authentication failed'
3188
+ * });
3189
+ * } finally {
3190
+ * span.end();
3191
+ * }
3192
+ * ```
3193
+ */
3194
+ interface IOTelSpan {
3195
+ /**
3196
+ * Returns the span context object associated with this span.
3197
+ *
3198
+ * The span context is an immutable, serializable identifier that uniquely identifies
3199
+ * this span within a trace. It contains the trace ID, span ID, and trace flags that
3200
+ * can be used to create new child spans or propagate trace context across process boundaries.
3201
+ *
3202
+ * The returned span context remains valid even after the span has ended, making it
3203
+ * useful for asynchronous operations and cross-service communication.
3204
+ *
3205
+ * @returns The immutable span context associated with this span
3206
+ *
3207
+ * @remarks
3208
+ * - The span context is the primary mechanism for trace propagation
3209
+ * - Context can be serialized and transmitted across network boundaries
3210
+ * - Contains trace ID (unique to the entire trace) and span ID (unique to this span)
3211
+ *
3212
+ * @example
3213
+ * ```typescript
3214
+ * const span = tracer.startSpan('parent-operation');
3215
+ * const spanContext = span.spanContext();
3216
+ *
3217
+ * // Use context to create child spans in other parts of the system
3218
+ * const childSpan = tracer.startSpan('child-operation', {
3219
+ * parent: spanContext
3220
+ * });
3221
+ *
3222
+ * // Context can be serialized for cross-service propagation
3223
+ * const traceId = spanContext.traceId;
3224
+ * const spanId = spanContext.spanId;
3225
+ * ```
3226
+ */
3227
+ spanContext(): IDistributedTraceContext;
3228
+ /**
3229
+ * Sets a single attribute on the span with the specified key and value.
3230
+ *
3231
+ * Attributes provide contextual information about the operation represented by the span.
3232
+ * They are key-value pairs that help with filtering, grouping, and understanding spans
3233
+ * in trace analysis tools. Attributes should represent meaningful properties of the operation.
3234
+ *
3235
+ * @param key - The attribute key, should be descriptive and follow naming conventions
3236
+ * @param value - The attribute value; null or undefined values are invalid and result in undefined behavior
3237
+ *
3238
+ * @returns This span instance for method chaining
3239
+ *
3240
+ * @remarks
3241
+ * - Attribute keys should follow semantic conventions when available
3242
+ * - Common attributes include service.name, http.method, db.statement, etc.
3243
+ * - Setting null or undefined values is invalid and may cause unexpected behavior
3244
+ * - Attributes set after span creation don't affect sampling decisions
3245
+ *
3246
+ * @example
3247
+ * ```typescript
3248
+ * const span = tracer.startSpan('http-request');
3249
+ *
3250
+ * // Set individual attributes with descriptive keys
3251
+ * span.setAttribute('http.method', 'POST')
3252
+ * .setAttribute('http.url', 'https://api.example.com/users')
3253
+ * .setAttribute('http.status_code', 201)
3254
+ * .setAttribute('user.id', '12345')
3255
+ * .setAttribute('request.size', 1024);
3256
+ * ```
3257
+ */
3258
+ setAttribute(key: string, value: OTelAttributeValue): this;
3259
+ /**
3260
+ * Sets multiple attributes on the span at once using an attributes object.
3261
+ *
3262
+ * This method allows efficient batch setting of multiple attributes in a single call.
3263
+ * All attributes in the provided object will be added to the span, supplementing any
3264
+ * existing attributes (duplicate keys will be overwritten).
3265
+ *
3266
+ * @param attributes - An object containing key-value pairs to set as span attributes
3267
+ *
3268
+ * @returns This span instance for method chaining
3269
+ *
3270
+ * @remarks
3271
+ * - Null or undefined attribute values are invalid and will result in undefined behavior
3272
+ * - More efficient than multiple `setAttribute` calls for bulk operations
3273
+ * - Existing attributes with the same keys will be overwritten
3274
+ *
3275
+ * @example
3276
+ * ```typescript
3277
+ * const span = tracer.startSpan('database-query');
3278
+ *
3279
+ * // Set multiple attributes efficiently
3280
+ * span.setAttributes({
3281
+ * 'db.system': 'postgresql',
3282
+ * 'db.name': 'user_database',
3283
+ * 'db.table': 'users',
3284
+ * 'db.operation': 'SELECT',
3285
+ * 'db.rows_affected': 5,
3286
+ * 'query.duration_ms': 15.7
3287
+ * });
3288
+ * ```
3289
+ */
3290
+ setAttributes(attributes: IOTelAttributes): this;
3291
+ /**
3292
+ * The {@link IAttributeContainer | attribute container} associated with this span, providing
3293
+ * advanced attribute management capabilities. Rather than using the {@link IReadableSpan#attributes}
3294
+ * directly which returns a readonly {@link IOTelAttributes} map that is a snapshot of the attributes at
3295
+ * the time of access, the attribute container offers methods to get, set, delete, and iterate over attributes
3296
+ * with fine-grained control.
3297
+ * It is recommended that you only access the {@link IReadableSpan#attributes} property sparingly due to the
3298
+ * performance cost of taking a snapshot of all attributes.
3299
+ */
3300
+ readonly attribContainer: IAttributeContainer;
3301
+ /**
3302
+ * Sets the status of the span to indicate the success or failure of the operation.
3303
+ *
3304
+ * The span status provides a standardized way to indicate whether the operation
3305
+ * completed successfully, encountered an error, or is in an unknown state.
3306
+ * This status is used by observability tools to provide meaningful insights
3307
+ * about system health and operation outcomes.
3308
+ *
3309
+ * @param status - The status object containing code and optional message
3310
+ *
3311
+ * @returns This span instance for method chaining
3312
+ *
3313
+ * @remarks
3314
+ * - Default status is UNSET until explicitly set
3315
+ * - Setting status overrides any previous status values
3316
+ * - ERROR status should be accompanied by a descriptive message when possible
3317
+ * - Status should reflect the final outcome of the operation
3318
+ *
3319
+ * @example
3320
+ * ```typescript
3321
+ * const span = tracer.startSpan('payment-processing');
3322
+ *
3323
+ * try {
3324
+ * const result = await processPayment(paymentData);
3325
+ *
3326
+ * // Indicate successful completion
3327
+ * span.setStatus({
3328
+ * code: SpanStatusCode.OK
3329
+ * });
3330
+ *
3331
+ * } catch (error) {
3332
+ * // Indicate operation failed
3333
+ * span.setStatus({
3334
+ * code: SpanStatusCode.ERROR,
3335
+ * message: 'Payment processing failed: ' + error.message
3336
+ * });
3337
+ *
3338
+ * span.recordException(error);
3339
+ * }
3340
+ * ```
3341
+ */
3342
+ setStatus(status: IOTelSpanStatus): this;
3343
+ /**
3344
+ * Updates the name of the span, overriding the name provided during creation.
3345
+ *
3346
+ * Span names should be descriptive and represent the operation being performed.
3347
+ * Updating the name can be useful when the operation's scope becomes clearer
3348
+ * during execution, or when implementing generic spans that need specific naming
3349
+ * based on runtime conditions.
3350
+ *
3351
+ * @param name - The new name for the span, should be descriptive of the operation
3352
+ *
3353
+ * @returns This span instance for method chaining
3354
+ *
3355
+ * @remarks
3356
+ * - Name updates may affect sampling behavior depending on implementation
3357
+ * - Choose names that are meaningful but not too specific to avoid cardinality issues
3358
+ * - Follow naming conventions consistent with your observability strategy
3359
+ * - Consider the impact on existing traces and dashboards when changing names
3360
+ *
3361
+ * @example
3362
+ * ```typescript
3363
+ * const span = tracer.startSpan('generic-operation');
3364
+ *
3365
+ * // Update name based on runtime determination
3366
+ * if (operationType === 'user-registration') {
3367
+ * span.updateName('user-registration');
3368
+ * span.setAttribute('operation.type', 'registration');
3369
+ * } else if (operationType === 'user-login') {
3370
+ * span.updateName('user-authentication');
3371
+ * span.setAttribute('operation.type', 'authentication');
3372
+ * }
3373
+ * ```
3374
+ */
3375
+ updateName(name: string): this;
3376
+ /**
3377
+ * Marks the end of the span's execution and records the end timestamp.
3378
+ *
3379
+ * This method finalizes the span and makes it available for export to tracing systems.
3380
+ * Once ended, the span should not be used for further operations. The span's duration
3381
+ * is calculated from its start time to the end time provided or current time.
3382
+ *
3383
+ * @param endTime - Optional end time; if not provided, current time is used
3384
+ *
3385
+ * @remarks
3386
+ * - This method does NOT return `this` to discourage chaining after span completion
3387
+ * - Ending a span has no effect on child spans, which may continue running
3388
+ * - Child spans can be ended independently after their parent has ended
3389
+ * - The span becomes eligible for export once ended
3390
+ * - Calling end() multiple times has no additional effect
3391
+ *
3392
+ * @example
3393
+ * ```typescript
3394
+ * const span = tracer.startSpan('file-processing');
3395
+ *
3396
+ * try {
3397
+ * // Perform the operation
3398
+ * const result = await processFile(filePath);
3399
+ *
3400
+ * // Record success
3401
+ * span.setStatus({ code: SpanStatusCode.OK });
3402
+ * span.setAttribute('file.size', result.size);
3403
+ *
3404
+ * } catch (error) {
3405
+ * span.recordException(error);
3406
+ * span.setStatus({
3407
+ * code: SpanStatusCode.ERROR,
3408
+ * message: error.message
3409
+ * });
3410
+ * } finally {
3411
+ * // Always end the span
3412
+ * span.end();
3413
+ * // Don't use span after this point
3414
+ * }
3415
+ *
3416
+ * // Custom end time example
3417
+ * const customEndTime = Date.now() * 1000000; // nanoseconds
3418
+ * span.end(customEndTime);
3419
+ * ```
3420
+ */
3421
+ end(endTime?: OTelTimeInput): void;
3422
+ /**
3423
+ * Returns whether this span is actively recording information.
3424
+ *
3425
+ * A recording span accepts and stores attributes, events, status, and other span data.
3426
+ * Non-recording spans (typically due to sampling decisions) may ignore operations
3427
+ * like setAttribute() to optimize performance. This method allows conditional
3428
+ * logic to avoid expensive operations on non-recording spans.
3429
+ *
3430
+ * @returns True if the span is actively recording information, false otherwise
3431
+ *
3432
+ * @remarks
3433
+ * - Recording status is typically determined at span creation time
3434
+ * - Non-recording spans still provide valid span context for propagation
3435
+ * - Use this check to avoid expensive attribute calculations for non-recording spans
3436
+ * - Recording status remains constant throughout the span's lifetime
3437
+ *
3438
+ * @example
3439
+ * ```typescript
3440
+ * const span = tracer.startSpan('data-processing');
3441
+ *
3442
+ * // Only perform expensive operations if span is recording
3443
+ * if (span.isRecording()) {
3444
+ * const metadata = await expensiveMetadataCalculation();
3445
+ * span.setAttributes({
3446
+ * 'process.metadata': JSON.stringify(metadata),
3447
+ * 'process.complexity': metadata.complexity,
3448
+ * 'process.estimated_duration': metadata.estimatedMs
3449
+ * });
3450
+ * }
3451
+ *
3452
+ * // Always safe to set basic attributes
3453
+ * span.setAttribute('process.started', true);
3454
+ * ```
3455
+ */
3456
+ isRecording(): boolean;
3457
+ /**
3458
+ * Records an exception as a span event with automatic error status handling.
3459
+ *
3460
+ * This method captures exception information and automatically creates a span event
3461
+ * with standardized exception attributes. It's the recommended way to handle errors
3462
+ * within spans, providing consistent error reporting across the application.
3463
+ *
3464
+ * @param exception - The exception to record; accepts string messages or Error objects
3465
+ * @param time - Optional timestamp for when the exception occurred; defaults to current time
3466
+ *
3467
+ * @remarks
3468
+ * - Automatically extracts exception type, message, and stack trace when available
3469
+ * - Creates a standardized span event with exception details
3470
+ * - Does NOT automatically set span status to ERROR - call setStatus() explicitly if needed
3471
+ * - Exception events are useful for debugging and error analysis
3472
+ *
3473
+ * @example
3474
+ * ```typescript
3475
+ * const span = tracer.startSpan('risky-operation');
3476
+ *
3477
+ * try {
3478
+ * await performRiskyOperation();
3479
+ * span.setStatus({ code: SpanStatusCode.OK });
3480
+ *
3481
+ * } catch (error) {
3482
+ * // Record the exception details
3483
+ * span.recordException(error);
3484
+ *
3485
+ * // Explicitly set error status
3486
+ * span.setStatus({
3487
+ * code: SpanStatusCode.ERROR,
3488
+ * message: 'Operation failed due to: ' + error.message
3489
+ * });
3490
+ *
3491
+ * // Re-throw if needed
3492
+ * throw error;
3493
+ * } finally {
3494
+ * span.end();
3495
+ * }
3496
+ *
3497
+ * // Recording string exceptions
3498
+ * span.recordException('Custom error message occurred');
3499
+ *
3500
+ * // Recording with custom timestamp
3501
+ * const errorTime = Date.now() * 1000000; // nanoseconds
3502
+ * span.recordException(error, errorTime);
3503
+ * ```
3504
+ */
3505
+ recordException(exception: OTelException, time?: OTelTimeInput): void;
3506
+ }
3507
+
3508
+ /**
3509
+ * A SpanContext represents the portion of a {@link IOTelSpan} which must be
3510
+ * serialized and propagated along side of a {@link IOTelBaggage}.
3511
+ */
3512
+ interface IOTelSpanContext extends IDistributedTraceInit {
3513
+ /**
3514
+ * Trace flags to propagate.
3515
+ *
3516
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
3517
+ * sampled or not. When set, the least significant bit documents that the
3518
+ * caller may have recorded trace data. A caller who does not record trace
3519
+ * data out-of-band leaves this flag unset.
3520
+ *
3521
+ * see {@link eW3CTraceFlags} for valid flag values.
3522
+ */
3523
+ traceFlags: number;
3524
+ }
3525
+
3526
+ /**
3527
+ * Provides an OpenTelemetry like Interface for the Open Telemetry Api (1.9.0) SpanOptions
3528
+ * type. Where SpanOptions are options that can be used to configure a span.
3529
+ */
3530
+ interface IOTelSpanOptions {
3531
+ /**
3532
+ * The SpanKind of a span of this span, this is used to specify
3533
+ * the relationship between the span and its parent span.
3534
+ * @see {@link eOTelSpanKind} for possible values.
3535
+ * @default eOTelSpanKind.INTERNAL
3536
+ */
3537
+ kind?: OTelSpanKind;
3538
+ /**
3539
+ * A span's attributes
3540
+ */
3541
+ attributes?: IOTelAttributes;
3542
+ /** A manually specified start time for the created `Span` object. */
3543
+ startTime?: OTelTimeInput;
3544
+ /** The new span should be a root span. (Ignore parent from context). */
3545
+ root?: boolean;
3546
+ /** Specify whether the span should be a recording span, default is true */
3547
+ recording?: boolean;
3548
+ }
3549
+
3550
+ interface IOTelSpanStatus {
3551
+ /**
3552
+ * The status code of this message.
3553
+ */
3554
+ code: eOTelSpanStatusCode;
3555
+ /**
3556
+ * A developer-facing error message.
3557
+ */
3558
+ message?: string;
3559
+ }
3560
+
3561
+ /**
3562
+ * OpenTelemetry tracer interface for creating and managing spans within a trace.
3563
+ *
3564
+ * A tracer is responsible for creating spans that represent units of work within a distributed system.
3565
+ * Each tracer is typically associated with a specific instrumentation library or component,
3566
+ * allowing for fine-grained control over how different parts of an application generate telemetry.
3567
+ *
3568
+ * @example
3569
+ * ```typescript
3570
+ * // Get a tracer instance
3571
+ * const tracer = otelApi.getTracer('my-service');
3572
+ *
3573
+ * // Create a simple span
3574
+ * const span = tracer.startSpan('database-query');
3575
+ * span.setAttribute('db.operation', 'SELECT');
3576
+ * span.end();
3577
+ *
3578
+ * // Create an active span with automatic context management
3579
+ * tracer.startActiveSpan('process-request', (span) => {
3580
+ * span.setAttribute('request.id', '12345');
3581
+ *
3582
+ * // Any spans created within this block will be children of this span
3583
+ * processRequest();
3584
+ *
3585
+ * span.end();
3586
+ * });
3587
+ * ```
3588
+ *
3589
+ * @see {@link IReadableSpan} - Interface for individual spans
3590
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
3591
+ *
3592
+ * @since 3.4.0
3593
+ */
3594
+ interface IOTelTracer {
3595
+ /**
3596
+ * Creates and starts a new span without setting it as the active span in the current context.
3597
+ *
3598
+ * This method creates a span but does NOT modify the current execution context.
3599
+ * The caller is responsible for managing the span's lifecycle, including calling `end()`
3600
+ * when the operation completes.
3601
+ *
3602
+ * @param name - The name of the span, should be descriptive of the operation being traced
3603
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
3604
+ *
3605
+ * @returns The newly created span, or null if span creation failed
3606
+ *
3607
+ * @remarks
3608
+ * - The returned span must be manually ended by calling `span.end()`
3609
+ * - This span will not automatically become the parent for spans created in nested operations
3610
+ * - Use `startActiveSpan` if you want automatic context management
3611
+ *
3612
+ * @example
3613
+ * ```typescript
3614
+ * const span = tracer.startSpan('database-operation');
3615
+ * if (span) {
3616
+ * try {
3617
+ * span.setAttribute('db.table', 'users');
3618
+ * span.setAttribute('db.operation', 'SELECT');
3619
+ *
3620
+ * // Perform database operation
3621
+ * const result = await db.query('SELECT * FROM users');
3622
+ *
3623
+ * span.setAttributes({
3624
+ * 'db.rows_affected': result.length,
3625
+ * 'operation.success': true
3626
+ * });
3627
+ * } catch (error) {
3628
+ * span.setStatus({
3629
+ * code: SpanStatusCode.ERROR,
3630
+ * message: error.message
3631
+ * });
3632
+ * span.recordException(error);
3633
+ * } finally {
3634
+ * span.end(); // Always end the span
3635
+ * }
3636
+ * }
3637
+ * ```
3638
+ */
3639
+ startSpan(name: string, options?: IOTelSpanOptions): IReadableSpan | null;
3640
+ /**
3641
+ * Creates and starts a new span, sets it as the active span in the current context,
3642
+ * and executes a provided function within this context.
3643
+ *
3644
+ * This method creates a span, makes it active during the execution of the provided
3645
+ * function, and automatically ends the span when the function completes (or throws).
3646
+ * This provides automatic span lifecycle management and context propagation.
3647
+ *
3648
+ * @param name - The name of the span, should be descriptive of the operation being traced
3649
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
3650
+ * @param fn - The function to execute within the span's active context
3651
+ *
3652
+ * @returns The result of executing the provided function
3653
+ *
3654
+ * @remarks
3655
+ * - The span is automatically ended when the function completes or throws an exception
3656
+ * - The span becomes the active parent for any spans created within the function
3657
+ * - If the function throws an error, the span status is automatically set to ERROR
3658
+ * - This is the recommended method for most tracing scenarios due to automatic lifecycle management
3659
+ * - Multiple overloads available for different parameter combinations
3660
+ *
3661
+ * @example
3662
+ * ```typescript
3663
+ * // Synchronous operation with just name and function
3664
+ * const result = tracer.startActiveSpan('user-service', (span) => {
3665
+ * span.setAttribute('operation', 'get-user-details');
3666
+ * return { user: getUserData(), timestamp: new Date().toISOString() };
3667
+ * });
3668
+ *
3669
+ * // With options
3670
+ * const result2 = tracer.startActiveSpan('database-query',
3671
+ * { attributes: { 'db.table': 'users' } },
3672
+ * (span) => {
3673
+ * span.setAttribute('db.operation', 'SELECT');
3674
+ * return database.getUser('123');
3675
+ * }
3676
+ * );
3677
+ *
3678
+ * // With full context control
3679
+ * const result3 = tracer.startActiveSpan('external-api',
3680
+ * { attributes: { 'service.name': 'payment-api' } },
3681
+ * currentContext,
3682
+ * async (span) => {
3683
+ * try {
3684
+ * const response = await fetch('/api/payment');
3685
+ * span.setAttributes({
3686
+ * 'http.status_code': response.status,
3687
+ * 'operation.success': response.ok
3688
+ * });
3689
+ * return response.json();
3690
+ * } catch (error) {
3691
+ * span.setAttribute('error.type', error.constructor.name);
3692
+ * throw error; // Error automatically recorded
3693
+ * }
3694
+ * }
3695
+ * );
3696
+ * ```
3697
+ */
3698
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, fn: F): ReturnType<F>;
3699
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, options: IOTelSpanOptions, fn: F): ReturnType<F>;
3700
+ }
3701
+
3702
+ interface IOTelTracerOptions {
3703
+ /**
3704
+ * The schemaUrl of the tracer or instrumentation library
3705
+ */
3706
+ schemaUrl?: string;
3707
+ }
3708
+
3709
+ /**
3710
+ * OpenTelemetry Trace API for getting tracers.
3711
+ * This provides the standard OpenTelemetry trace API entry point.
3712
+ */
3713
+ interface IOTelTracerProvider {
3714
+ /**
3715
+ * Returns a Tracer, creating one if one with the given name and version is
3716
+ * not already created. This may return
3717
+ * - The same Tracer instance if one has already been created with the same name and version
3718
+ * - A new Tracer instance if one has not already been created with the same name and version
3719
+ * - A non-operational Tracer if the provider is not operational
3720
+ *
3721
+ * @param name - The name of the tracer or instrumentation library.
3722
+ * @param version - The version of the tracer or instrumentation library.
3723
+ * @param options - The options of the tracer or instrumentation library.
3724
+ * @returns Tracer A Tracer with the given name and version
3725
+ */
3726
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
3727
+ /**
3728
+ * Forces the tracer provider to flush any buffered data.
3729
+ * @returns A promise that resolves when the flush is complete.
3730
+ */
3731
+ forceFlush?: () => IPromise<void> | void;
3732
+ /**
3733
+ * Shuts down the tracer provider and releases any resources.
3734
+ * @returns A promise that resolves when the shutdown is complete.
3735
+ */
3736
+ shutdown?: () => IPromise<void> | void;
3737
+ }
3738
+
3739
+ /**
3740
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Api (1.9.0) TraceState type.
3741
+ *
3742
+ * The TraceState is a list of key/value pairs that are used to propagate
3743
+ * vendor-specific trace information across different distributed tracing systems.
3744
+ * The TraceState is used to store the state of a trace across different
3745
+ * distributed tracing systems, and it is used to ensure that the trace information
3746
+ * is consistent across different systems.
3747
+ *
3748
+ * Instances of TraceState are immutable, and the methods on this interface
3749
+ * return a new instance of TraceState with the updated values.
3750
+ */
3751
+ interface IOTelTraceState {
3752
+ /**
3753
+ * Create a new TraceState which inherits from this TraceState and has the
3754
+ * given key set.
3755
+ * The new entry will always be added in the front of the list of states.
3756
+ *
3757
+ * @param key - key of the TraceState entry.
3758
+ * @param value - value of the TraceState entry.
3759
+ */
3760
+ set(key: string, value: string): IOTelTraceState;
3761
+ /**
3762
+ * Return a new TraceState which inherits from this TraceState but does not
3763
+ * contain the given key.
3764
+ *
3765
+ * @param key - the key for the TraceState entry to be removed.
3766
+ */
3767
+ unset(key: string): IOTelTraceState;
3768
+ /**
3769
+ * Returns the value to which the specified key is mapped, or `undefined` if
3770
+ * this map contains no mapping for the key.
3771
+ *
3772
+ * @param key - with which the specified value is to be associated.
3773
+ * @returns the value to which the specified key is mapped, or `undefined` if
3774
+ * this map contains no mapping for the key.
3775
+ */
3776
+ get(key: string): string | undefined;
3777
+ /**
3778
+ * Serializes the TraceState to a `list` as defined below. The `list` is a series of `list-members`
3779
+ * separated by commas `,`, and a list-member is a key/value pair separated by an equals sign `=`.
3780
+ * Spaces and horizontal tabs surrounding `list-members` are ignored. There can be a maximum of 32
3781
+ * `list-members` in a `list`.
3782
+ *
3783
+ * If the resulting serialization is limited to no longer than 512 bytes, if the combination of
3784
+ * keys and values exceeds this limit, the serialization will be truncated to the last key/value pair
3785
+ * that fits within the limit. The serialization will be returned as a string.
3786
+ *
3787
+ * This is different from the {@link IW3cTraceState} serialization which returns an array of strings where each
3788
+ * string is limited to 512 bytes and the array is limited to 32 strings. Thus the OpenTelemetry serialization
3789
+ * will only return the first single string that fits within the limie.
3790
+ *
3791
+ * @returns the serialized string.
3792
+ */
3793
+ serialize(): string;
3794
+ }
3795
+
3796
+ interface IPageViewPerformanceTelemetry extends IPartC {
3797
+ /**
3798
+ * name String - The name of the page. Defaults to the document title.
3799
+ */
3800
+ name?: string;
2088
3801
  /**
2089
3802
  * url String - a relative or absolute URL that identifies the page or other item. Defaults to the window location.
2090
3803
  */
@@ -2612,6 +4325,44 @@ declare namespace ApplicationInsights {
2612
4325
  finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
2613
4326
  }
2614
4327
 
4328
+ /**
4329
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Sdk-Trace-Base (1.8.0 and 2.0.0) ReadableSpan type.
4330
+ *
4331
+ * The IReadableSpan interface is used to represent a span that can be read and exported, while the OpenTelemetry
4332
+ * specification defines a ReadableSpan as a Span that has been ended and is ready to be exported. By default all
4333
+ * spans created by this library implement the IReadableSpan interface which also extends the {@link IOTelSpan} interface.
4334
+ *
4335
+ * This interface is defined to provide compatibility with exporters defined by the OpenTelemetry Trace SDK.
4336
+ * @since 3.4.0
4337
+ */
4338
+ interface IReadableSpan extends IOTelSpan {
4339
+ /**
4340
+ * The span's unique identifier.
4341
+ */
4342
+ readonly name: string;
4343
+ /**
4344
+ * Identifies the type (or kind) that this span is representing.
4345
+ */
4346
+ readonly kind: OTelSpanKind;
4347
+ readonly spanContext: () => IDistributedTraceContext;
4348
+ readonly parentSpanId?: string;
4349
+ readonly parentSpanContext?: IDistributedTraceContext;
4350
+ readonly startTime: IOTelHrTime;
4351
+ readonly endTime: IOTelHrTime;
4352
+ readonly status: IOTelSpanStatus;
4353
+ /**
4354
+ * Provides a snapshot of the span's attributes at the time this span was ended.
4355
+ * @returns A read-only snapshot of the span's attributes
4356
+ * @remarks
4357
+ * It is recommended that you only access this property sparingly due to the
4358
+ * performance cost of taking a snapshot of all attributes.
4359
+ */
4360
+ readonly attributes: IOTelAttributes;
4361
+ readonly duration: IOTelHrTime;
4362
+ readonly ended: boolean;
4363
+ readonly droppedAttributesCount: number;
4364
+ }
4365
+
2615
4366
  interface IRequestContext {
2616
4367
  status?: number;
2617
4368
  xhr?: XMLHttpRequest;
@@ -2619,6 +4370,35 @@ declare namespace ApplicationInsights {
2619
4370
  response?: Response | string;
2620
4371
  }
2621
4372
 
4373
+ /**
4374
+ * Represents the execution scope for a span, combining the trace instance and the active span.
4375
+ * This interface is used as the context for executing functions within a span's scope.
4376
+ *
4377
+ * @since 3.4.0
4378
+ */
4379
+ interface ISpanScope<T extends ITraceHost = ITraceHost> {
4380
+ /**
4381
+ * The trace host (core or AISKU instance).
4382
+ * @since 3.4.0
4383
+ */
4384
+ readonly host: T;
4385
+ /**
4386
+ * The active span for this execution scope.
4387
+ * @since 3.4.0
4388
+ */
4389
+ readonly span: IReadableSpan;
4390
+ /**
4391
+ * The previously active span before this scope was created, if any.
4392
+ * @since 3.4.0
4393
+ */
4394
+ readonly prvSpan?: IReadableSpan;
4395
+ /**
4396
+ * Restores the previous active span in the trace instance.
4397
+ * @since 3.4.0
4398
+ */
4399
+ restore(): void;
4400
+ }
4401
+
2622
4402
  interface IStackDetails {
2623
4403
  src: string;
2624
4404
  obj: string[];
@@ -2962,6 +4742,205 @@ declare namespace ApplicationInsights {
2962
4742
  enabled: boolean;
2963
4743
  }
2964
4744
 
4745
+ /**
4746
+ * ITraceApi provides an interface definition which is simular to the OpenTelemetry TraceAPI
4747
+ */
4748
+ interface ITraceApi {
4749
+ /**
4750
+ * Returns a Tracer, creating one if one with the given name and version
4751
+ * if one has not already created.
4752
+ *
4753
+ * @param name - The name of the tracer or instrumentation library.
4754
+ * @param version - The version of the tracer or instrumentation library.
4755
+ * @param options - The options of the tracer or instrumentation library.
4756
+ * @returns Tracer A Tracer with the given name and version
4757
+ */
4758
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
4759
+ /**
4760
+ * Wrap the given {@link IDistributedTraceContext} in a new non-recording {@link IReadableSpan}
4761
+ *
4762
+ * @param spanContext - The {@link IDistributedTraceContext} to be wrapped
4763
+ * @returns a new non-recording {@link IReadableSpan} with the provided context
4764
+ */
4765
+ wrapSpanContext(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): IReadableSpan;
4766
+ /**
4767
+ * Returns true if this {@link IDistributedTraceContext} is valid.
4768
+ * @return true if this {@link IDistributedTraceContext} is valid.
4769
+ */
4770
+ isSpanContextValid(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): boolean;
4771
+ /**
4772
+ * Gets the span from the current context, if one exists.
4773
+ */
4774
+ getActiveSpan(): IReadableSpan | undefined | null;
4775
+ /**
4776
+ * Set or clear the current active span.
4777
+ * @param span - The span to set as the active span, or null/undefined to clear the active span.
4778
+ * @return An ISpanScope instance returned by the host, or void if there is no defined host.
4779
+ */
4780
+ setActiveSpan(span: IReadableSpan | undefined | null): ISpanScope | undefined | null;
4781
+ }
4782
+
4783
+ /**
4784
+ * Configuration interface for OpenTelemetry compatible tracing functionality.
4785
+ * This interface contains all the settings that control how traces are created,
4786
+ * processed, and managed within the OpenTelemetry system.
4787
+ *
4788
+ * @example
4789
+ * ```typescript
4790
+ * const traceCfg: ITraceCfg = {
4791
+ * serviceName: "my-service",
4792
+ * generalLimits: {
4793
+ * attributeCountLimit: 128,
4794
+ * attributeValueLengthLimit: 4096
4795
+ * },
4796
+ * spanLimits: {
4797
+ * attributeCountLimit: 128,
4798
+ * linkCountLimit: 128,
4799
+ * eventCountLimit: 128
4800
+ * }
4801
+ * };
4802
+ * ```
4803
+ *
4804
+ * @since 3.4.0
4805
+ */
4806
+ interface ITraceCfg {
4807
+ /**
4808
+ * Global attribute limits that apply to all telemetry items.
4809
+ * These limits help prevent excessive memory usage and ensure consistent
4810
+ * behavior across different telemetry types.
4811
+ *
4812
+ * @remarks
4813
+ * These limits are inherited by more specific configurations unless overridden.
4814
+ * For example, spans will use these limits unless `spanLimits` specifies different values.
4815
+ */
4816
+ generalLimits?: IOTelAttributeLimits;
4817
+ /**
4818
+ * The name of the service generating telemetry data.
4819
+ * This name will be included in all telemetry items as a resource attribute.
4820
+ *
4821
+ * @remarks
4822
+ * The service name is crucial for identifying and filtering telemetry data
4823
+ * in observability systems. It should be consistent across all instances
4824
+ * of the same service.
4825
+ *
4826
+ * @example
4827
+ * ```typescript
4828
+ * serviceName: "user-authentication-service"
4829
+ * ```
4830
+ */
4831
+ serviceName?: string;
4832
+ /**
4833
+ * A flag that indicates whether the tracing (creating of a "trace" event) should be suppressed
4834
+ * when a {@link IOTelSpan} ends and the span {@link IOTelSpan#isRecording | isRecording} is true.
4835
+ * This value is also inherited by spans when they are created.
4836
+ */
4837
+ suppressTracing?: boolean;
4838
+ }
4839
+
4840
+ /**
4841
+ * Interface for OpenTelemetry trace operations.
4842
+ * This interface provides span creation, context management, and trace provider operations
4843
+ * that are common across different SDK implementations (Core, AISKU, etc.).
4844
+ *
4845
+ * @since 3.4.0
4846
+ */
4847
+ interface ITraceHost<CfgType extends IConfiguration = IConfiguration> {
4848
+ readonly config: CfgType;
4849
+ /**
4850
+ * Gets the current distributed trace active context for this instance
4851
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true. By default this
4852
+ * will use any located parent as defined by the {@link IConfiguration.traceHdrMode} configuration for each new instance created.
4853
+ */
4854
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
4855
+ /**
4856
+ * Sets the current distributed trace context for this instance if available
4857
+ */
4858
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
4859
+ /**
4860
+ * Start a new span with the given name and optional parent context.
4861
+ *
4862
+ * Note: This method only creates and returns the span. It does not automatically
4863
+ * set the span as the active trace context. Context management should be handled
4864
+ * separately using setTraceCtx() if needed.
4865
+ *
4866
+ * @param name - The name of the span
4867
+ * @param options - Options for creating the span (kind, attributes, startTime)
4868
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
4869
+ * @returns A new span instance, or null if no trace provider is available
4870
+ * @since 3.4.0
4871
+ *
4872
+ * @see {@link IReadableSpan} - Interface for individual spans
4873
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
4874
+ */
4875
+ startSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan | null;
4876
+ /**
4877
+ * Return the current active span, if no trace provider is available null will be returned
4878
+ * but when a trace provider is available a span instance will always be returned, even if
4879
+ * there is no active span (in which case a non-recording span will be returned).
4880
+ * @param createNew - Optional flag to create a non-recording span if no active span exists, defaults to true.
4881
+ * When false, returns the existing active span or null without creating a non-recording span, which can improve
4882
+ * performance when only checking if an active span exists.
4883
+ * @returns The current active span or null if no trace provider is available or if createNew is false and no active span exists
4884
+ * @since 3.4.0
4885
+ */
4886
+ getActiveSpan(createNew?: boolean): IReadableSpan | null;
4887
+ /**
4888
+ * Set the current Active Span, if no trace provider is available the span will be not be set as the active span.
4889
+ * @param span - The span to set as the active span
4890
+ * @returns An ISpanScope instance that provides the current scope, the span will always be the span passed in
4891
+ * even when no trace provider is available
4892
+ * @since 3.4.0
4893
+ */
4894
+ setActiveSpan(span: IReadableSpan): ISpanScope;
4895
+ /**
4896
+ * Get the current trace provider.
4897
+ *
4898
+ * @returns The current trace provider, or null if none is set
4899
+ * @since 3.4.0
4900
+ */
4901
+ getTraceProvider(): ITraceProvider | null;
4902
+ }
4903
+
4904
+ /**
4905
+ * A trace provider interface that enables different SKUs to provide their own
4906
+ * span implementations while being managed by the core SDK.
4907
+ *
4908
+ * This follows the OpenTelemetry TraceProvider pattern, allowing the core to
4909
+ * delegate span creation to the appropriate implementation based on the SDK variant.
4910
+ *
4911
+ * @since 3.4.0
4912
+ */
4913
+ interface ITraceProvider {
4914
+ /**
4915
+ * The OpenTelemetry API instance associated with this trace provider.
4916
+ * This provides access to the tracer provider and other OpenTelemetry functionality.
4917
+ * @since 3.4.0
4918
+ */
4919
+ readonly api: IOTelApi;
4920
+ /**
4921
+ * Creates a new span with the given name and options.
4922
+ *
4923
+ * @param name - The name of the span
4924
+ * @param options - Options for creating the span (kind, attributes, startTime)
4925
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
4926
+ * @returns A new span instance specific to this provider's implementation
4927
+ * @since 3.4.0
4928
+ */
4929
+ createSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan;
4930
+ /**
4931
+ * Gets the provider identifier for debugging and logging purposes.
4932
+ * @returns A string identifying this trace provider implementation
4933
+ * @since 3.4.0
4934
+ */
4935
+ getProviderId(): string;
4936
+ /**
4937
+ * Determines if this provider is available and ready to create spans.
4938
+ * @returns true if the provider can create spans, false otherwise
4939
+ * @since 3.4.0
4940
+ */
4941
+ isAvailable(): boolean;
4942
+ }
4943
+
2965
4944
  interface ITraceTelemetry extends IPartC {
2966
4945
  /**
2967
4946
  * @description A message string
@@ -2996,6 +4975,76 @@ declare namespace ApplicationInsights {
2996
4975
  run: (logger?: IDiagnosticLogger) => void;
2997
4976
  }
2998
4977
 
4978
+ /**
4979
+ * Represents a mutable [W3C trace state list](https://www.w3.org/TR/trace-context/#tracestate-header), this is a
4980
+ * list of key/value pairs that are used to pass trace state information between different tracing systems. The
4981
+ * list is ordered and the order is important as it determines the processing order.
4982
+ *
4983
+ * Importantly instances of this type are mutable, change made to an instance via {@link IW3cTraceState.set} or
4984
+ * {@link IW3cTraceState.del} will be reflected on the instance and any child instances that use it as a parent.
4985
+ * However, any parent instance associated with an instance will not be modified by operations on that particular
4986
+ * instance.
4987
+ *
4988
+ * @since 3.4.0
4989
+ */
4990
+ interface IW3cTraceState {
4991
+ /**
4992
+ * Returns a readonly array of the current keys associated with the trace state, keys are returned in the
4993
+ * required processing order and if this instance has a parent the keys from the parent will be included
4994
+ * unless they have been removed (deleted) from the child instance.
4995
+ * Once created any modifications to the parent will also be reflected in the child, this is different from
4996
+ * the OpenTelemetry implementation which creates a new instance for each call.
4997
+ * @returns A readonly array of the current keys associated with the trace state
4998
+ */
4999
+ readonly keys: string[];
5000
+ /**
5001
+ * Check if the trace state list is empty, meaning it has no keys or values.
5002
+ * This exists to allow for quick checks without needing to create a new array of keys.
5003
+ * @since 3.4.0
5004
+ * @returns true if the trace state list is empty, false otherwise
5005
+ */
5006
+ readonly isEmpty: boolean;
5007
+ /**
5008
+ * Get the value for the specified key that is associated with this instance, either directly or from the parent.
5009
+ * @param key - The key to lookup
5010
+ * @returns The value for the key, or undefined if not found
5011
+ */
5012
+ get(key: string): string | undefined;
5013
+ /**
5014
+ * Set the value for the specified key for this instance, returning its new location within the list.
5015
+ * - 0 is the front of the list
5016
+ * - -1 not set because the key/value pair is invalid
5017
+ * If the key already exists it will be removed from its current location and added to the front of the list. And
5018
+ * if the key was in the parent this will override the value inherited from the parent, more importantly it will
5019
+ * not modify the parent value.
5020
+ * @param key - The key to set
5021
+ * @param value - The value to set
5022
+ * @returns 0 if successful, -1 if not
5023
+ */
5024
+ set(key: string, value: string): number;
5025
+ /**
5026
+ * Delete the specified key from this instance, if the key was in the parent it will be removed (hidden) from
5027
+ * this instance but will still be available directly from the parent.
5028
+ * @param key - The key to delete
5029
+ */
5030
+ del(key: string): void;
5031
+ /**
5032
+ * Format the trace state list into a strings where each string can be used as a header value.
5033
+ * This will return an empty array if the trace state list is empty.
5034
+ * @param maxHeaders - The maximum number of entries to include in the output, once the limit is reached no more entries will be included
5035
+ * @param maxKeys - The maximum number of keys to include in the output, once the limit is reached no more keys will be included
5036
+ * @param maxLen - The maximum length of each header value, once the limit is reached a new header value will be created
5037
+ * @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
5038
+ */
5039
+ hdrs(maxHeaders?: number, maxKeys?: number, maxLen?: number): string[];
5040
+ /**
5041
+ * Create a new instance of IW3cTraceState which is a child of this instance, meaning it will inherit the keys
5042
+ * and values from this instance but any changes made to the child will not affect this instance.
5043
+ * @returns A new instance of IW3cTraceState which is a child of this instance
5044
+ */
5045
+ child(): IW3cTraceState;
5046
+ }
5047
+
2999
5048
  interface IWatchDetails<T = IConfiguration> {
3000
5049
  /**
3001
5050
  * The current config object
@@ -3034,6 +5083,74 @@ declare namespace ApplicationInsights {
3034
5083
 
3035
5084
  type LoggingSeverity = number | eLoggingSeverity;
3036
5085
 
5086
+ /**
5087
+ * Attribute values may be any non-nullish primitive value except an object.
5088
+ *
5089
+ * null or undefined attribute values are invalid and will result in undefined behavior.
5090
+ *
5091
+ * @since 3.4.0
5092
+ */
5093
+ type OTelAttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
5094
+
5095
+ /**
5096
+ * Defines Exception.
5097
+ *
5098
+ * string or an object with one of (message or name or code) and optional stack
5099
+ *
5100
+ * @since 3.4.0
5101
+ */
5102
+ type OTelException = IOTelExceptionWithCode | IOTelExceptionWithMessage | IOTelExceptionWithName | string;
5103
+
5104
+ /**
5105
+ * High-resolution time represented as a tuple of [seconds, nanoseconds].
5106
+ * This is the base type for all OpenTelemetry high-resolution time values.
5107
+ *
5108
+ * @remarks
5109
+ * The first element represents seconds since Unix epoch, and the second element
5110
+ * represents nanoseconds (0-999,999,999) within that second.
5111
+ *
5112
+ * @example
5113
+ * ```typescript
5114
+ * const hrTime: OTelHrTimeBase = [1609459200, 500000000]; // 2021-01-01 00:00:00.5 UTC
5115
+ * ```
5116
+ *
5117
+ * @since 3.4.0
5118
+ */
5119
+ type OTelHrTimeBase = [number, number];
5120
+
5121
+ /**
5122
+ * Creates an enum style object for the OTelSpanKind enum, providing the enum
5123
+ * values as properties of the object as both string and number types.
5124
+ * This allows for easy access to the enum values in a more readable format.
5125
+ */
5126
+ const OTelSpanKind: EnumValue<typeof eOTelSpanKind>;
5127
+
5128
+ type OTelSpanKind = number | eOTelSpanKind;
5129
+
5130
+ /**
5131
+ * Union type representing all valid time input formats accepted by OpenTelemetry APIs.
5132
+ *
5133
+ * @remarks
5134
+ * - `IOTelHrTime`: High-resolution time with nanosecond precision
5135
+ * - `number`: Milliseconds since Unix epoch (JavaScript Date.now() format)
5136
+ * - `Date`: JavaScript Date object
5137
+ *
5138
+ * @example
5139
+ * ```typescript
5140
+ * // All of these are valid time inputs:
5141
+ * const hrTime: OTelTimeInput = [1609459200, 500000000];
5142
+ * const msTime: OTelTimeInput = Date.now();
5143
+ * const dateTime: OTelTimeInput = new Date();
5144
+ *
5145
+ * span.addEvent("event", {}, hrTime);
5146
+ * span.addEvent("event", {}, msTime);
5147
+ * span.addEvent("event", {}, dateTime);
5148
+ * ```
5149
+ *
5150
+ * @since 3.4.0
5151
+ */
5152
+ type OTelTimeInput = IOTelHrTime | number | Date;
5153
+
3037
5154
  /**
3038
5155
  * This defines the handler function for when a promise is rejected.
3039
5156
  * @param value - This is the value passed as part of resolving the Promise