@microsoft/applicationinsights-debugplugin-js 3.3.12-nightly3.2602-20 → 3.4.0-nightly3.2602-34

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 (53) hide show
  1. package/browser/es5/{ai.dbg.3.3.12-nightly3.2602-20.cjs.js → ai.dbg.3.4.0-nightly3.2602-34.cjs.js} +88 -57
  2. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.cjs.js.map +1 -0
  3. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.cjs.min.js +6 -0
  4. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.cjs.min.js.map +1 -0
  5. package/browser/es5/{ai.dbg.3.3.12-nightly3.2602-20.gbl.js → ai.dbg.3.4.0-nightly3.2602-34.gbl.js} +90 -59
  6. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.gbl.js.map +1 -0
  7. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.gbl.min.js +6 -0
  8. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.gbl.min.js.map +1 -0
  9. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.integrity.json +66 -0
  10. package/browser/es5/{ai.dbg.3.3.12-nightly3.2602-20.js → ai.dbg.3.4.0-nightly3.2602-34.js} +90 -59
  11. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.js.map +1 -0
  12. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.min.js +6 -0
  13. package/browser/es5/ai.dbg.3.4.0-nightly3.2602-34.min.js.map +1 -0
  14. package/browser/es5/ai.dbg.3.cjs.js +87 -56
  15. package/browser/es5/ai.dbg.3.cjs.js.map +1 -1
  16. package/browser/es5/ai.dbg.3.cjs.min.js +2 -2
  17. package/browser/es5/ai.dbg.3.cjs.min.js.map +1 -1
  18. package/browser/es5/ai.dbg.3.gbl.js +89 -58
  19. package/browser/es5/ai.dbg.3.gbl.js.map +1 -1
  20. package/browser/es5/ai.dbg.3.gbl.min.js +2 -2
  21. package/browser/es5/ai.dbg.3.gbl.min.js.map +1 -1
  22. package/browser/es5/ai.dbg.3.integrity.json +25 -25
  23. package/browser/es5/ai.dbg.3.js +89 -58
  24. package/browser/es5/ai.dbg.3.js.map +1 -1
  25. package/browser/es5/ai.dbg.3.min.js +2 -2
  26. package/browser/es5/ai.dbg.3.min.js.map +1 -1
  27. package/dist/es5/applicationinsights-debugplugin-js.js +87 -56
  28. package/dist/es5/applicationinsights-debugplugin-js.js.map +1 -1
  29. package/dist/es5/applicationinsights-debugplugin-js.min.js +2 -2
  30. package/dist/es5/applicationinsights-debugplugin-js.min.js.map +1 -1
  31. package/dist-es5/DebugPlugin.js +1 -1
  32. package/dist-es5/__DynamicConstants.js +1 -1
  33. package/dist-es5/applicationinsights-debugplugin-js.js +1 -1
  34. package/dist-es5/components/Dashboard.js +1 -1
  35. package/dist-es5/components/LogEntry.js +1 -1
  36. package/dist-es5/components/debugBins.js +1 -1
  37. package/dist-es5/components/filterList.js +1 -1
  38. package/dist-es5/components/helpers.js +1 -1
  39. package/dist-es5/components/styleNodeSrc.js +1 -1
  40. package/dist-es5/interfaces/IDebugPluginConfig.js +1 -1
  41. package/package.json +2 -3
  42. package/types/applicationinsights-debugplugin-js.d.ts +1 -1
  43. package/types/applicationinsights-debugplugin-js.namespaced.d.ts +2076 -50
  44. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.cjs.js.map +0 -1
  45. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.cjs.min.js +0 -6
  46. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.cjs.min.js.map +0 -1
  47. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.gbl.js.map +0 -1
  48. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.gbl.min.js +0 -6
  49. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.gbl.min.js.map +0 -1
  50. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.integrity.json +0 -66
  51. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.js.map +0 -1
  52. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.min.js +0 -6
  53. package/browser/es5/ai.dbg.3.3.12-nightly3.2602-20.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft.ApplicationInsights, 3.3.12-nightly3.2602-20
2
+ * Microsoft.ApplicationInsights, 3.4.0-nightly3.2602-34
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -134,6 +134,51 @@ declare namespace ApplicationInsights {
134
134
  PENDING = 3
135
135
  }
136
136
 
137
+ /**
138
+ * Const enum for attribute change operation types
139
+ */
140
+ const enum eAttributeChangeOp {
141
+ /**
142
+ * Clear operation - clearing all attributes
143
+ */
144
+ Clear = 0,
145
+ /**
146
+ * Set operation - setting an attribute value (generic)
147
+ */
148
+ Set = 1,
149
+ /**
150
+ * Add operation - adding a new attribute that didn't exist before
151
+ */
152
+ Add = 2,
153
+ /**
154
+ * Delete operation - deleting an attribute
155
+ */
156
+ Delete = 3,
157
+ /**
158
+ * Dropped attributes - attributes that were dropped due to size limits
159
+ */
160
+ DroppedAttributes = 4
161
+ }
162
+
163
+ /**
164
+ * Identifies the source of an attribute value in iterator operations
165
+ * @since 3.4.0
166
+ */
167
+ const enum eAttributeFilter {
168
+ /**
169
+ * The attribute exists local to the current container instance
170
+ */
171
+ Local = 0,
172
+ /**
173
+ * The attribute does not exist locally and is inherited from a parent container or attributes object
174
+ */
175
+ Inherited = 1,
176
+ /**
177
+ * The attribute exists or has been deleted locally (only) to the current container instance
178
+ */
179
+ LocalOrDeleted = 2
180
+ }
181
+
137
182
  const enum _eInternalMessageId {
138
183
  BrowserDoesNotSupportLocalStorage = 0,
139
184
  BrowserCannotReadLocalStorage = 1,
@@ -226,7 +271,12 @@ declare namespace ApplicationInsights {
226
271
  SdkLdrUpdate = 111,
227
272
  InitPromiseException = 112,
228
273
  StatsBeatManagerException = 113,
229
- StatsBeatException = 114
274
+ StatsBeatException = 114,
275
+ AttributeError = 115,
276
+ SpanError = 116,
277
+ TraceError = 117,
278
+ NotImplementedError = 118,
279
+ VersionMismatch = 119
230
280
  }
231
281
 
232
282
  const enum eLoggingSeverity {
@@ -264,6 +314,81 @@ declare namespace ApplicationInsights {
264
314
 
265
315
  type EnumValue<E = any> = EnumCls<E>;
266
316
 
317
+ /**
318
+ * The defined set of Span Kinds as defined by the OpenTelemetry.
319
+ */
320
+ const enum eOTelSpanKind {
321
+ /** Default value. Indicates that the span is used internally. */
322
+ INTERNAL = 0,
323
+ /**
324
+ * Indicates that the span covers server-side handling of an RPC or other
325
+ * remote request.
326
+ */
327
+ SERVER = 1,
328
+ /**
329
+ * Indicates that the span covers the client-side wrapper around an RPC or
330
+ * other remote request.
331
+ */
332
+ CLIENT = 2,
333
+ /**
334
+ * Indicates that the span describes producer sending a message to a
335
+ * broker. Unlike client and server, there is no direct critical path latency
336
+ * relationship between producer and consumer spans.
337
+ */
338
+ PRODUCER = 3,
339
+ /**
340
+ * Indicates that the span describes consumer receiving a message from a
341
+ * broker. Unlike client and server, there is no direct critical path latency
342
+ * relationship between producer and consumer spans.
343
+ */
344
+ CONSUMER = 4
345
+ }
346
+
347
+ /**
348
+ * An enumeration of status codes, matching the OpenTelemetry specification.
349
+ *
350
+ * @since 3.4.0
351
+ */
352
+ const enum eOTelSpanStatusCode {
353
+ /**
354
+ * The default status.
355
+ */
356
+ UNSET = 0,
357
+ /**
358
+ * The operation has been validated by an Application developer or
359
+ * Operator to have completed successfully.
360
+ */
361
+ OK = 1,
362
+ /**
363
+ * The operation contains an error.
364
+ */
365
+ ERROR = 2
366
+ }
367
+
368
+ /**
369
+ * Controls how the SDK should look for trace headers (traceparent/tracestate) from the initial page load
370
+ * The values are bitwise OR'd together to allow for multiple values to be set at once.
371
+ * @since 3.4.0
372
+ */
373
+ const enum eTraceHeadersMode {
374
+ /**
375
+ * Don't look for any trace headers
376
+ */
377
+ None = 0,
378
+ /**
379
+ * Look for traceparent header/meta tag
380
+ */
381
+ TraceParent = 1,
382
+ /**
383
+ * Look for tracestate header/meta tag
384
+ */
385
+ TraceState = 2,
386
+ /**
387
+ * Look for both traceparent and tracestate headers/meta tags
388
+ */
389
+ All = 3
390
+ }
391
+
267
392
  const enum FeatureOptInMode {
268
393
  /**
269
394
  * not set, completely depends on cdn cfg
@@ -284,8 +409,7 @@ declare namespace ApplicationInsights {
284
409
  */
285
410
  type FinallyPromiseHandler = (() => void) | undefined | null;
286
411
 
287
- interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
288
- readonly config: CfgType;
412
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider, ITraceHost<CfgType> {
289
413
  /**
290
414
  * The current logger instance for this instance.
291
415
  */
@@ -406,14 +530,13 @@ declare namespace ApplicationInsights {
406
530
  */
407
531
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
408
532
  /**
409
- * Gets the current distributed trace context for this instance if available
410
- * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
411
- */
412
- getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
413
- /**
414
- * Sets the current distributed trace context for this instance if available
533
+ * Set the trace provider for creating spans.
534
+ * This allows different SKUs to provide their own span implementations.
535
+ *
536
+ * @param provider - The trace provider to use for span creation
537
+ * @since 3.4.0
415
538
  */
416
- setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
539
+ setTraceProvider(provider: ICachedValue<ITraceProvider>): void;
417
540
  /**
418
541
  * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
419
542
  * handler will be recalled.
@@ -441,6 +564,150 @@ declare namespace ApplicationInsights {
441
564
  _setPendingStatus?: () => void;
442
565
  }
443
566
 
567
+ /**
568
+ * Information about what changed in an attribute container
569
+ */
570
+ interface IAttributeChangeInfo<V extends OTelAttributeValue = OTelAttributeValue> {
571
+ /**
572
+ * The Id of the container that is initiated the change (not the immediate sender -- which is always the parent)
573
+ * As children only receive listener notifications from their parent in reaction to both changes
574
+ * they make and any changes they receive from their parent
575
+ */
576
+ frm: string;
577
+ /**
578
+ * Operation type that occurred
579
+ */
580
+ op: eAttributeChangeOp;
581
+ /**
582
+ * The key that was changed (only present for 'set' operations)
583
+ */
584
+ k?: string;
585
+ /**
586
+ * The old value (only present for 'set' operations when replacing existing value)
587
+ */
588
+ prev?: V;
589
+ /**
590
+ * The new value (only present for 'set' operations)
591
+ */
592
+ val?: V;
593
+ }
594
+
595
+ /**
596
+ * Interface for an attribute container
597
+ * @since 3.4.0
598
+ */
599
+ interface IAttributeContainer<V extends OTelAttributeValue = OTelAttributeValue> {
600
+ /**
601
+ * Unique identifier for the attribute container
602
+ */
603
+ readonly id: string;
604
+ /**
605
+ * The number of attributes that have been set
606
+ * @returns The number of attributes that have been set
607
+ */
608
+ readonly size: number;
609
+ /**
610
+ * The number of attributes that were dropped due to the attribute limit being reached
611
+ * @returns The number of attributes that were dropped due to the attribute limit being reached
612
+ */
613
+ readonly droppedAttributes: number;
614
+ /**
615
+ * Return a snapshot of the current attributes, including inherited ones.
616
+ * This value is read-only and reflects the state of the attributes at the time of access,
617
+ * and the returned instance will not change if any attributes are modified later, you will need
618
+ * to access the attributes property again to get the latest state.
619
+ *
620
+ * Note: As this causes a snapshot to be taken, it is an expensive operation as it enumerates all
621
+ * attributes, so you SHOULD use this property sparingly.
622
+ * @returns A read-only snapshot of the current attributes
623
+ */
624
+ readonly attributes: IOTelAttributes;
625
+ /**
626
+ * Clear all existing attributes from the container, this will also remove any inherited attributes
627
+ * from this instance only (it will not change the inherited attributes / container(s))
628
+ */
629
+ clear: () => void;
630
+ /**
631
+ * Get the value of an attribute by key
632
+ * @param key - The attribute key to retrieve
633
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
634
+ * @returns The attribute value if found, undefined otherwise
635
+ */
636
+ get: (key: string, source?: eAttributeFilter) => V | undefined;
637
+ /**
638
+ * Check if an attribute exists by key
639
+ * @param key - The attribute key to check
640
+ * @param source - Optional filter to only check attributes from a specific source (Local or Inherited)
641
+ * @returns True if the attribute exists, false otherwise
642
+ */
643
+ has: (key: string, source?: eAttributeFilter) => boolean;
644
+ /**
645
+ * Set the value of an attribute by key on this instance.
646
+ * @param key - The attribute key to set
647
+ * @param value - The value to assign to the named attribute
648
+ * @returns true if the value was successfully set / replaced
649
+ */
650
+ set: (key: string, value: V) => boolean;
651
+ /**
652
+ * Delete an existing attribute, if the key doesn't exist this will return false. If the key does
653
+ * exist then it will be removed from this instance and any inherited value will be hidden (even if
654
+ * the inherited value changes)
655
+ * @param key - The attribute key to delete
656
+ * @returns True if the attribute was deleted, false if it didn't exist (which includes if it has already been deleted)
657
+ */
658
+ del: (key: string) => boolean;
659
+ /**
660
+ * The keys() method returns a new iterator object that contains the existing keys for each element
661
+ * in this attribute container. It will return all locally set keys first and then the inherited keys.
662
+ * When a key exists in both the local and inherited attributes, only the local key will be returned.
663
+ * If the key has been deleted locally, it will not be included in the iterator.
664
+ * @returns An iterator over the keys of the attribute container
665
+ */
666
+ keys: () => Iterator<string>;
667
+ /**
668
+ * The entries() method of returns a new iterator object that contains the [key, value, source?] tuples for
669
+ * each attribute, it returns all existing attributes of this instance including all inherited ones. If the
670
+ * same key exists in both the local and inherited attributes, only the first (non-deleted) tuple will be returned.
671
+ * If the key has been deleted, it will not be included in the iterator.
672
+ *
673
+ * The source value of the tuple identifies the origin of the attribute (Local or Inherited).
674
+ * @returns An iterator over the entries of the attribute container
675
+ */
676
+ entries: () => Iterator<[string, V, eAttributeFilter]>;
677
+ /**
678
+ * The forEach() method of executes a provided function once per each key/value pair in this attribute container,
679
+ * it will process all local attributes first, then the inherited attributes. If the same key exists in both the
680
+ * local and inherited attributes, only the first (non-deleted) key/value pair will be processed.
681
+ * If a key has been deleted, it will not be included in the set of processed key/value pairs.
682
+ * @param callback - The function to execute for each key/value pair
683
+ * @param thisArg - Optional value to use as `this` when executing `callback`
684
+ */
685
+ forEach: (callback: (key: string, value: V, source?: eAttributeFilter) => void, thisArg?: any) => void;
686
+ /**
687
+ * The values() method returns a new iterator instance that contains the values for each element in this
688
+ * attribute container. It will return all locally set values first and then the inherited values. If the
689
+ * same key is present in both the local or inherited attributes only the first (non-deleted) value will be
690
+ * returned. If a key has been deleted, it will not be included in the iterator.
691
+ * @returns An iterator over the values of the attribute container
692
+ */
693
+ values: () => Iterator<V>;
694
+ /**
695
+ * Register a callback listener for any attribute changes, this will include local and inherited changes.
696
+ * @param callback - Function to be called when attributes change, receives change information
697
+ * @returns IUnloadHook instance with rm() function to remove this listener, once called it will never be invoked again
698
+ */
699
+ listen: (callback: (changeInfo: IAttributeChangeInfo<V>) => void) => IUnloadHook;
700
+ /**
701
+ * Create a child attribute container that inherits from this one, optionally taking a snapshot
702
+ * so that any future changes to the parent container do not affect the child container.
703
+ * The child will use all of the configuration from the parent container.
704
+ * @param name - Optional name for the child container
705
+ * @param snapshot - If true, the child container will be a snapshot of the current state
706
+ * @returns A new attribute container instance
707
+ */
708
+ child: (name?: string, snapshot?: boolean) => IAttributeContainer;
709
+ }
710
+
444
711
  interface IBaseProcessingContext {
445
712
  /**
446
713
  * The current core instance for the request
@@ -455,9 +722,12 @@ declare namespace ApplicationInsights {
455
722
  */
456
723
  getCfg: () => IConfiguration;
457
724
  /**
458
- * Gets the named extension config
725
+ * Gets the named extension configuration
726
+ * @param identifier - The named extension identifier
727
+ * @param defaultValue - The default value(s) to return if no defined config exists
728
+ * @param rootOnly - If true, only the look for the configuration in the top level and not in the "extensionConfig"
459
729
  */
460
- getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
730
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>, rootOnly?: boolean) => T;
461
731
  /**
462
732
  * Gets the named config from either the named identifier extension or core config if neither exist then the
463
733
  * default value is returned
@@ -502,6 +772,30 @@ declare namespace ApplicationInsights {
502
772
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
503
773
  }
504
774
 
775
+ /**
776
+ * A generic interface for holding a cached value
777
+ * @since 0.10.5
778
+ * @group Helpers
779
+ * @group Cache
780
+ * @typeParam T - The type of the value to be cached
781
+ * @example
782
+ * ```ts
783
+ * let cachedValue: ICachedValue<string> = {
784
+ * v: "some value"
785
+ * };
786
+ * ```
787
+ */
788
+ interface ICachedValue<T> {
789
+ /**
790
+ * Returns the current cached value
791
+ */
792
+ v: T;
793
+ /**
794
+ * Returns the current cached value
795
+ */
796
+ toJSON(): T;
797
+ }
798
+
505
799
  /**
506
800
  * Provides data transmission capabilities
507
801
  */
@@ -621,7 +915,7 @@ declare namespace ApplicationInsights {
621
915
  /**
622
916
  * Configuration provided to SDK core
623
917
  */
624
- interface IConfiguration {
918
+ interface IConfiguration extends IOTelConfig {
625
919
  /**
626
920
  * Instrumentation key of resource. Either this or connectionString must be specified.
627
921
  */
@@ -823,6 +1117,12 @@ declare namespace ApplicationInsights {
823
1117
  * @example ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature","auth_token", "api_key", "private_data"]
824
1118
  */
825
1119
  redactQueryParams?: string[];
1120
+ /**
1121
+ * [Optional] Controls if the SDK should look for the `traceparent` and/or `tracestate` values from
1122
+ * the service timing headers or meta tags from the initial page load.
1123
+ * @defaultValue eTraceHeadersMode.All
1124
+ */
1125
+ traceHdrMode?: eTraceHeadersMode;
826
1126
  }
827
1127
 
828
1128
  interface ICookieMgr {
@@ -983,7 +1283,7 @@ declare namespace ApplicationInsights {
983
1283
  /**
984
1284
  * The internal logging queue
985
1285
  */
986
- queue: _InternalLogMessage[];
1286
+ queue: IInternalLogMessage[];
987
1287
  /**
988
1288
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
989
1289
  * @param severity - The severity of the log message
@@ -1016,7 +1316,7 @@ declare namespace ApplicationInsights {
1016
1316
  * @param severity - The severity of the log message
1017
1317
  * @param message - The message to log.
1018
1318
  */
1019
- logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1319
+ logInternalMessage?(severity: LoggingSeverity, message: IInternalLogMessage): void;
1020
1320
  /**
1021
1321
  * Optional Callback hook to allow the diagnostic logger to update it's configuration
1022
1322
  * @param updateState - The new configuration state to apply to the diagnostic logger
@@ -1031,16 +1331,25 @@ declare namespace ApplicationInsights {
1031
1331
  * / Promise to allow any listeners to wait for the operation to complete.
1032
1332
  */
1033
1333
  unload?(isAsync?: boolean): void | IPromise<void>;
1334
+ /**
1335
+ * A flag that indicates whether this logger is in debug (throw real exceptions) mode
1336
+ */
1337
+ readonly dbgMode?: boolean;
1034
1338
  }
1035
1339
 
1036
- interface IDistributedTraceContext {
1340
+ interface IDistributedTraceContext extends IDistributedTraceInit {
1037
1341
  /**
1038
1342
  * Returns the current name of the page
1039
1343
  */
1040
1344
  getName(): string;
1041
1345
  /**
1042
- * Sets the current name of the page
1346
+ * Sets the current name of the page, also updates the name for any parent context.
1347
+ * This is used to identify the page in the telemetry data.
1348
+ * @remarks This function updates the current and ALL parent contexts with the new name,
1349
+ * to just update the name of the current context, use the `pageName` property.
1043
1350
  * @param pageName - The name of the page
1351
+ * @deprecated Use the `pageName` property to avoid the side effect of changing the page name of all
1352
+ * parent contexts.
1044
1353
  */
1045
1354
  setName(pageName: string): void;
1046
1355
  /**
@@ -1053,6 +1362,12 @@ declare namespace ApplicationInsights {
1053
1362
  * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1054
1363
  * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1055
1364
  * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1365
+ *
1366
+ * @remarks Sets the traceId for the current context AND all parent contexts, if you want to set the traceId
1367
+ * for the current context only, use the `traceId` property.
1368
+ * @param newValue - The traceId to set
1369
+ * @deprecated Use the `traceId` property to avoid the side effect of changing the traceId of all
1370
+ * parent contexts.
1056
1371
  */
1057
1372
  setTraceId(newValue: string): void;
1058
1373
  /**
@@ -1064,6 +1379,12 @@ declare namespace ApplicationInsights {
1064
1379
  * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1065
1380
  * Also know as the parentId, used to link requests together
1066
1381
  * https://www.w3.org/TR/trace-context/#parent-id
1382
+ *
1383
+ * @remarks Sets the spanId for the current context AND all parent contexts, if you want to set the spanId for
1384
+ * the current context only, use the `spanId` property.
1385
+ * @param newValue - The spanId to set
1386
+ * @deprecated Use the `spanId` property to avoid the side effect of changing the spanId of all
1387
+ * parent contexts.
1067
1388
  */
1068
1389
  setSpanId(newValue: string): void;
1069
1390
  /**
@@ -1072,9 +1393,258 @@ declare namespace ApplicationInsights {
1072
1393
  getTraceFlags(): number | undefined;
1073
1394
  /**
1074
1395
  * https://www.w3.org/TR/trace-context/#trace-flags
1396
+ * @remarks Sets the trace flags for the current context and ALL parent contexts, if you want to set the trace
1397
+ * flags for the current context only, use the `traceFlags` property.
1075
1398
  * @param newValue - An integer representation of the W3C TraceContext trace-flags.
1399
+ * @deprecated Use the `traceFlags` property to avoid the side effect of changing the traceFlags of all
1400
+ * parent contexts.
1076
1401
  */
1077
1402
  setTraceFlags(newValue?: number): void;
1403
+ /**
1404
+ * Returns the current name of the page
1405
+ * @remarks This function updates the current context only, to update the name of the current and ALL parent contexts,
1406
+ * use the `setName` method.
1407
+ * @default undefined
1408
+ * @since 3.4.0
1409
+ */
1410
+ pageName: string;
1411
+ /**
1412
+ * The current ID of the trace that this span belongs to. It is worldwide unique
1413
+ * with practically sufficient probability by being made as 16 randomly
1414
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1415
+ * 128 bits.
1416
+ * @remarks It is NOT recommended that you dynamically change this value after creation and it is actively
1417
+ * being used as this may affect anyone accessing this context (as a parent for instance). You should logically
1418
+ * treat this as readonly after creation.
1419
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1420
+ * if you need to update the current and ALL parent contexts, use the `setTraceId` method which
1421
+ * provides the previous behavior.
1422
+ * @since 3.4.0
1423
+ */
1424
+ traceId: string;
1425
+ /**
1426
+ * The ID of the Span. It is globally unique with practically sufficient
1427
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1428
+ * lowercase hex characters corresponding to 64 bits.
1429
+ * If you update this value, it will only update for the current context, not the parent context.
1430
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1431
+ * if you need to update the current and ALL parent contexts, use the `setSpanId` method.
1432
+ * @since 3.4.0
1433
+ */
1434
+ spanId: string;
1435
+ /**
1436
+ * Returns true if the current context was initialized (propagated) from a remote parent.
1437
+ * @since 3.4.0
1438
+ * @default false
1439
+ * @returns True if the context was propagated from a remote parent
1440
+ */
1441
+ readonly isRemote: boolean;
1442
+ /**
1443
+ * Trace flags to propagate.
1444
+ *
1445
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
1446
+ * sampled or not. When set, the least significant bit documents that the
1447
+ * caller may have recorded trace data. A caller who does not record trace
1448
+ * data out-of-band leaves this flag unset.
1449
+ *
1450
+ * see {@link eW3CTraceFlags} for valid flag values.
1451
+ *
1452
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
1453
+ * if you need to update the current and ALL parent contexts, use the `setTraceFlags` method.
1454
+ * @since 3.4.0
1455
+ */
1456
+ traceFlags?: number;
1457
+ /**
1458
+ * Returns the current trace state which will be used to propgate context across different services.
1459
+ * Updating (adding / removing keys) of the trace state will modify the current context.IOTelTraceState
1460
+ * @remarks Unlike the OpenTelemetry {@link IOTelTraceState}, this value is a mutable object, so you can
1461
+ * modify it directly you do not need to reassign the new value to this property.
1462
+ * @since 3.4.0
1463
+ */
1464
+ readonly traceState: IW3cTraceState;
1465
+ /**
1466
+ * Provides access to the parent context of the current context.
1467
+ * @remarks This is a read-only property, you cannot modify the parent context directly, you can only
1468
+ * modify the current context. If you need to modify the parent context, you need to do it through the
1469
+ * current context using the `setTraceId`, `setSpanId`, `setTraceFlags` and `setName` methods.
1470
+ * @default null
1471
+ * @since 3.4.0
1472
+ */
1473
+ readonly parentCtx?: IDistributedTraceContext | null;
1474
+ }
1475
+
1476
+ /**
1477
+ * An object that can be used to populate a new {@link IDistributedTraceContext} instance,
1478
+ * the included {@link IW3cTraceState} or {@link IOTelTraceState} is used as the parent of the
1479
+ * created instances traceState
1480
+ */
1481
+ interface IDistributedTraceInit {
1482
+ /**
1483
+ * The unique identifier for the trace that this span belongs to.
1484
+ *
1485
+ * The trace ID is a globally unique identifier that connects all spans within a single
1486
+ * distributed trace. It consists of 16 randomly generated bytes encoded as 32 lowercase
1487
+ * hexadecimal characters, providing 128 bits of entropy to ensure worldwide uniqueness
1488
+ * with practically sufficient probability.
1489
+ *
1490
+ * @remarks
1491
+ * - Must be exactly 32 lowercase hexadecimal characters
1492
+ * - Represents 128 bits (16 bytes) of random data
1493
+ * - Shared by all spans within the same trace
1494
+ * - Used for trace correlation across distributed systems
1495
+ * - Should never be all zeros (invalid trace ID)
1496
+ *
1497
+ * @example
1498
+ * ```typescript
1499
+ * // Example trace ID format
1500
+ * const traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
1501
+ *
1502
+ * // All spans in the same trace share this ID
1503
+ * console.log(parentSpan.spanContext().traceId === childSpan.spanContext().traceId); // true
1504
+ * ```
1505
+ */
1506
+ traceId: string;
1507
+ /**
1508
+ * The unique identifier for this specific span within the trace.
1509
+ *
1510
+ * The span ID uniquely identifies this span within the trace and is used to establish
1511
+ * parent-child relationships between spans. It consists of 8 randomly generated bytes
1512
+ * encoded as 16 lowercase hexadecimal characters, providing 64 bits of entropy to
1513
+ * ensure global uniqueness with practically sufficient probability.
1514
+ *
1515
+ * @remarks
1516
+ * - Must be exactly 16 lowercase hexadecimal characters
1517
+ * - Represents 64 bits (8 bytes) of random data
1518
+ * - Unique within the trace (different spans have different span IDs)
1519
+ * - Used as parent ID when creating child spans
1520
+ * - Should never be all zeros (invalid span ID)
1521
+ *
1522
+ * @example
1523
+ * ```typescript
1524
+ * // Example span ID format
1525
+ * const spanId = "00f067aa0ba902b7";
1526
+ *
1527
+ * // Each span has a unique ID within the trace
1528
+ * const parentId = parentSpan.spanContext().spanId; // "00f067aa0ba902b7"
1529
+ * const childId = childSpan.spanContext().spanId; // "b9c7c989f97918e1"
1530
+ *
1531
+ * // Child span uses parent's span ID as its parent ID
1532
+ * console.log(childSpan.parentSpanId === parentId); // true
1533
+ * ```
1534
+ */
1535
+ spanId: string;
1536
+ /**
1537
+ * Indicates whether this span context was propagated from a remote parent span.
1538
+ *
1539
+ * This flag distinguishes between spans created locally within the same process
1540
+ * and spans that represent operations in remote services. Remote spans are typically
1541
+ * created when trace context is received via HTTP headers, message queues, or other
1542
+ * inter-process communication mechanisms.
1543
+ *
1544
+ * @defaultValue false - spans are considered local unless explicitly marked as remote
1545
+ *
1546
+ * @remarks
1547
+ * - True only when span context was received from another process/service
1548
+ * - Helps distinguish local vs. distributed trace segments
1549
+ * - Used by tracing systems for visualization and analysis
1550
+ * - Local child spans of remote parents are NOT considered remote themselves
1551
+ *
1552
+ * @example
1553
+ * ```typescript
1554
+ * // HTTP service receiving trace context
1555
+ * const incomingSpanContext = extractSpanContextFromHeaders(request.headers);
1556
+ * console.log(incomingSpanContext.isRemote); // true
1557
+ *
1558
+ * // Child span created locally
1559
+ * const localChild = tracer.startSpan('local-operation', {
1560
+ * parent: incomingSpanContext
1561
+ * });
1562
+ * console.log(localChild.spanContext().isRemote); // false
1563
+ * ```
1564
+ */
1565
+ isRemote?: boolean;
1566
+ /**
1567
+ * Trace flags that control trace behavior and indicate sampling decisions.
1568
+ *
1569
+ * The trace flags are represented as a single byte (8-bit bitmap) that carries
1570
+ * trace-level information. The least significant bit (0x01) indicates whether
1571
+ * the trace is sampled. When this bit is set, it documents that the caller
1572
+ * may have recorded trace data. Additional bits are reserved for future use
1573
+ * and should be ignored when not understood.
1574
+ *
1575
+ * @remarks
1576
+ * - Represented as a number (0-255) corresponding to 8 bits
1577
+ * - Bit 0 (0x01): Sampled flag - indicates trace may contain recorded data
1578
+ * - Bits 1-7: Reserved for future use, should be preserved during propagation
1579
+ * - Used by sampling algorithms to make consistent decisions across services
1580
+ * - See {@link eW3CTraceFlags} for standard flag values
1581
+ *
1582
+ * @example
1583
+ * ```typescript
1584
+ * // Check if trace is sampled
1585
+ * const isSampled = (spanContext.traceFlags & 0x01) === 1;
1586
+ *
1587
+ * // Common flag values
1588
+ * const UNSAMPLED = 0x00; // 00000000 - not sampled
1589
+ * const SAMPLED = 0x01; // 00000001 - sampled
1590
+ *
1591
+ * // Preserving unknown flags during propagation
1592
+ * const preservedFlags = spanContext.traceFlags | 0x01; // Set sampled bit while preserving others
1593
+ *
1594
+ * // W3C traceparent header format includes these flags
1595
+ * const traceparent = `00-${traceId}-${spanId}-${traceFlags.toString(16).padStart(2, '0')}`;
1596
+ * ```
1597
+ */
1598
+ traceFlags?: number;
1599
+ /**
1600
+ * Vendor-specific trace state information for cross-system trace correlation.
1601
+ *
1602
+ * The trace state carries tracing-system-specific context in a standardized format
1603
+ * defined by the W3C Trace Context specification. It allows multiple tracing systems
1604
+ * to participate in the same trace by providing a mechanism for each system to add
1605
+ * its own metadata without interfering with others.
1606
+ *
1607
+ * The trace state is formatted as a comma-separated list of key-value pairs, where
1608
+ * each pair represents one tracing system's contribution. Keys should be unique
1609
+ * within the trace state and follow specific naming conventions.
1610
+ *
1611
+ * @remarks
1612
+ * - Maximum of 32 list members allowed
1613
+ * - Each member format: `key=value` separated by commas
1614
+ * - Keys should be namespaced to avoid conflicts (e.g., `vendor@system=value`)
1615
+ * - Total size should not exceed 512 characters for practical header limits
1616
+ * - Spaces around list members are ignored
1617
+ * - Preserves vendor-specific information during trace propagation
1618
+ *
1619
+ * @see {@link https://www.w3.org/TR/trace-context/#tracestate-field | W3C Trace Context Specification}
1620
+ *
1621
+ * @example
1622
+ * ```typescript
1623
+ * // Single tracing system
1624
+ * const singleVendor = {
1625
+ * get: (key: string) => key === 'rojo' ? '00f067aa0ba902b7' : undefined,
1626
+ * set: (key: string, value: string) => { ... },
1627
+ * unset: (key: string) => { ... },
1628
+ * serialize: () => 'rojo=00f067aa0ba902b7'
1629
+ * };
1630
+ *
1631
+ * // Multiple tracing systems
1632
+ * const multiVendor = {
1633
+ * serialize: () => 'rojo=00f067aa0ba902b7,congo=t61rcWkgMzE,vendor@system=custom-value'
1634
+ * };
1635
+ *
1636
+ * // Accessing trace state
1637
+ * const rojoValue = spanContext.traceState?.get('rojo');
1638
+ * const serialized = spanContext.traceState?.serialize();
1639
+ *
1640
+ * // HTTP header format (When the traceState is an IOTelTraceState)
1641
+ * headers['tracestate'] = spanContext.traceState?.serialize() || '';
1642
+ *
1643
+ * // HTTP header format (When the traceState is an IW3cTraceState)
1644
+ * headers['tracestate'] = spanContext.traceState?.hdrs()[0] || '';
1645
+ * ```
1646
+ */
1647
+ traceState?: IW3cTraceState | IOTelTraceState;
1078
1648
  }
1079
1649
 
1080
1650
  /**
@@ -1141,7 +1711,7 @@ declare namespace ApplicationInsights {
1141
1711
  * Identifies configuration override values when given feature is enabled
1142
1712
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1143
1713
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1144
- * Default: undefined
1714
+ * @default undefined
1145
1715
  */
1146
1716
  onCfg?: {
1147
1717
  [field: string]: any;
@@ -1150,7 +1720,7 @@ declare namespace ApplicationInsights {
1150
1720
  * Identifies configuration override values when given feature is disabled
1151
1721
  * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1152
1722
  * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: \{["extensionConfig.Analytics.disableAjaxTrackig"]:1\}
1153
- * Default: undefined
1723
+ * @default undefined
1154
1724
  */
1155
1725
  offCfg?: {
1156
1726
  [field: string]: any;
@@ -1162,6 +1732,11 @@ declare namespace ApplicationInsights {
1162
1732
  blockCdnCfg?: boolean;
1163
1733
  }
1164
1734
 
1735
+ interface IInternalLogMessage {
1736
+ message: string;
1737
+ messageId: _InternalMessageId;
1738
+ }
1739
+
1165
1740
  /**
1166
1741
  * Internal Interface
1167
1742
  */
@@ -1361,47 +1936,1094 @@ declare namespace ApplicationInsights {
1361
1936
  offlineBatchDrop?(cnt: number, reason?: number): void;
1362
1937
  }
1363
1938
 
1364
- class _InternalLogMessage {
1365
- static dataType: string;
1366
- message: string;
1367
- messageId: _InternalMessageId;
1368
- constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1369
- }
1370
-
1371
1939
  type _InternalMessageId = number | _eInternalMessageId;
1372
1940
 
1373
- /** IPayloadData describes interface of payload sent via POST channel */
1374
- interface IPayloadData {
1375
- urlString: string;
1376
- data: Uint8Array | string;
1377
- headers?: {
1378
- [name: string]: string;
1379
- };
1380
- timeout?: number;
1381
- disableXhrSync?: boolean;
1382
- disableFetchKeepAlive?: boolean;
1383
- sendReason?: SendRequestReason;
1384
- }
1385
-
1386
1941
  /**
1387
- * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
1942
+ * The main OpenTelemetry API interface that provides access to all OpenTelemetry functionality.
1943
+ * This interface extends the IOTelTracerProvider and serves as the entry point for OpenTelemetry operations.
1944
+ *
1945
+ * @example
1946
+ * ```typescript
1947
+ * // Get a tracer from the API instance
1948
+ * const tracer = otelApi.getTracer("my-component");
1949
+ *
1950
+ * // Create a span
1951
+ * const span = tracer.startSpan("operation");
1952
+ *
1953
+ * // Access context manager
1954
+ * const currentContext = otelApi.context.active();
1955
+ *
1956
+ * // Access trace API
1957
+ * const activeSpan = otelApi.trace.getActiveSpan();
1958
+ * ```
1959
+ *
1960
+ * @since 3.4.0
1388
1961
  */
1389
- interface IPerfEvent {
1962
+ interface IOTelApi extends IOTelTracerProvider {
1390
1963
  /**
1391
- * The name of the performance event
1964
+ * The configuration object that contains all OpenTelemetry-specific settings.
1965
+ * This includes tracing configuration, error handlers, and other OpenTelemetry options.
1966
+ *
1967
+ * @remarks
1968
+ * Changes to this configuration after initialization may not take effect until
1969
+ * the next telemetry operation, depending on the implementation.
1392
1970
  */
1393
- name: string;
1971
+ cfg: IOTelConfig;
1394
1972
  /**
1395
- * The start time of the performance event
1973
+ * The current {@link ITraceHost} instance for this IOTelApi instance, this is effectively
1974
+ * the OpenTelemetry ContextAPI instance without the static methods.
1975
+ * @returns The ContextManager instance
1396
1976
  */
1397
- start: number;
1977
+ host: ITraceHost;
1398
1978
  /**
1399
- * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
1400
- * the runtime environment.
1979
+ * The current {@link ITraceApi} instance for this IOTelApi instance, this is
1980
+ * effectively the OpenTelemetry TraceAPI instance without the static methods.
1981
+ * @returns The current {@link ITraceApi} instance
1401
1982
  */
1402
- payload: any;
1983
+ trace: ITraceApi;
1984
+ }
1985
+
1986
+ /**
1987
+ * Configuration interface for OpenTelemetry attribute limits.
1988
+ * These limits help control the size and number of attributes to prevent
1989
+ * excessive memory usage and ensure consistent performance.
1990
+ *
1991
+ * @example
1992
+ * ```typescript
1993
+ * const limits: IOTelAttributeLimits = {
1994
+ * attributeCountLimit: 128, // Maximum 128 attributes
1995
+ * attributeValueLengthLimit: 4096 // Maximum 4KB per attribute value
1996
+ * };
1997
+ * ```
1998
+ *
1999
+ * @remarks
2000
+ * When limits are exceeded:
2001
+ * - Additional attributes beyond `attributeCountLimit` are dropped
2002
+ * - Attribute values longer than `attributeValueLengthLimit` are truncated
2003
+ * - The behavior may vary based on the specific implementation
2004
+ *
2005
+ * @since 3.4.0
2006
+ */
2007
+ interface IOTelAttributeLimits {
1403
2008
  /**
1404
- * Is this occurring from an asynchronous event
2009
+ * Maximum allowed length for attribute values in characters.
2010
+ *
2011
+ * @remarks
2012
+ * - Values longer than this limit will be truncated
2013
+ * - Applies to string attribute values only
2014
+ * - Numeric and boolean values are not affected by this limit
2015
+ * - Array values have this limit applied to each individual element
2016
+ *
2017
+ * @defaultValue 4096
2018
+ *
2019
+ * @example
2020
+ * ```typescript
2021
+ * // If attributeValueLengthLimit is 100:
2022
+ * span.setAttribute("description", "a".repeat(200)); // Will be truncated to 100 characters
2023
+ * span.setAttribute("count", 12345); // Not affected (number)
2024
+ * span.setAttribute("enabled", true); // Not affected (boolean)
2025
+ * ```
2026
+ */
2027
+ attributeValueLengthLimit?: number;
2028
+ /**
2029
+ * Maximum number of attributes allowed per telemetry item.
2030
+ *
2031
+ * @remarks
2032
+ * - Attributes added beyond this limit will be dropped
2033
+ * - The order of attributes matters; earlier attributes take precedence
2034
+ * - This limit applies to the total count of attributes, regardless of their type
2035
+ * - Inherited or default attributes count toward this limit
2036
+ *
2037
+ * @defaultValue 128
2038
+ *
2039
+ * @example
2040
+ * ```typescript
2041
+ * // If attributeCountLimit is 5:
2042
+ * span.setAttributes({
2043
+ * "attr1": "value1", // Kept
2044
+ * "attr2": "value2", // Kept
2045
+ * "attr3": "value3", // Kept
2046
+ * "attr4": "value4", // Kept
2047
+ * "attr5": "value5", // Kept
2048
+ * "attr6": "value6" // Dropped (exceeds limit)
2049
+ * });
2050
+ * ```
2051
+ */
2052
+ attributeCountLimit?: number;
2053
+ }
2054
+
2055
+ /**
2056
+ * Attributes is a map from string to attribute values.
2057
+ *
2058
+ * Note: only the own enumerable keys are counted as valid attribute keys.
2059
+ *
2060
+ * @since 3.4.0
2061
+ */
2062
+ interface IOTelAttributes {
2063
+ [key: string]: OTelAttributeValue | undefined;
2064
+ }
2065
+
2066
+ /**
2067
+ * OpenTelemetry configuration interface
2068
+ * Provides configuration specific to the OpenTelemetry extensions
2069
+ */
2070
+ interface IOTelConfig {
2071
+ /**
2072
+ * Configuration interface for OpenTelemetry tracing functionality.
2073
+ * This interface contains all the settings that control how traces are created,
2074
+ * processed, and managed within the OpenTelemetry system.
2075
+ *
2076
+ * @example
2077
+ * ```typescript
2078
+ * const traceCfg: ITraceCfg = {
2079
+ * serviceName: "my-service",
2080
+ * generalLimits: {
2081
+ * attributeCountLimit: 128,
2082
+ * attributeValueLengthLimit: 4096
2083
+ * },
2084
+ * spanLimits: {
2085
+ * attributeCountLimit: 128,
2086
+ * linkCountLimit: 128,
2087
+ * eventCountLimit: 128
2088
+ * }
2089
+ * };
2090
+ * ```
2091
+ *
2092
+ * @since 3.4.0
2093
+ */
2094
+ traceCfg?: ITraceCfg;
2095
+ /**
2096
+ * Error handlers for OpenTelemetry operations.
2097
+ * This interface allows you to specify custom error handling logic for various
2098
+ * OpenTelemetry components, enabling better control over how errors are managed
2099
+ * within the OpenTelemetry system.
2100
+ *
2101
+ * @see {@link IOTelErrorHandlers}
2102
+ *
2103
+ * @example
2104
+ * ```typescript
2105
+ * const errorHandlers: IOTelErrorHandlers = {
2106
+ * attribError: (message, key, value) => {
2107
+ * console.warn(`Attribute error for ${key}:`, message);
2108
+ * }
2109
+ * };
2110
+ * ```
2111
+ */
2112
+ errorHandlers?: IOTelErrorHandlers;
2113
+ }
2114
+
2115
+ /**
2116
+ * Configuration interface for OpenTelemetry error handling callbacks.
2117
+ * Provides hooks to customize how different types of errors and diagnostic
2118
+ * messages are handled within the OpenTelemetry system.
2119
+ *
2120
+ * @example
2121
+ * ```typescript
2122
+ * const errorHandlers: IOTelErrorHandlers = {
2123
+ * attribError: (message, key, value) => {
2124
+ * console.warn(`Attribute error for ${key}:`, message);
2125
+ * },
2126
+ * spanError: (message, spanName) => {
2127
+ * logger.error(`Span ${spanName} error:`, message);
2128
+ * },
2129
+ * warn: (message) => {
2130
+ * logger.warn(message);
2131
+ * },
2132
+ * error: (message) => {
2133
+ * logger.error(message);
2134
+ * }
2135
+ * };
2136
+ * ```
2137
+ *
2138
+ * @remarks
2139
+ * If handlers are not provided, default behavior will be used:
2140
+ * - `attribError`: Throws an `OTelInvalidAttributeError`
2141
+ * - `spanError`: Logs to console or calls warn handler
2142
+ * - `debug`: Logs to console.log
2143
+ * - `warn`: Logs to console.warn
2144
+ * - `error`: Logs to console.error
2145
+ * - `notImplemented`: Logs to console.error
2146
+ *
2147
+ * @since 3.4.0
2148
+ */
2149
+ interface IOTelErrorHandlers {
2150
+ /**
2151
+ * Handles attribute-related errors, such as invalid attribute values or keys.
2152
+ * Called when an attribute operation fails validation or processing.
2153
+ *
2154
+ * @param message - Descriptive error message explaining what went wrong
2155
+ * @param key - The attribute key that caused the error
2156
+ * @param value - The attribute value that caused the error (may be of any type)
2157
+ *
2158
+ * @remarks
2159
+ * Common scenarios that trigger this handler:
2160
+ * - Invalid attribute key format
2161
+ * - Attribute value exceeds length limits
2162
+ * - Unsupported attribute value type
2163
+ * - Attribute count exceeds limits
2164
+ *
2165
+ * @default Throws an `OTelInvalidAttributeError`
2166
+ *
2167
+ * @example
2168
+ * ```typescript
2169
+ * attribError: (message, key, value) => {
2170
+ * metrics.increment('otel.attribute.errors', { key, type: typeof value });
2171
+ * logger.warn(`Attribute ${key} rejected: ${message}`);
2172
+ * }
2173
+ * ```
2174
+ */
2175
+ attribError?: (message: string, key: string, value: any) => void;
2176
+ /**
2177
+ * Handles span-related errors that occur during span operations.
2178
+ * Called when a span operation fails or encounters an unexpected condition.
2179
+ *
2180
+ * @param message - Descriptive error message explaining the span error
2181
+ * @param spanName - The name of the span that encountered the error
2182
+ *
2183
+ * @remarks
2184
+ * Common scenarios that trigger this handler:
2185
+ * - Span operation called on an ended span
2186
+ * - Invalid span configuration
2187
+ * - Span processor errors
2188
+ * - Context propagation failures
2189
+ *
2190
+ * @default Logs to console or calls the warn handler
2191
+ *
2192
+ * @example
2193
+ * ```typescript
2194
+ * spanError: (message, spanName) => {
2195
+ * metrics.increment('otel.span.errors', { span_name: spanName });
2196
+ * logger.error(`Span operation failed for "${spanName}": ${message}`);
2197
+ * }
2198
+ * ```
2199
+ */
2200
+ spanError?: (message: string, spanName: string) => void;
2201
+ /**
2202
+ * Handles debug-level diagnostic messages.
2203
+ * Used for detailed troubleshooting information that is typically
2204
+ * only relevant during development or when diagnosing issues.
2205
+ *
2206
+ * @param message - Debug message to be handled
2207
+ *
2208
+ * @remarks
2209
+ * Debug messages are typically:
2210
+ * - Verbose operational details
2211
+ * - Internal state information
2212
+ * - Performance metrics
2213
+ * - Development-time diagnostics
2214
+ *
2215
+ * @default Logs to console.log
2216
+ *
2217
+ * @example
2218
+ * ```typescript
2219
+ * debug: (message) => {
2220
+ * if (process.env.NODE_ENV === 'development') {
2221
+ * console.debug('[OTel Debug]', message);
2222
+ * }
2223
+ * }
2224
+ * ```
2225
+ */
2226
+ debug?: (message: string) => void;
2227
+ /**
2228
+ * Handles warning-level messages for non-fatal issues.
2229
+ * Used for conditions that are unusual but don't prevent continued operation.
2230
+ *
2231
+ * @param message - Warning message to be handled
2232
+ *
2233
+ * @remarks
2234
+ * Warning scenarios include:
2235
+ * - Configuration issues that fall back to defaults
2236
+ * - Performance degradation
2237
+ * - Deprecated API usage
2238
+ * - Resource limit approaches
2239
+ *
2240
+ * @default Logs to console.warn
2241
+ *
2242
+ * @example
2243
+ * ```typescript
2244
+ * warn: (message) => {
2245
+ * logger.warn('[OTel Warning]', message);
2246
+ * metrics.increment('otel.warnings');
2247
+ * }
2248
+ * ```
2249
+ */
2250
+ warn?: (message: string) => void;
2251
+ /**
2252
+ * Handles general error conditions that may affect functionality.
2253
+ * Used for significant errors that should be investigated but may not be fatal.
2254
+ *
2255
+ * @param message - Error message to be handled
2256
+ *
2257
+ * @remarks
2258
+ * Error scenarios include:
2259
+ * - Failed network requests
2260
+ * - Configuration validation failures
2261
+ * - Resource allocation failures
2262
+ * - Unexpected runtime conditions
2263
+ *
2264
+ * @default Logs to console.error
2265
+ *
2266
+ * @example
2267
+ * ```typescript
2268
+ * error: (message) => {
2269
+ * logger.error('[OTel Error]', message);
2270
+ * errorReporting.captureException(new Error(message));
2271
+ * }
2272
+ * ```
2273
+ */
2274
+ error?: (message: string) => void;
2275
+ /**
2276
+ * Handles errors related to unimplemented functionality.
2277
+ * Called when a method or feature is not yet implemented or is intentionally
2278
+ * disabled in the current configuration.
2279
+ *
2280
+ * @param message - Message describing the unimplemented functionality
2281
+ *
2282
+ * @remarks
2283
+ * Common scenarios:
2284
+ * - Placeholder methods that haven't been implemented
2285
+ * - Features disabled in the current build
2286
+ * - Platform-specific functionality not available
2287
+ * - Optional features not included in the configuration
2288
+ *
2289
+ * @default Logs to console.error
2290
+ *
2291
+ * @example
2292
+ * ```typescript
2293
+ * notImplemented: (message) => {
2294
+ * logger.warn(`[OTel Not Implemented] ${message}`);
2295
+ * if (process.env.NODE_ENV === 'development') {
2296
+ * console.trace('Not implemented method called');
2297
+ * }
2298
+ * }
2299
+ * ```
2300
+ */
2301
+ notImplemented?: (message: string) => void;
2302
+ }
2303
+
2304
+ interface IOTelExceptionWithCode {
2305
+ code: string | number;
2306
+ name?: string;
2307
+ message?: string;
2308
+ stack?: string;
2309
+ }
2310
+
2311
+ interface IOTelExceptionWithMessage {
2312
+ code?: string | number;
2313
+ message: string;
2314
+ name?: string;
2315
+ stack?: string;
2316
+ }
2317
+
2318
+ interface IOTelExceptionWithName {
2319
+ code?: string | number;
2320
+ message?: string;
2321
+ name: string;
2322
+ stack?: string;
2323
+ }
2324
+
2325
+ /**
2326
+ * Enhanced high-resolution time interface that extends the base tuple with additional properties.
2327
+ * Provides a more structured way to work with high-resolution timestamps.
2328
+ *
2329
+ * @example
2330
+ * ```typescript
2331
+ * const hrTime: IOTelHrTime = {
2332
+ * 0: 1609459200, // seconds since Unix epoch
2333
+ * 1: 500000000, // nanoseconds (0-999,999,999)
2334
+ * };
2335
+ * ```
2336
+ *
2337
+ * @since 3.4.0
2338
+ */
2339
+ interface IOTelHrTime extends OTelHrTimeBase {
2340
+ /**
2341
+ * Seconds since Unix epoch (January 1, 1970 00:00:00 UTC).
2342
+ * Must be a non-negative integer.
2343
+ */
2344
+ 0: number;
2345
+ /**
2346
+ * Nanoseconds within the second specified by index 0.
2347
+ * Must be in the range [0, 999999999].
2348
+ */
2349
+ 1: number;
2350
+ }
2351
+
2352
+ /**
2353
+ * Provides an OpenTelemetry compatible interface for spans conforming to the OpenTelemetry API specification (v1.9.0).
2354
+ *
2355
+ * A span represents an operation within a trace and is the fundamental unit of work in distributed tracing.
2356
+ * Spans can be thought of as a grouping mechanism for a set of operations that are executed as part of
2357
+ * a single logical unit of work, providing timing information and contextual data about the operation.
2358
+ *
2359
+ * Spans form a tree structure within a trace, with a single root span that may have zero or more child spans,
2360
+ * which in turn may have their own children. This hierarchical structure allows for detailed analysis of
2361
+ * complex, multi-step operations across distributed systems.
2362
+ *
2363
+ * @since 3.4.0
2364
+ *
2365
+ * @remarks
2366
+ * - All spans created by this library implement the ISpan interface and extend the IReadableSpan interface
2367
+ * - Spans should be ended by calling `end()` when the operation completes
2368
+ * - Once ended, spans should generally not be used for further operations
2369
+ * - Spans automatically track timing information from creation to end
2370
+ *
2371
+ * @example
2372
+ * ```typescript
2373
+ * // Basic span usage
2374
+ * const span = tracer.startSpan('user-authentication');
2375
+ * span.setAttribute('user.id', '12345');
2376
+ * span.setAttribute('auth.method', 'oauth2');
2377
+ *
2378
+ * try {
2379
+ * const result = await authenticateUser();
2380
+ * span.setStatus({ code: SpanStatusCode.OK });
2381
+ * span.setAttribute('auth.success', true);
2382
+ * } catch (error) {
2383
+ * span.recordException(error);
2384
+ * span.setStatus({
2385
+ * code: SpanStatusCode.ERROR,
2386
+ * message: 'Authentication failed'
2387
+ * });
2388
+ * } finally {
2389
+ * span.end();
2390
+ * }
2391
+ * ```
2392
+ */
2393
+ interface IOTelSpan {
2394
+ /**
2395
+ * Returns the span context object associated with this span.
2396
+ *
2397
+ * The span context is an immutable, serializable identifier that uniquely identifies
2398
+ * this span within a trace. It contains the trace ID, span ID, and trace flags that
2399
+ * can be used to create new child spans or propagate trace context across process boundaries.
2400
+ *
2401
+ * The returned span context remains valid even after the span has ended, making it
2402
+ * useful for asynchronous operations and cross-service communication.
2403
+ *
2404
+ * @returns The immutable span context associated with this span
2405
+ *
2406
+ * @remarks
2407
+ * - The span context is the primary mechanism for trace propagation
2408
+ * - Context can be serialized and transmitted across network boundaries
2409
+ * - Contains trace ID (unique to the entire trace) and span ID (unique to this span)
2410
+ *
2411
+ * @example
2412
+ * ```typescript
2413
+ * const span = tracer.startSpan('parent-operation');
2414
+ * const spanContext = span.spanContext();
2415
+ *
2416
+ * // Use context to create child spans in other parts of the system
2417
+ * const childSpan = tracer.startSpan('child-operation', {
2418
+ * parent: spanContext
2419
+ * });
2420
+ *
2421
+ * // Context can be serialized for cross-service propagation
2422
+ * const traceId = spanContext.traceId;
2423
+ * const spanId = spanContext.spanId;
2424
+ * ```
2425
+ */
2426
+ spanContext(): IDistributedTraceContext;
2427
+ /**
2428
+ * Sets a single attribute on the span with the specified key and value.
2429
+ *
2430
+ * Attributes provide contextual information about the operation represented by the span.
2431
+ * They are key-value pairs that help with filtering, grouping, and understanding spans
2432
+ * in trace analysis tools. Attributes should represent meaningful properties of the operation.
2433
+ *
2434
+ * @param key - The attribute key, should be descriptive and follow naming conventions
2435
+ * @param value - The attribute value; null or undefined values are invalid and result in undefined behavior
2436
+ *
2437
+ * @returns This span instance for method chaining
2438
+ *
2439
+ * @remarks
2440
+ * - Attribute keys should follow semantic conventions when available
2441
+ * - Common attributes include service.name, http.method, db.statement, etc.
2442
+ * - Setting null or undefined values is invalid and may cause unexpected behavior
2443
+ * - Attributes set after span creation don't affect sampling decisions
2444
+ *
2445
+ * @example
2446
+ * ```typescript
2447
+ * const span = tracer.startSpan('http-request');
2448
+ *
2449
+ * // Set individual attributes with descriptive keys
2450
+ * span.setAttribute('http.method', 'POST')
2451
+ * .setAttribute('http.url', 'https://api.example.com/users')
2452
+ * .setAttribute('http.status_code', 201)
2453
+ * .setAttribute('user.id', '12345')
2454
+ * .setAttribute('request.size', 1024);
2455
+ * ```
2456
+ */
2457
+ setAttribute(key: string, value: OTelAttributeValue): this;
2458
+ /**
2459
+ * Sets multiple attributes on the span at once using an attributes object.
2460
+ *
2461
+ * This method allows efficient batch setting of multiple attributes in a single call.
2462
+ * All attributes in the provided object will be added to the span, supplementing any
2463
+ * existing attributes (duplicate keys will be overwritten).
2464
+ *
2465
+ * @param attributes - An object containing key-value pairs to set as span attributes
2466
+ *
2467
+ * @returns This span instance for method chaining
2468
+ *
2469
+ * @remarks
2470
+ * - Null or undefined attribute values are invalid and will result in undefined behavior
2471
+ * - More efficient than multiple `setAttribute` calls for bulk operations
2472
+ * - Existing attributes with the same keys will be overwritten
2473
+ *
2474
+ * @example
2475
+ * ```typescript
2476
+ * const span = tracer.startSpan('database-query');
2477
+ *
2478
+ * // Set multiple attributes efficiently
2479
+ * span.setAttributes({
2480
+ * 'db.system': 'postgresql',
2481
+ * 'db.name': 'user_database',
2482
+ * 'db.table': 'users',
2483
+ * 'db.operation': 'SELECT',
2484
+ * 'db.rows_affected': 5,
2485
+ * 'query.duration_ms': 15.7
2486
+ * });
2487
+ * ```
2488
+ */
2489
+ setAttributes(attributes: IOTelAttributes): this;
2490
+ /**
2491
+ * The {@link IAttributeContainer | attribute container} associated with this span, providing
2492
+ * advanced attribute management capabilities. Rather than using the {@link IReadableSpan#attributes}
2493
+ * directly which returns a readonly {@link IOTelAttributes} map that is a snapshot of the attributes at
2494
+ * the time of access, the attribute container offers methods to get, set, delete, and iterate over attributes
2495
+ * with fine-grained control.
2496
+ * It is recommended that you only access the {@link IReadableSpan#attributes} property sparingly due to the
2497
+ * performance cost of taking a snapshot of all attributes.
2498
+ */
2499
+ readonly attribContainer: IAttributeContainer;
2500
+ /**
2501
+ * Sets the status of the span to indicate the success or failure of the operation.
2502
+ *
2503
+ * The span status provides a standardized way to indicate whether the operation
2504
+ * completed successfully, encountered an error, or is in an unknown state.
2505
+ * This status is used by observability tools to provide meaningful insights
2506
+ * about system health and operation outcomes.
2507
+ *
2508
+ * @param status - The status object containing code and optional message
2509
+ *
2510
+ * @returns This span instance for method chaining
2511
+ *
2512
+ * @remarks
2513
+ * - Default status is UNSET until explicitly set
2514
+ * - Setting status overrides any previous status values
2515
+ * - ERROR status should be accompanied by a descriptive message when possible
2516
+ * - Status should reflect the final outcome of the operation
2517
+ *
2518
+ * @example
2519
+ * ```typescript
2520
+ * const span = tracer.startSpan('payment-processing');
2521
+ *
2522
+ * try {
2523
+ * const result = await processPayment(paymentData);
2524
+ *
2525
+ * // Indicate successful completion
2526
+ * span.setStatus({
2527
+ * code: SpanStatusCode.OK
2528
+ * });
2529
+ *
2530
+ * } catch (error) {
2531
+ * // Indicate operation failed
2532
+ * span.setStatus({
2533
+ * code: SpanStatusCode.ERROR,
2534
+ * message: 'Payment processing failed: ' + error.message
2535
+ * });
2536
+ *
2537
+ * span.recordException(error);
2538
+ * }
2539
+ * ```
2540
+ */
2541
+ setStatus(status: IOTelSpanStatus): this;
2542
+ /**
2543
+ * Updates the name of the span, overriding the name provided during creation.
2544
+ *
2545
+ * Span names should be descriptive and represent the operation being performed.
2546
+ * Updating the name can be useful when the operation's scope becomes clearer
2547
+ * during execution, or when implementing generic spans that need specific naming
2548
+ * based on runtime conditions.
2549
+ *
2550
+ * @param name - The new name for the span, should be descriptive of the operation
2551
+ *
2552
+ * @returns This span instance for method chaining
2553
+ *
2554
+ * @remarks
2555
+ * - Name updates may affect sampling behavior depending on implementation
2556
+ * - Choose names that are meaningful but not too specific to avoid cardinality issues
2557
+ * - Follow naming conventions consistent with your observability strategy
2558
+ * - Consider the impact on existing traces and dashboards when changing names
2559
+ *
2560
+ * @example
2561
+ * ```typescript
2562
+ * const span = tracer.startSpan('generic-operation');
2563
+ *
2564
+ * // Update name based on runtime determination
2565
+ * if (operationType === 'user-registration') {
2566
+ * span.updateName('user-registration');
2567
+ * span.setAttribute('operation.type', 'registration');
2568
+ * } else if (operationType === 'user-login') {
2569
+ * span.updateName('user-authentication');
2570
+ * span.setAttribute('operation.type', 'authentication');
2571
+ * }
2572
+ * ```
2573
+ */
2574
+ updateName(name: string): this;
2575
+ /**
2576
+ * Marks the end of the span's execution and records the end timestamp.
2577
+ *
2578
+ * This method finalizes the span and makes it available for export to tracing systems.
2579
+ * Once ended, the span should not be used for further operations. The span's duration
2580
+ * is calculated from its start time to the end time provided or current time.
2581
+ *
2582
+ * @param endTime - Optional end time; if not provided, current time is used
2583
+ *
2584
+ * @remarks
2585
+ * - This method does NOT return `this` to discourage chaining after span completion
2586
+ * - Ending a span has no effect on child spans, which may continue running
2587
+ * - Child spans can be ended independently after their parent has ended
2588
+ * - The span becomes eligible for export once ended
2589
+ * - Calling end() multiple times has no additional effect
2590
+ *
2591
+ * @example
2592
+ * ```typescript
2593
+ * const span = tracer.startSpan('file-processing');
2594
+ *
2595
+ * try {
2596
+ * // Perform the operation
2597
+ * const result = await processFile(filePath);
2598
+ *
2599
+ * // Record success
2600
+ * span.setStatus({ code: SpanStatusCode.OK });
2601
+ * span.setAttribute('file.size', result.size);
2602
+ *
2603
+ * } catch (error) {
2604
+ * span.recordException(error);
2605
+ * span.setStatus({
2606
+ * code: SpanStatusCode.ERROR,
2607
+ * message: error.message
2608
+ * });
2609
+ * } finally {
2610
+ * // Always end the span
2611
+ * span.end();
2612
+ * // Don't use span after this point
2613
+ * }
2614
+ *
2615
+ * // Custom end time example
2616
+ * const customEndTime = Date.now() * 1000000; // nanoseconds
2617
+ * span.end(customEndTime);
2618
+ * ```
2619
+ */
2620
+ end(endTime?: OTelTimeInput): void;
2621
+ /**
2622
+ * Returns whether this span is actively recording information.
2623
+ *
2624
+ * A recording span accepts and stores attributes, events, status, and other span data.
2625
+ * Non-recording spans (typically due to sampling decisions) may ignore operations
2626
+ * like setAttribute() to optimize performance. This method allows conditional
2627
+ * logic to avoid expensive operations on non-recording spans.
2628
+ *
2629
+ * @returns True if the span is actively recording information, false otherwise
2630
+ *
2631
+ * @remarks
2632
+ * - Recording status is typically determined at span creation time
2633
+ * - Non-recording spans still provide valid span context for propagation
2634
+ * - Use this check to avoid expensive attribute calculations for non-recording spans
2635
+ * - Recording status remains constant throughout the span's lifetime
2636
+ *
2637
+ * @example
2638
+ * ```typescript
2639
+ * const span = tracer.startSpan('data-processing');
2640
+ *
2641
+ * // Only perform expensive operations if span is recording
2642
+ * if (span.isRecording()) {
2643
+ * const metadata = await expensiveMetadataCalculation();
2644
+ * span.setAttributes({
2645
+ * 'process.metadata': JSON.stringify(metadata),
2646
+ * 'process.complexity': metadata.complexity,
2647
+ * 'process.estimated_duration': metadata.estimatedMs
2648
+ * });
2649
+ * }
2650
+ *
2651
+ * // Always safe to set basic attributes
2652
+ * span.setAttribute('process.started', true);
2653
+ * ```
2654
+ */
2655
+ isRecording(): boolean;
2656
+ /**
2657
+ * Records an exception as a span event with automatic error status handling.
2658
+ *
2659
+ * This method captures exception information and automatically creates a span event
2660
+ * with standardized exception attributes. It's the recommended way to handle errors
2661
+ * within spans, providing consistent error reporting across the application.
2662
+ *
2663
+ * @param exception - The exception to record; accepts string messages or Error objects
2664
+ * @param time - Optional timestamp for when the exception occurred; defaults to current time
2665
+ *
2666
+ * @remarks
2667
+ * - Automatically extracts exception type, message, and stack trace when available
2668
+ * - Creates a standardized span event with exception details
2669
+ * - Does NOT automatically set span status to ERROR - call setStatus() explicitly if needed
2670
+ * - Exception events are useful for debugging and error analysis
2671
+ *
2672
+ * @example
2673
+ * ```typescript
2674
+ * const span = tracer.startSpan('risky-operation');
2675
+ *
2676
+ * try {
2677
+ * await performRiskyOperation();
2678
+ * span.setStatus({ code: SpanStatusCode.OK });
2679
+ *
2680
+ * } catch (error) {
2681
+ * // Record the exception details
2682
+ * span.recordException(error);
2683
+ *
2684
+ * // Explicitly set error status
2685
+ * span.setStatus({
2686
+ * code: SpanStatusCode.ERROR,
2687
+ * message: 'Operation failed due to: ' + error.message
2688
+ * });
2689
+ *
2690
+ * // Re-throw if needed
2691
+ * throw error;
2692
+ * } finally {
2693
+ * span.end();
2694
+ * }
2695
+ *
2696
+ * // Recording string exceptions
2697
+ * span.recordException('Custom error message occurred');
2698
+ *
2699
+ * // Recording with custom timestamp
2700
+ * const errorTime = Date.now() * 1000000; // nanoseconds
2701
+ * span.recordException(error, errorTime);
2702
+ * ```
2703
+ */
2704
+ recordException(exception: OTelException, time?: OTelTimeInput): void;
2705
+ }
2706
+
2707
+ /**
2708
+ * A SpanContext represents the portion of a {@link IOTelSpan} which must be
2709
+ * serialized and propagated along side of a {@link IOTelBaggage}.
2710
+ */
2711
+ interface IOTelSpanContext extends IDistributedTraceInit {
2712
+ /**
2713
+ * Trace flags to propagate.
2714
+ *
2715
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
2716
+ * sampled or not. When set, the least significant bit documents that the
2717
+ * caller may have recorded trace data. A caller who does not record trace
2718
+ * data out-of-band leaves this flag unset.
2719
+ *
2720
+ * see {@link eW3CTraceFlags} for valid flag values.
2721
+ */
2722
+ traceFlags: number;
2723
+ }
2724
+
2725
+ /**
2726
+ * Provides an OpenTelemetry like Interface for the Open Telemetry Api (1.9.0) SpanOptions
2727
+ * type. Where SpanOptions are options that can be used to configure a span.
2728
+ */
2729
+ interface IOTelSpanOptions {
2730
+ /**
2731
+ * The SpanKind of a span of this span, this is used to specify
2732
+ * the relationship between the span and its parent span.
2733
+ * @see {@link eOTelSpanKind} for possible values.
2734
+ * @default eOTelSpanKind.INTERNAL
2735
+ */
2736
+ kind?: OTelSpanKind;
2737
+ /**
2738
+ * A span's attributes
2739
+ */
2740
+ attributes?: IOTelAttributes;
2741
+ /** A manually specified start time for the created `Span` object. */
2742
+ startTime?: OTelTimeInput;
2743
+ /** The new span should be a root span. (Ignore parent from context). */
2744
+ root?: boolean;
2745
+ /** Specify whether the span should be a recording span, default is true */
2746
+ recording?: boolean;
2747
+ }
2748
+
2749
+ interface IOTelSpanStatus {
2750
+ /**
2751
+ * The status code of this message.
2752
+ */
2753
+ code: eOTelSpanStatusCode;
2754
+ /**
2755
+ * A developer-facing error message.
2756
+ */
2757
+ message?: string;
2758
+ }
2759
+
2760
+ /**
2761
+ * OpenTelemetry tracer interface for creating and managing spans within a trace.
2762
+ *
2763
+ * A tracer is responsible for creating spans that represent units of work within a distributed system.
2764
+ * Each tracer is typically associated with a specific instrumentation library or component,
2765
+ * allowing for fine-grained control over how different parts of an application generate telemetry.
2766
+ *
2767
+ * @example
2768
+ * ```typescript
2769
+ * // Get a tracer instance
2770
+ * const tracer = otelApi.getTracer('my-service');
2771
+ *
2772
+ * // Create a simple span
2773
+ * const span = tracer.startSpan('database-query');
2774
+ * span.setAttribute('db.operation', 'SELECT');
2775
+ * span.end();
2776
+ *
2777
+ * // Create an active span with automatic context management
2778
+ * tracer.startActiveSpan('process-request', (span) => {
2779
+ * span.setAttribute('request.id', '12345');
2780
+ *
2781
+ * // Any spans created within this block will be children of this span
2782
+ * processRequest();
2783
+ *
2784
+ * span.end();
2785
+ * });
2786
+ * ```
2787
+ *
2788
+ * @see {@link IReadableSpan} - Interface for individual spans
2789
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
2790
+ *
2791
+ * @since 3.4.0
2792
+ */
2793
+ interface IOTelTracer {
2794
+ /**
2795
+ * Creates and starts a new span without setting it as the active span in the current context.
2796
+ *
2797
+ * This method creates a span but does NOT modify the current execution context.
2798
+ * The caller is responsible for managing the span's lifecycle, including calling `end()`
2799
+ * when the operation completes.
2800
+ *
2801
+ * @param name - The name of the span, should be descriptive of the operation being traced
2802
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
2803
+ *
2804
+ * @returns The newly created span, or null if span creation failed
2805
+ *
2806
+ * @remarks
2807
+ * - The returned span must be manually ended by calling `span.end()`
2808
+ * - This span will not automatically become the parent for spans created in nested operations
2809
+ * - Use `startActiveSpan` if you want automatic context management
2810
+ *
2811
+ * @example
2812
+ * ```typescript
2813
+ * const span = tracer.startSpan('database-operation');
2814
+ * if (span) {
2815
+ * try {
2816
+ * span.setAttribute('db.table', 'users');
2817
+ * span.setAttribute('db.operation', 'SELECT');
2818
+ *
2819
+ * // Perform database operation
2820
+ * const result = await db.query('SELECT * FROM users');
2821
+ *
2822
+ * span.setAttributes({
2823
+ * 'db.rows_affected': result.length,
2824
+ * 'operation.success': true
2825
+ * });
2826
+ * } catch (error) {
2827
+ * span.setStatus({
2828
+ * code: SpanStatusCode.ERROR,
2829
+ * message: error.message
2830
+ * });
2831
+ * span.recordException(error);
2832
+ * } finally {
2833
+ * span.end(); // Always end the span
2834
+ * }
2835
+ * }
2836
+ * ```
2837
+ */
2838
+ startSpan(name: string, options?: IOTelSpanOptions): IReadableSpan | null;
2839
+ /**
2840
+ * Creates and starts a new span, sets it as the active span in the current context,
2841
+ * and executes a provided function within this context.
2842
+ *
2843
+ * This method creates a span, makes it active during the execution of the provided
2844
+ * function, and automatically ends the span when the function completes (or throws).
2845
+ * This provides automatic span lifecycle management and context propagation.
2846
+ *
2847
+ * @param name - The name of the span, should be descriptive of the operation being traced
2848
+ * @param options - Optional configuration for span creation (parent context, attributes, etc.)
2849
+ * @param fn - The function to execute within the span's active context
2850
+ *
2851
+ * @returns The result of executing the provided function
2852
+ *
2853
+ * @remarks
2854
+ * - The span is automatically ended when the function completes or throws an exception
2855
+ * - The span becomes the active parent for any spans created within the function
2856
+ * - If the function throws an error, the span status is automatically set to ERROR
2857
+ * - This is the recommended method for most tracing scenarios due to automatic lifecycle management
2858
+ * - Multiple overloads available for different parameter combinations
2859
+ *
2860
+ * @example
2861
+ * ```typescript
2862
+ * // Synchronous operation with just name and function
2863
+ * const result = tracer.startActiveSpan('user-service', (span) => {
2864
+ * span.setAttribute('operation', 'get-user-details');
2865
+ * return { user: getUserData(), timestamp: new Date().toISOString() };
2866
+ * });
2867
+ *
2868
+ * // With options
2869
+ * const result2 = tracer.startActiveSpan('database-query',
2870
+ * { attributes: { 'db.table': 'users' } },
2871
+ * (span) => {
2872
+ * span.setAttribute('db.operation', 'SELECT');
2873
+ * return database.getUser('123');
2874
+ * }
2875
+ * );
2876
+ *
2877
+ * // With full context control
2878
+ * const result3 = tracer.startActiveSpan('external-api',
2879
+ * { attributes: { 'service.name': 'payment-api' } },
2880
+ * currentContext,
2881
+ * async (span) => {
2882
+ * try {
2883
+ * const response = await fetch('/api/payment');
2884
+ * span.setAttributes({
2885
+ * 'http.status_code': response.status,
2886
+ * 'operation.success': response.ok
2887
+ * });
2888
+ * return response.json();
2889
+ * } catch (error) {
2890
+ * span.setAttribute('error.type', error.constructor.name);
2891
+ * throw error; // Error automatically recorded
2892
+ * }
2893
+ * }
2894
+ * );
2895
+ * ```
2896
+ */
2897
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, fn: F): ReturnType<F>;
2898
+ startActiveSpan<F extends (span: IReadableSpan) => unknown>(name: string, options: IOTelSpanOptions, fn: F): ReturnType<F>;
2899
+ }
2900
+
2901
+ interface IOTelTracerOptions {
2902
+ /**
2903
+ * The schemaUrl of the tracer or instrumentation library
2904
+ */
2905
+ schemaUrl?: string;
2906
+ }
2907
+
2908
+ /**
2909
+ * OpenTelemetry Trace API for getting tracers.
2910
+ * This provides the standard OpenTelemetry trace API entry point.
2911
+ */
2912
+ interface IOTelTracerProvider {
2913
+ /**
2914
+ * Returns a Tracer, creating one if one with the given name and version is
2915
+ * not already created. This may return
2916
+ * - The same Tracer instance if one has already been created with the same name and version
2917
+ * - A new Tracer instance if one has not already been created with the same name and version
2918
+ * - A non-operational Tracer if the provider is not operational
2919
+ *
2920
+ * @param name - The name of the tracer or instrumentation library.
2921
+ * @param version - The version of the tracer or instrumentation library.
2922
+ * @param options - The options of the tracer or instrumentation library.
2923
+ * @returns Tracer A Tracer with the given name and version
2924
+ */
2925
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
2926
+ /**
2927
+ * Forces the tracer provider to flush any buffered data.
2928
+ * @returns A promise that resolves when the flush is complete.
2929
+ */
2930
+ forceFlush?: () => IPromise<void> | void;
2931
+ /**
2932
+ * Shuts down the tracer provider and releases any resources.
2933
+ * @returns A promise that resolves when the shutdown is complete.
2934
+ */
2935
+ shutdown?: () => IPromise<void> | void;
2936
+ }
2937
+
2938
+ /**
2939
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Api (1.9.0) TraceState type.
2940
+ *
2941
+ * The TraceState is a list of key/value pairs that are used to propagate
2942
+ * vendor-specific trace information across different distributed tracing systems.
2943
+ * The TraceState is used to store the state of a trace across different
2944
+ * distributed tracing systems, and it is used to ensure that the trace information
2945
+ * is consistent across different systems.
2946
+ *
2947
+ * Instances of TraceState are immutable, and the methods on this interface
2948
+ * return a new instance of TraceState with the updated values.
2949
+ */
2950
+ interface IOTelTraceState {
2951
+ /**
2952
+ * Create a new TraceState which inherits from this TraceState and has the
2953
+ * given key set.
2954
+ * The new entry will always be added in the front of the list of states.
2955
+ *
2956
+ * @param key - key of the TraceState entry.
2957
+ * @param value - value of the TraceState entry.
2958
+ */
2959
+ set(key: string, value: string): IOTelTraceState;
2960
+ /**
2961
+ * Return a new TraceState which inherits from this TraceState but does not
2962
+ * contain the given key.
2963
+ *
2964
+ * @param key - the key for the TraceState entry to be removed.
2965
+ */
2966
+ unset(key: string): IOTelTraceState;
2967
+ /**
2968
+ * Returns the value to which the specified key is mapped, or `undefined` if
2969
+ * this map contains no mapping for the key.
2970
+ *
2971
+ * @param key - with which the specified value is to be associated.
2972
+ * @returns the value to which the specified key is mapped, or `undefined` if
2973
+ * this map contains no mapping for the key.
2974
+ */
2975
+ get(key: string): string | undefined;
2976
+ /**
2977
+ * Serializes the TraceState to a `list` as defined below. The `list` is a series of `list-members`
2978
+ * separated by commas `,`, and a list-member is a key/value pair separated by an equals sign `=`.
2979
+ * Spaces and horizontal tabs surrounding `list-members` are ignored. There can be a maximum of 32
2980
+ * `list-members` in a `list`.
2981
+ *
2982
+ * If the resulting serialization is limited to no longer than 512 bytes, if the combination of
2983
+ * keys and values exceeds this limit, the serialization will be truncated to the last key/value pair
2984
+ * that fits within the limit. The serialization will be returned as a string.
2985
+ *
2986
+ * This is different from the {@link IW3cTraceState} serialization which returns an array of strings where each
2987
+ * string is limited to 512 bytes and the array is limited to 32 strings. Thus the OpenTelemetry serialization
2988
+ * will only return the first single string that fits within the limie.
2989
+ *
2990
+ * @returns the serialized string.
2991
+ */
2992
+ serialize(): string;
2993
+ }
2994
+
2995
+ /** IPayloadData describes interface of payload sent via POST channel */
2996
+ interface IPayloadData {
2997
+ urlString: string;
2998
+ data: Uint8Array | string;
2999
+ headers?: {
3000
+ [name: string]: string;
3001
+ };
3002
+ timeout?: number;
3003
+ disableXhrSync?: boolean;
3004
+ disableFetchKeepAlive?: boolean;
3005
+ sendReason?: SendRequestReason;
3006
+ }
3007
+
3008
+ /**
3009
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
3010
+ */
3011
+ interface IPerfEvent {
3012
+ /**
3013
+ * The name of the performance event
3014
+ */
3015
+ name: string;
3016
+ /**
3017
+ * The start time of the performance event
3018
+ */
3019
+ start: number;
3020
+ /**
3021
+ * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
3022
+ * the runtime environment.
3023
+ */
3024
+ payload: any;
3025
+ /**
3026
+ * Is this occurring from an asynchronous event
1405
3027
  */
1406
3028
  isAsync: boolean;
1407
3029
  /**
@@ -1770,6 +3392,73 @@ declare namespace ApplicationInsights {
1770
3392
  finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
1771
3393
  }
1772
3394
 
3395
+ /**
3396
+ * Provides an OpenTelemetry compatible Interface for the Open Telemetry Sdk-Trace-Base (1.8.0 and 2.0.0) ReadableSpan type.
3397
+ *
3398
+ * The IReadableSpan interface is used to represent a span that can be read and exported, while the OpenTelemetry
3399
+ * specification defines a ReadableSpan as a Span that has been ended and is ready to be exported. By default all
3400
+ * spans created by this library implement the IReadableSpan interface which also extends the {@link IOTelSpan} interface.
3401
+ *
3402
+ * This interface is defined to provide compatibility with exporters defined by the OpenTelemetry Trace SDK.
3403
+ * @since 3.4.0
3404
+ */
3405
+ interface IReadableSpan extends IOTelSpan {
3406
+ /**
3407
+ * The span's unique identifier.
3408
+ */
3409
+ readonly name: string;
3410
+ /**
3411
+ * Identifies the type (or kind) that this span is representing.
3412
+ */
3413
+ readonly kind: OTelSpanKind;
3414
+ readonly spanContext: () => IDistributedTraceContext;
3415
+ readonly parentSpanId?: string;
3416
+ readonly parentSpanContext?: IDistributedTraceContext;
3417
+ readonly startTime: IOTelHrTime;
3418
+ readonly endTime: IOTelHrTime;
3419
+ readonly status: IOTelSpanStatus;
3420
+ /**
3421
+ * Provides a snapshot of the span's attributes at the time this span was ended.
3422
+ * @returns A read-only snapshot of the span's attributes
3423
+ * @remarks
3424
+ * It is recommended that you only access this property sparingly due to the
3425
+ * performance cost of taking a snapshot of all attributes.
3426
+ */
3427
+ readonly attributes: IOTelAttributes;
3428
+ readonly duration: IOTelHrTime;
3429
+ readonly ended: boolean;
3430
+ readonly droppedAttributesCount: number;
3431
+ }
3432
+
3433
+ /**
3434
+ * Represents the execution scope for a span, combining the trace instance and the active span.
3435
+ * This interface is used as the context for executing functions within a span's scope.
3436
+ *
3437
+ * @since 3.4.0
3438
+ */
3439
+ interface ISpanScope<T extends ITraceHost = ITraceHost> {
3440
+ /**
3441
+ * The trace host (core or AISKU instance).
3442
+ * @since 3.4.0
3443
+ */
3444
+ readonly host: T;
3445
+ /**
3446
+ * The active span for this execution scope.
3447
+ * @since 3.4.0
3448
+ */
3449
+ readonly span: IReadableSpan;
3450
+ /**
3451
+ * The previously active span before this scope was created, if any.
3452
+ * @since 3.4.0
3453
+ */
3454
+ readonly prvSpan?: IReadableSpan;
3455
+ /**
3456
+ * Restores the previous active span in the trace instance.
3457
+ * @since 3.4.0
3458
+ */
3459
+ restore(): void;
3460
+ }
3461
+
1773
3462
  interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
1774
3463
  remove(): void;
1775
3464
  }
@@ -2029,6 +3718,205 @@ declare namespace ApplicationInsights {
2029
3718
  enabled: boolean;
2030
3719
  }
2031
3720
 
3721
+ /**
3722
+ * ITraceApi provides an interface definition which is simular to the OpenTelemetry TraceAPI
3723
+ */
3724
+ interface ITraceApi {
3725
+ /**
3726
+ * Returns a Tracer, creating one if one with the given name and version
3727
+ * if one has not already created.
3728
+ *
3729
+ * @param name - The name of the tracer or instrumentation library.
3730
+ * @param version - The version of the tracer or instrumentation library.
3731
+ * @param options - The options of the tracer or instrumentation library.
3732
+ * @returns Tracer A Tracer with the given name and version
3733
+ */
3734
+ getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
3735
+ /**
3736
+ * Wrap the given {@link IDistributedTraceContext} in a new non-recording {@link IReadableSpan}
3737
+ *
3738
+ * @param spanContext - The {@link IDistributedTraceContext} to be wrapped
3739
+ * @returns a new non-recording {@link IReadableSpan} with the provided context
3740
+ */
3741
+ wrapSpanContext(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): IReadableSpan;
3742
+ /**
3743
+ * Returns true if this {@link IDistributedTraceContext} is valid.
3744
+ * @return true if this {@link IDistributedTraceContext} is valid.
3745
+ */
3746
+ isSpanContextValid(spanContext: IDistributedTraceContext | IDistributedTraceInit | IOTelSpanContext): boolean;
3747
+ /**
3748
+ * Gets the span from the current context, if one exists.
3749
+ */
3750
+ getActiveSpan(): IReadableSpan | undefined | null;
3751
+ /**
3752
+ * Set or clear the current active span.
3753
+ * @param span - The span to set as the active span, or null/undefined to clear the active span.
3754
+ * @return An ISpanScope instance returned by the host, or void if there is no defined host.
3755
+ */
3756
+ setActiveSpan(span: IReadableSpan | undefined | null): ISpanScope | undefined | null;
3757
+ }
3758
+
3759
+ /**
3760
+ * Configuration interface for OpenTelemetry compatible tracing functionality.
3761
+ * This interface contains all the settings that control how traces are created,
3762
+ * processed, and managed within the OpenTelemetry system.
3763
+ *
3764
+ * @example
3765
+ * ```typescript
3766
+ * const traceCfg: ITraceCfg = {
3767
+ * serviceName: "my-service",
3768
+ * generalLimits: {
3769
+ * attributeCountLimit: 128,
3770
+ * attributeValueLengthLimit: 4096
3771
+ * },
3772
+ * spanLimits: {
3773
+ * attributeCountLimit: 128,
3774
+ * linkCountLimit: 128,
3775
+ * eventCountLimit: 128
3776
+ * }
3777
+ * };
3778
+ * ```
3779
+ *
3780
+ * @since 3.4.0
3781
+ */
3782
+ interface ITraceCfg {
3783
+ /**
3784
+ * Global attribute limits that apply to all telemetry items.
3785
+ * These limits help prevent excessive memory usage and ensure consistent
3786
+ * behavior across different telemetry types.
3787
+ *
3788
+ * @remarks
3789
+ * These limits are inherited by more specific configurations unless overridden.
3790
+ * For example, spans will use these limits unless `spanLimits` specifies different values.
3791
+ */
3792
+ generalLimits?: IOTelAttributeLimits;
3793
+ /**
3794
+ * The name of the service generating telemetry data.
3795
+ * This name will be included in all telemetry items as a resource attribute.
3796
+ *
3797
+ * @remarks
3798
+ * The service name is crucial for identifying and filtering telemetry data
3799
+ * in observability systems. It should be consistent across all instances
3800
+ * of the same service.
3801
+ *
3802
+ * @example
3803
+ * ```typescript
3804
+ * serviceName: "user-authentication-service"
3805
+ * ```
3806
+ */
3807
+ serviceName?: string;
3808
+ /**
3809
+ * A flag that indicates whether the tracing (creating of a "trace" event) should be suppressed
3810
+ * when a {@link IOTelSpan} ends and the span {@link IOTelSpan#isRecording | isRecording} is true.
3811
+ * This value is also inherited by spans when they are created.
3812
+ */
3813
+ suppressTracing?: boolean;
3814
+ }
3815
+
3816
+ /**
3817
+ * Interface for OpenTelemetry trace operations.
3818
+ * This interface provides span creation, context management, and trace provider operations
3819
+ * that are common across different SDK implementations (Core, AISKU, etc.).
3820
+ *
3821
+ * @since 3.4.0
3822
+ */
3823
+ interface ITraceHost<CfgType extends IConfiguration = IConfiguration> {
3824
+ readonly config: CfgType;
3825
+ /**
3826
+ * Gets the current distributed trace active context for this instance
3827
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true. By default this
3828
+ * will use any located parent as defined by the {@link IConfiguration.traceHdrMode} configuration for each new instance created.
3829
+ */
3830
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
3831
+ /**
3832
+ * Sets the current distributed trace context for this instance if available
3833
+ */
3834
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
3835
+ /**
3836
+ * Start a new span with the given name and optional parent context.
3837
+ *
3838
+ * Note: This method only creates and returns the span. It does not automatically
3839
+ * set the span as the active trace context. Context management should be handled
3840
+ * separately using setTraceCtx() if needed.
3841
+ *
3842
+ * @param name - The name of the span
3843
+ * @param options - Options for creating the span (kind, attributes, startTime)
3844
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
3845
+ * @returns A new span instance, or null if no trace provider is available
3846
+ * @since 3.4.0
3847
+ *
3848
+ * @see {@link IReadableSpan} - Interface for individual spans
3849
+ * @see {@link IOTelSpanOptions} - Configuration options for span creation
3850
+ */
3851
+ startSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan | null;
3852
+ /**
3853
+ * Return the current active span, if no trace provider is available null will be returned
3854
+ * but when a trace provider is available a span instance will always be returned, even if
3855
+ * there is no active span (in which case a non-recording span will be returned).
3856
+ * @param createNew - Optional flag to create a non-recording span if no active span exists, defaults to true.
3857
+ * When false, returns the existing active span or null without creating a non-recording span, which can improve
3858
+ * performance when only checking if an active span exists.
3859
+ * @returns The current active span or null if no trace provider is available or if createNew is false and no active span exists
3860
+ * @since 3.4.0
3861
+ */
3862
+ getActiveSpan(createNew?: boolean): IReadableSpan | null;
3863
+ /**
3864
+ * Set the current Active Span, if no trace provider is available the span will be not be set as the active span.
3865
+ * @param span - The span to set as the active span
3866
+ * @returns An ISpanScope instance that provides the current scope, the span will always be the span passed in
3867
+ * even when no trace provider is available
3868
+ * @since 3.4.0
3869
+ */
3870
+ setActiveSpan(span: IReadableSpan): ISpanScope;
3871
+ /**
3872
+ * Get the current trace provider.
3873
+ *
3874
+ * @returns The current trace provider, or null if none is set
3875
+ * @since 3.4.0
3876
+ */
3877
+ getTraceProvider(): ITraceProvider | null;
3878
+ }
3879
+
3880
+ /**
3881
+ * A trace provider interface that enables different SKUs to provide their own
3882
+ * span implementations while being managed by the core SDK.
3883
+ *
3884
+ * This follows the OpenTelemetry TraceProvider pattern, allowing the core to
3885
+ * delegate span creation to the appropriate implementation based on the SDK variant.
3886
+ *
3887
+ * @since 3.4.0
3888
+ */
3889
+ interface ITraceProvider {
3890
+ /**
3891
+ * The OpenTelemetry API instance associated with this trace provider.
3892
+ * This provides access to the tracer provider and other OpenTelemetry functionality.
3893
+ * @since 3.4.0
3894
+ */
3895
+ readonly api: IOTelApi;
3896
+ /**
3897
+ * Creates a new span with the given name and options.
3898
+ *
3899
+ * @param name - The name of the span
3900
+ * @param options - Options for creating the span (kind, attributes, startTime)
3901
+ * @param parent - Optional parent context. If not provided, uses the current active trace context
3902
+ * @returns A new span instance specific to this provider's implementation
3903
+ * @since 3.4.0
3904
+ */
3905
+ createSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan;
3906
+ /**
3907
+ * Gets the provider identifier for debugging and logging purposes.
3908
+ * @returns A string identifying this trace provider implementation
3909
+ * @since 3.4.0
3910
+ */
3911
+ getProviderId(): string;
3912
+ /**
3913
+ * Determines if this provider is available and ready to create spans.
3914
+ * @returns true if the provider can create spans, false otherwise
3915
+ * @since 3.4.0
3916
+ */
3917
+ isAvailable(): boolean;
3918
+ }
3919
+
2032
3920
  /**
2033
3921
  * An interface which provides automatic removal during unloading of the component
2034
3922
  */
@@ -2048,6 +3936,76 @@ declare namespace ApplicationInsights {
2048
3936
  run: (logger?: IDiagnosticLogger) => void;
2049
3937
  }
2050
3938
 
3939
+ /**
3940
+ * Represents a mutable [W3C trace state list](https://www.w3.org/TR/trace-context/#tracestate-header), this is a
3941
+ * list of key/value pairs that are used to pass trace state information between different tracing systems. The
3942
+ * list is ordered and the order is important as it determines the processing order.
3943
+ *
3944
+ * Importantly instances of this type are mutable, change made to an instance via {@link IW3cTraceState.set} or
3945
+ * {@link IW3cTraceState.del} will be reflected on the instance and any child instances that use it as a parent.
3946
+ * However, any parent instance associated with an instance will not be modified by operations on that particular
3947
+ * instance.
3948
+ *
3949
+ * @since 3.4.0
3950
+ */
3951
+ interface IW3cTraceState {
3952
+ /**
3953
+ * Returns a readonly array of the current keys associated with the trace state, keys are returned in the
3954
+ * required processing order and if this instance has a parent the keys from the parent will be included
3955
+ * unless they have been removed (deleted) from the child instance.
3956
+ * Once created any modifications to the parent will also be reflected in the child, this is different from
3957
+ * the OpenTelemetry implementation which creates a new instance for each call.
3958
+ * @returns A readonly array of the current keys associated with the trace state
3959
+ */
3960
+ readonly keys: string[];
3961
+ /**
3962
+ * Check if the trace state list is empty, meaning it has no keys or values.
3963
+ * This exists to allow for quick checks without needing to create a new array of keys.
3964
+ * @since 3.4.0
3965
+ * @returns true if the trace state list is empty, false otherwise
3966
+ */
3967
+ readonly isEmpty: boolean;
3968
+ /**
3969
+ * Get the value for the specified key that is associated with this instance, either directly or from the parent.
3970
+ * @param key - The key to lookup
3971
+ * @returns The value for the key, or undefined if not found
3972
+ */
3973
+ get(key: string): string | undefined;
3974
+ /**
3975
+ * Set the value for the specified key for this instance, returning its new location within the list.
3976
+ * - 0 is the front of the list
3977
+ * - -1 not set because the key/value pair is invalid
3978
+ * If the key already exists it will be removed from its current location and added to the front of the list. And
3979
+ * if the key was in the parent this will override the value inherited from the parent, more importantly it will
3980
+ * not modify the parent value.
3981
+ * @param key - The key to set
3982
+ * @param value - The value to set
3983
+ * @returns 0 if successful, -1 if not
3984
+ */
3985
+ set(key: string, value: string): number;
3986
+ /**
3987
+ * Delete the specified key from this instance, if the key was in the parent it will be removed (hidden) from
3988
+ * this instance but will still be available directly from the parent.
3989
+ * @param key - The key to delete
3990
+ */
3991
+ del(key: string): void;
3992
+ /**
3993
+ * Format the trace state list into a strings where each string can be used as a header value.
3994
+ * This will return an empty array if the trace state list is empty.
3995
+ * @param maxHeaders - The maximum number of entries to include in the output, once the limit is reached no more entries will be included
3996
+ * @param maxKeys - The maximum number of keys to include in the output, once the limit is reached no more keys will be included
3997
+ * @param maxLen - The maximum length of each header value, once the limit is reached a new header value will be created
3998
+ * @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
3999
+ */
4000
+ hdrs(maxHeaders?: number, maxKeys?: number, maxLen?: number): string[];
4001
+ /**
4002
+ * Create a new instance of IW3cTraceState which is a child of this instance, meaning it will inherit the keys
4003
+ * and values from this instance but any changes made to the child will not affect this instance.
4004
+ * @returns A new instance of IW3cTraceState which is a child of this instance
4005
+ */
4006
+ child(): IW3cTraceState;
4007
+ }
4008
+
2051
4009
  interface IWatchDetails<T = IConfiguration> {
2052
4010
  /**
2053
4011
  * The current config object
@@ -2086,6 +4044,74 @@ declare namespace ApplicationInsights {
2086
4044
 
2087
4045
  type LoggingSeverity = number | eLoggingSeverity;
2088
4046
 
4047
+ /**
4048
+ * Attribute values may be any non-nullish primitive value except an object.
4049
+ *
4050
+ * null or undefined attribute values are invalid and will result in undefined behavior.
4051
+ *
4052
+ * @since 3.4.0
4053
+ */
4054
+ type OTelAttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
4055
+
4056
+ /**
4057
+ * Defines Exception.
4058
+ *
4059
+ * string or an object with one of (message or name or code) and optional stack
4060
+ *
4061
+ * @since 3.4.0
4062
+ */
4063
+ type OTelException = IOTelExceptionWithCode | IOTelExceptionWithMessage | IOTelExceptionWithName | string;
4064
+
4065
+ /**
4066
+ * High-resolution time represented as a tuple of [seconds, nanoseconds].
4067
+ * This is the base type for all OpenTelemetry high-resolution time values.
4068
+ *
4069
+ * @remarks
4070
+ * The first element represents seconds since Unix epoch, and the second element
4071
+ * represents nanoseconds (0-999,999,999) within that second.
4072
+ *
4073
+ * @example
4074
+ * ```typescript
4075
+ * const hrTime: OTelHrTimeBase = [1609459200, 500000000]; // 2021-01-01 00:00:00.5 UTC
4076
+ * ```
4077
+ *
4078
+ * @since 3.4.0
4079
+ */
4080
+ type OTelHrTimeBase = [number, number];
4081
+
4082
+ /**
4083
+ * Creates an enum style object for the OTelSpanKind enum, providing the enum
4084
+ * values as properties of the object as both string and number types.
4085
+ * This allows for easy access to the enum values in a more readable format.
4086
+ */
4087
+ const OTelSpanKind: EnumValue<typeof eOTelSpanKind>;
4088
+
4089
+ type OTelSpanKind = number | eOTelSpanKind;
4090
+
4091
+ /**
4092
+ * Union type representing all valid time input formats accepted by OpenTelemetry APIs.
4093
+ *
4094
+ * @remarks
4095
+ * - `IOTelHrTime`: High-resolution time with nanosecond precision
4096
+ * - `number`: Milliseconds since Unix epoch (JavaScript Date.now() format)
4097
+ * - `Date`: JavaScript Date object
4098
+ *
4099
+ * @example
4100
+ * ```typescript
4101
+ * // All of these are valid time inputs:
4102
+ * const hrTime: OTelTimeInput = [1609459200, 500000000];
4103
+ * const msTime: OTelTimeInput = Date.now();
4104
+ * const dateTime: OTelTimeInput = new Date();
4105
+ *
4106
+ * span.addEvent("event", {}, hrTime);
4107
+ * span.addEvent("event", {}, msTime);
4108
+ * span.addEvent("event", {}, dateTime);
4109
+ * ```
4110
+ *
4111
+ * @since 3.4.0
4112
+ */
4113
+ type OTelTimeInput = IOTelHrTime | number | Date;
4114
+
2089
4115
  /**
2090
4116
  * This defines the handler function for when a promise is rejected.
2091
4117
  * @param value - This is the value passed as part of resolving the Promise