@equinor/fusion-framework-module-analytics 0.1.1
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.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/esm/AnalyticsConfigurator.interface.js +2 -0
- package/dist/esm/AnalyticsConfigurator.interface.js.map +1 -0
- package/dist/esm/AnalyticsConfigurator.js +61 -0
- package/dist/esm/AnalyticsConfigurator.js.map +1 -0
- package/dist/esm/AnalyticsProvider.interface.js +2 -0
- package/dist/esm/AnalyticsProvider.interface.js.map +1 -0
- package/dist/esm/AnalyticsProvider.js +92 -0
- package/dist/esm/AnalyticsProvider.js.map +1 -0
- package/dist/esm/adapters/AnalyticsAdapter.interface.js +2 -0
- package/dist/esm/adapters/AnalyticsAdapter.interface.js.map +1 -0
- package/dist/esm/adapters/ConsoleAnalyticsAdapter.js +12 -0
- package/dist/esm/adapters/ConsoleAnalyticsAdapter.js.map +1 -0
- package/dist/esm/adapters/FusionAnalyticsAdapter.js +42 -0
- package/dist/esm/adapters/FusionAnalyticsAdapter.js.map +1 -0
- package/dist/esm/adapters/index.js +3 -0
- package/dist/esm/adapters/index.js.map +1 -0
- package/dist/esm/collectors/AnalyticsCollector.interface.js +2 -0
- package/dist/esm/collectors/AnalyticsCollector.interface.js.map +1 -0
- package/dist/esm/collectors/AppLoadedCollector.js +42 -0
- package/dist/esm/collectors/AppLoadedCollector.js.map +1 -0
- package/dist/esm/collectors/AppSelectedCollector.js +32 -0
- package/dist/esm/collectors/AppSelectedCollector.js.map +1 -0
- package/dist/esm/collectors/BaseCollector.js +40 -0
- package/dist/esm/collectors/BaseCollector.js.map +1 -0
- package/dist/esm/collectors/ContextSelectedCollector.js +36 -0
- package/dist/esm/collectors/ContextSelectedCollector.js.map +1 -0
- package/dist/esm/collectors/index.js +4 -0
- package/dist/esm/collectors/index.js.map +1 -0
- package/dist/esm/collectors/utils/extractAppMetadata.js +37 -0
- package/dist/esm/collectors/utils/extractAppMetadata.js.map +1 -0
- package/dist/esm/collectors/utils/extractContextMetadata.js +23 -0
- package/dist/esm/collectors/utils/extractContextMetadata.js.map +1 -0
- package/dist/esm/enable-analytics.js +20 -0
- package/dist/esm/enable-analytics.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.js +22 -0
- package/dist/esm/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.js.map +1 -0
- package/dist/esm/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.js +84 -0
- package/dist/esm/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.js.map +1 -0
- package/dist/esm/logExporters/index.js +3 -0
- package/dist/esm/logExporters/index.js.map +1 -0
- package/dist/esm/module.js +28 -0
- package/dist/esm/module.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/AnalyticsConfigurator.d.ts +39 -0
- package/dist/types/AnalyticsConfigurator.interface.d.ts +39 -0
- package/dist/types/AnalyticsProvider.d.ts +45 -0
- package/dist/types/AnalyticsProvider.interface.d.ts +20 -0
- package/dist/types/adapters/AnalyticsAdapter.interface.d.ts +21 -0
- package/dist/types/adapters/ConsoleAnalyticsAdapter.d.ts +9 -0
- package/dist/types/adapters/FusionAnalyticsAdapter.d.ts +19 -0
- package/dist/types/adapters/index.d.ts +3 -0
- package/dist/types/collectors/AnalyticsCollector.interface.d.ts +16 -0
- package/dist/types/collectors/AppLoadedCollector.d.ts +23 -0
- package/dist/types/collectors/AppSelectedCollector.d.ts +21 -0
- package/dist/types/collectors/BaseCollector.d.ts +27 -0
- package/dist/types/collectors/ContextSelectedCollector.d.ts +21 -0
- package/dist/types/collectors/index.d.ts +4 -0
- package/dist/types/collectors/utils/extractAppMetadata.d.ts +17 -0
- package/dist/types/collectors/utils/extractContextMetadata.d.ts +11 -0
- package/dist/types/enable-analytics.d.ts +11 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.d.ts +11 -0
- package/dist/types/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.d.ts +12 -0
- package/dist/types/logExporters/index.d.ts +2 -0
- package/dist/types/module.d.ts +44 -0
- package/dist/types/types.d.ts +22 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +72 -0
- package/src/AnalyticsConfigurator.interface.ts +48 -0
- package/src/AnalyticsConfigurator.ts +116 -0
- package/src/AnalyticsProvider.interface.ts +22 -0
- package/src/AnalyticsProvider.ts +118 -0
- package/src/adapters/AnalyticsAdapter.interface.ts +23 -0
- package/src/adapters/ConsoleAnalyticsAdapter.ts +17 -0
- package/src/adapters/FusionAnalyticsAdapter.ts +61 -0
- package/src/adapters/index.ts +3 -0
- package/src/collectors/AnalyticsCollector.interface.ts +18 -0
- package/src/collectors/AppLoadedCollector.ts +74 -0
- package/src/collectors/AppSelectedCollector.ts +53 -0
- package/src/collectors/BaseCollector.ts +65 -0
- package/src/collectors/ContextSelectedCollector.ts +56 -0
- package/src/collectors/index.ts +4 -0
- package/src/collectors/utils/extractAppMetadata.ts +45 -0
- package/src/collectors/utils/extractContextMetadata.ts +27 -0
- package/src/enable-analytics.ts +27 -0
- package/src/index.ts +11 -0
- package/src/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.ts +41 -0
- package/src/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.ts +89 -0
- package/src/logExporters/index.ts +2 -0
- package/src/module.ts +59 -0
- package/src/types.ts +29 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseConfigBuilder, type ConfigBuilderCallback } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IAnalyticsConfigurator, AnalyticsConfig } from './AnalyticsConfigurator.interface.js';
|
|
3
|
+
import type { IAnalyticsCollector } from './collectors/AnalyticsCollector.interface.js';
|
|
4
|
+
import type { IAnalyticsAdapter } from './adapters/AnalyticsAdapter.interface.js';
|
|
5
|
+
import type { AnalyticsEvent } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configures analytics settings for the module.
|
|
8
|
+
*
|
|
9
|
+
* The `AnalyticsConfigurator` class extends `BaseConfigBuilder` to provide a fluent API for
|
|
10
|
+
* setting up analytics adapters and collectors.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* - Adapters are managed internally and can be set using `setAdapter`.
|
|
14
|
+
* - Collectors are managed internally and can be set using `setCollector`.
|
|
15
|
+
* - All setter methods return `this` for method chaining.
|
|
16
|
+
*
|
|
17
|
+
* @see BaseConfigBuilder
|
|
18
|
+
* @see IAnalyticsConfigurator
|
|
19
|
+
*/
|
|
20
|
+
export declare class AnalyticsConfigurator extends BaseConfigBuilder<AnalyticsConfig> implements IAnalyticsConfigurator {
|
|
21
|
+
#private;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Registers a analytics collector with the configurator.
|
|
25
|
+
*
|
|
26
|
+
* @param identifier - The name of the collector
|
|
27
|
+
* @param callback - A callback function that returns an analytics collector instance
|
|
28
|
+
* @returns The current instance for method chaining
|
|
29
|
+
*/
|
|
30
|
+
setCollector<T extends AnalyticsEvent>(identifier: string, callback: ConfigBuilderCallback<IAnalyticsCollector<T>>): this;
|
|
31
|
+
/**
|
|
32
|
+
* Registers a analytics adapter with the configurator.
|
|
33
|
+
*
|
|
34
|
+
* @param identifier - The name of the adapter
|
|
35
|
+
* @param callback - A callback function that returns an analytics adapter instance
|
|
36
|
+
* @returns The current instance for method chaining
|
|
37
|
+
*/
|
|
38
|
+
setAdapter<T extends AnalyticsEvent>(identifier: string, callback: ConfigBuilderCallback<IAnalyticsAdapter<T>>): this;
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ConfigBuilderCallback } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IAnalyticsCollector } from './collectors/AnalyticsCollector.interface.js';
|
|
3
|
+
import type { IAnalyticsAdapter } from './adapters/AnalyticsAdapter.interface.js';
|
|
4
|
+
import type { AnalyticsEvent } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for setting up analytics within the framework.
|
|
7
|
+
*
|
|
8
|
+
* @property collectors - Record of analytics collectors keyed by identifier to be used for reporting analytics data.
|
|
9
|
+
* @property adapters - Record of analytics adapters keyed by identifier to be used to handle events.
|
|
10
|
+
*/
|
|
11
|
+
export type AnalyticsConfig = {
|
|
12
|
+
collectors: Record<string, IAnalyticsCollector>;
|
|
13
|
+
adapters: Record<string, IAnalyticsAdapter>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Interface for configuring analytics within the module.
|
|
17
|
+
*
|
|
18
|
+
* Provides methods to set analytics adapters and collectors.
|
|
19
|
+
*
|
|
20
|
+
* @interface IAnalyticsConfigurator
|
|
21
|
+
*/
|
|
22
|
+
export interface IAnalyticsConfigurator {
|
|
23
|
+
/**
|
|
24
|
+
* Sets a analytics collector with the given identifier and configuration callback.
|
|
25
|
+
*
|
|
26
|
+
* @param identifier - The unique identifier for the collector.
|
|
27
|
+
* @param callBack - Configuration callback that returns the collector instance.
|
|
28
|
+
* @returns The configurator instance for method chaining.
|
|
29
|
+
*/
|
|
30
|
+
setCollector<T extends AnalyticsEvent>(identifier: string, callBack: ConfigBuilderCallback<IAnalyticsCollector<T>>): this;
|
|
31
|
+
/**
|
|
32
|
+
* Sets a analytics adapter with the given identifier and configuration callback.
|
|
33
|
+
*
|
|
34
|
+
* @param identifier - The unique identifier for the adapter.
|
|
35
|
+
* @param callBack - Configuration callback that returns the adapter instance.
|
|
36
|
+
* @returns The configurator instance for method chaining.
|
|
37
|
+
*/
|
|
38
|
+
setAdapter<T extends AnalyticsEvent>(identifier: string, callback: ConfigBuilderCallback<IAnalyticsAdapter<T>>): this;
|
|
39
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
|
|
2
|
+
import type { AnalyticsConfig } from './AnalyticsConfigurator.interface.js';
|
|
3
|
+
import type { IAnalyticsProvider } from './AnalyticsProvider.interface.js';
|
|
4
|
+
import type { AnalyticsEvent } from './types.js';
|
|
5
|
+
import { type ObservableInput, Subscription } from 'rxjs';
|
|
6
|
+
/**
|
|
7
|
+
* Provides analytics tracking, adapters integration and collectors for application instrumentation.
|
|
8
|
+
*
|
|
9
|
+
* The `AnalyticsProvider` class is responsible for collecting, processing and relaying analytics
|
|
10
|
+
* data to the adapters. The events are collected with collectors.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam AnalyticsConfig - The configuration type for analytics.
|
|
13
|
+
* @implements IAnalyticsProvider
|
|
14
|
+
* @extends BaseModuleProvider<AnalyticsConfig>
|
|
15
|
+
*/
|
|
16
|
+
export declare class AnalyticsProvider extends BaseModuleProvider<AnalyticsConfig> implements IAnalyticsProvider {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(config: AnalyticsConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Initializes the analytics provider with adapters and collectors.
|
|
21
|
+
*
|
|
22
|
+
* This method sets up the provider for operation by:
|
|
23
|
+
* 1. Storing the provided adapters
|
|
24
|
+
* 2. Initializing all adapters
|
|
25
|
+
* 3. Storing the provided collectors
|
|
26
|
+
* 4. Initializing all collectors
|
|
27
|
+
* 5. Setting up subscription for analytics processing
|
|
28
|
+
*
|
|
29
|
+
* @returns A promise that resolves when initialization is complete
|
|
30
|
+
*/
|
|
31
|
+
initialize(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Tracks an analytics event
|
|
34
|
+
*
|
|
35
|
+
* @param event - The analytics event to track
|
|
36
|
+
*/
|
|
37
|
+
trackAnalytic(event: AnalyticsEvent): void;
|
|
38
|
+
/**
|
|
39
|
+
* Uses a analytics stream and returns both Disposable and Subscription for cleanup.
|
|
40
|
+
*
|
|
41
|
+
* @param analytic$ - Observable input stream of analytic events.
|
|
42
|
+
* @returns Object containing both Disposable and Subscription for proper cleanup.
|
|
43
|
+
*/
|
|
44
|
+
trackAnalytic$(analytic$: ObservableInput<AnalyticsEvent>): Disposable & Subscription;
|
|
45
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ObservableInput, Subscription } from 'rxjs';
|
|
2
|
+
import type { AnalyticsEvent } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for analytics providers used to track analytics events.
|
|
5
|
+
*/
|
|
6
|
+
export interface IAnalyticsProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Tracks a analytics event.
|
|
9
|
+
*
|
|
10
|
+
* @param event - The analytic event to track.
|
|
11
|
+
*/
|
|
12
|
+
trackAnalytic(event: AnalyticsEvent): void;
|
|
13
|
+
/**
|
|
14
|
+
* Uses a analytics stream and returns both Disposable and Subscription for cleanup.
|
|
15
|
+
*
|
|
16
|
+
* @param analytic$ - Observable input stream of analytic events.
|
|
17
|
+
* @returns Object containing both Disposable and Subscription for proper cleanup.
|
|
18
|
+
*/
|
|
19
|
+
trackAnalytic$(analytic$: ObservableInput<AnalyticsEvent>): Disposable & Subscription;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AnalyticsEvent } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing an analytics adapter responsible for handling analytics events.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of analytics event handled by the adapter. Defaults to `AnalyticsEvent`.
|
|
6
|
+
*/
|
|
7
|
+
export interface IAnalyticsAdapter<T extends AnalyticsEvent = AnalyticsEvent> extends Disposable {
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the analytics adapter for setup and configuration.
|
|
10
|
+
*
|
|
11
|
+
* @returns Promise that resolves when initialization is complete, or void for synchronous initialization.
|
|
12
|
+
*/
|
|
13
|
+
initialize?(): Promise<void> | void;
|
|
14
|
+
/**
|
|
15
|
+
* Exports analytics event to the configured backend.
|
|
16
|
+
*
|
|
17
|
+
* @param events - Array of analytics events to export.
|
|
18
|
+
* @returns Promise that resolves when export is complete.
|
|
19
|
+
*/
|
|
20
|
+
registerAnalytic(event: T): Promise<void> | void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAnalyticsAdapter } from './AnalyticsAdapter.interface.js';
|
|
2
|
+
import type { AnalyticsEvent } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* An analytics adapter printing the events to the console.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConsoleAnalyticsAdapter<T extends AnalyticsEvent = AnalyticsEvent> implements IAnalyticsAdapter {
|
|
7
|
+
registerAnalytic(event: T): Promise<void> | void;
|
|
8
|
+
[Symbol.dispose](): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IAnalyticsAdapter } from './AnalyticsAdapter.interface.js';
|
|
2
|
+
import type { AnalyticsEvent } from '../types.js';
|
|
3
|
+
import { type ReadableLogRecord } from '@opentelemetry/sdk-logs';
|
|
4
|
+
import type { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';
|
|
5
|
+
/**
|
|
6
|
+
* An analytics adapter for sending events to the log exporter for handling.
|
|
7
|
+
*
|
|
8
|
+
* The exporter is a Open Telemetry exporter.
|
|
9
|
+
* @see OTLPExporterBase
|
|
10
|
+
*/
|
|
11
|
+
export declare class FusionAnalyticsAdapter<T extends AnalyticsEvent = AnalyticsEvent> implements IAnalyticsAdapter {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(args: {
|
|
14
|
+
portalId: string;
|
|
15
|
+
logExporter: OTLPExporterBase<ReadableLogRecord[]>;
|
|
16
|
+
});
|
|
17
|
+
registerAnalytic(event: T): Promise<void> | void;
|
|
18
|
+
[Symbol.dispose](): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Subscribable } from 'rxjs';
|
|
2
|
+
import type { AnalyticsEvent } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing an analytics collector responsible for sending analytics events.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of analytics event handled by the adapter. Defaults to `AnalyticsEvent`.
|
|
7
|
+
*/
|
|
8
|
+
export interface IAnalyticsCollector<T extends AnalyticsEvent = AnalyticsEvent> extends Subscribable<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the analytics collector for setup and configuration.
|
|
11
|
+
* This method is optional - if not implemented, the collector should be directly subscribable.
|
|
12
|
+
*
|
|
13
|
+
* @returns Promise that resolves when initialization is complete, or void for synchronous initialization.
|
|
14
|
+
*/
|
|
15
|
+
initialize?(): Promise<void> | void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseCollector } from './BaseCollector.js';
|
|
2
|
+
import { type AppItemType } from './utils/extractAppMetadata.js';
|
|
3
|
+
import { type ContextItemType } from './utils/extractContextMetadata.js';
|
|
4
|
+
import type { IAnalyticsCollector } from './AnalyticsCollector.interface.js';
|
|
5
|
+
import type { AppModuleProvider } from '@equinor/fusion-framework-module-app';
|
|
6
|
+
import type { IEventModuleProvider } from '@equinor/fusion-framework-module-event';
|
|
7
|
+
import { type ObservableInput } from 'rxjs';
|
|
8
|
+
/**
|
|
9
|
+
* Collector to listen for app loaded and add values and attributes for
|
|
10
|
+
* further processing by adapters.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AppLoadedCollector extends BaseCollector<AppItemType, {
|
|
13
|
+
context?: ContextItemType;
|
|
14
|
+
}> implements IAnalyticsCollector {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(eventProvider: IEventModuleProvider, appProvider: AppModuleProvider);
|
|
17
|
+
_initialize(): ObservableInput<{
|
|
18
|
+
value: AppItemType;
|
|
19
|
+
attributes: {
|
|
20
|
+
context?: ContextItemType;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ObservableInput } from 'rxjs';
|
|
2
|
+
import type { IAnalyticsCollector } from './AnalyticsCollector.interface.js';
|
|
3
|
+
import { BaseCollector } from './BaseCollector.js';
|
|
4
|
+
import { type AppKeyType } from './utils/extractAppMetadata.js';
|
|
5
|
+
import type { AppModuleProvider } from '@equinor/fusion-framework-module-app';
|
|
6
|
+
/**
|
|
7
|
+
* Collector to listen for app selection and add values and attributes for
|
|
8
|
+
* further processing by adapters.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AppSelectedCollector extends BaseCollector<AppKeyType, {
|
|
11
|
+
previous?: AppKeyType;
|
|
12
|
+
}> implements IAnalyticsCollector {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(appProvider: AppModuleProvider);
|
|
15
|
+
_initialize(): ObservableInput<{
|
|
16
|
+
value: AppKeyType;
|
|
17
|
+
attributes: {
|
|
18
|
+
previous?: AppKeyType;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnyValue, AnyValueMap, AnalyticsEvent } from '../types.js';
|
|
2
|
+
import type { IAnalyticsCollector } from './AnalyticsCollector.interface.js';
|
|
3
|
+
import { type ObservableInput, type Observer, type Unsubscribable } from 'rxjs';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Function to create zod schema to be used when collecting
|
|
7
|
+
*/
|
|
8
|
+
export declare const createSchema: <TValue = AnyValue, TAttr = AnyValueMap>(value: z.ZodSchema<TValue>, attributes: z.ZodSchema<TAttr>) => z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
value: z.ZodType<TValue, unknown, z.core.$ZodTypeInternals<TValue, unknown>>;
|
|
11
|
+
attributes: z.ZodOptional<z.ZodType<TAttr, unknown, z.core.$ZodTypeInternals<TAttr, unknown>>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type CollectorSchema<TValue = AnyValue, TAttr = AnyValueMap> = ReturnType<typeof createSchema<TValue, TAttr>>;
|
|
14
|
+
/**
|
|
15
|
+
* A base collector to help with parsing the events with provided schema before
|
|
16
|
+
* emitting.
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class BaseCollector<TValue extends AnyValue, TAttr extends AnyValueMap = AnyValueMap> implements IAnalyticsCollector<AnalyticsEvent<TValue, TAttr>> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(name: string, schema: CollectorSchema<TValue, TAttr>);
|
|
21
|
+
abstract _initialize(): ObservableInput<{
|
|
22
|
+
value: TValue;
|
|
23
|
+
attributes: TAttr;
|
|
24
|
+
}>;
|
|
25
|
+
initialize(): Promise<void> | void;
|
|
26
|
+
subscribe(observer: Partial<Observer<z.infer<CollectorSchema<TValue, TAttr>>>>): Unsubscribable;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ObservableInput } from 'rxjs';
|
|
2
|
+
import type { IAnalyticsCollector } from './AnalyticsCollector.interface.js';
|
|
3
|
+
import type { IContextProvider } from '@equinor/fusion-framework-module-context';
|
|
4
|
+
import { BaseCollector } from './BaseCollector.js';
|
|
5
|
+
import { type ContextItemType } from './utils/extractContextMetadata.js';
|
|
6
|
+
/**
|
|
7
|
+
* Collector to listen for context changes and add values and attributes for
|
|
8
|
+
* further processing by adapters.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ContextSelectedCollector extends BaseCollector<ContextItemType, {
|
|
11
|
+
previous?: ContextItemType;
|
|
12
|
+
}> implements IAnalyticsCollector {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(contextProvider: IContextProvider);
|
|
15
|
+
_initialize(): ObservableInput<{
|
|
16
|
+
value: ContextItemType;
|
|
17
|
+
attributes: {
|
|
18
|
+
previous?: ContextItemType;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { IAnalyticsCollector } from './AnalyticsCollector.interface.js';
|
|
2
|
+
export { ContextSelectedCollector } from './ContextSelectedCollector.js';
|
|
3
|
+
export { AppSelectedCollector } from './AppSelectedCollector.js';
|
|
4
|
+
export { AppLoadedCollector } from './AppLoadedCollector.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { AppManifest, CurrentApp } from '@equinor/fusion-framework-module-app';
|
|
3
|
+
export declare const appKeySchema: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
4
|
+
appKey: z.ZodOptional<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>>>;
|
|
6
|
+
export declare const appSchema: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
appKey: z.ZodString;
|
|
8
|
+
displayName: z.ZodString;
|
|
9
|
+
type: z.ZodString;
|
|
10
|
+
categoryName: z.ZodOptional<z.ZodString>;
|
|
11
|
+
buildVersion: z.ZodOptional<z.ZodString>;
|
|
12
|
+
buildTag: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
export type AppKeyType = z.infer<typeof appKeySchema>;
|
|
15
|
+
export type AppItemType = z.infer<typeof appSchema>;
|
|
16
|
+
export declare const extractAppKeyMetadata: (app: CurrentApp) => z.input<typeof appKeySchema>;
|
|
17
|
+
export declare const extractAppMetadata: (app: AppManifest) => z.input<typeof appSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ContextItem } from '@equinor/fusion-framework-module-context';
|
|
3
|
+
export declare const contextSchema: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
type: z.ZodString;
|
|
6
|
+
title: z.ZodOptional<z.ZodString>;
|
|
7
|
+
externalId: z.ZodOptional<z.ZodString>;
|
|
8
|
+
source: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>>>;
|
|
10
|
+
export type ContextItemType = z.infer<typeof contextSchema>;
|
|
11
|
+
export declare const extractContextMetadata: (context: ContextItem) => z.input<typeof contextSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IAnalyticsConfigurator } from './AnalyticsConfigurator.interface.js';
|
|
3
|
+
type AnalyticsBuilderCallback = (builder: IAnalyticsConfigurator) => void | Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Enables analytics for agiven module configurator.
|
|
6
|
+
*
|
|
7
|
+
* @param configurator - The module configurator instance to which analytics should be attached.
|
|
8
|
+
* @param callback - An optional callback to further configure the analytics builder. Can be synchronous or asynchronous.
|
|
9
|
+
*/
|
|
10
|
+
export declare const enableAnalytics: (configurator: IModulesConfigurator<any, any>, callback?: AnalyticsBuilderCallback) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { module as analyticsModule, AnalyticsModule } from './module.js';
|
|
2
|
+
export { AnalyticsEvent } from './types.js';
|
|
3
|
+
export { AnalyticsProvider } from './AnalyticsProvider.js';
|
|
4
|
+
export { IAnalyticsProvider } from './AnalyticsProvider.interface.js';
|
|
5
|
+
export { AnalyticsConfig, IAnalyticsConfigurator } from './AnalyticsConfigurator.interface.js';
|
|
6
|
+
export { AnalyticsConfigurator } from './AnalyticsConfigurator.js';
|
|
7
|
+
export { enableAnalytics } from './enable-analytics.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
|
|
2
|
+
import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';
|
|
3
|
+
import type { IHttpClient } from '@equinor/fusion-framework-module-http';
|
|
4
|
+
/**
|
|
5
|
+
* A log exporter extending OTLPExporterBase but substitute the normal transport
|
|
6
|
+
* with a HttpClientExporterTransport. This will use the provided httpClient to
|
|
7
|
+
* emit the event.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FusionOTLPLogExporter extends OTLPExporterBase<ReadableLogRecord[]> implements LogRecordExporter {
|
|
10
|
+
constructor(httpClient: IHttpClient);
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IExporterTransport, ExportResponse } from '@opentelemetry/otlp-exporter-base';
|
|
2
|
+
import type { IHttpClient } from '@equinor/fusion-framework-module-http';
|
|
3
|
+
/**
|
|
4
|
+
* A Exporter Transport to POST events to provided path using the provided httpClient
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpClientExporterTransport implements IExporterTransport {
|
|
7
|
+
private httpClient;
|
|
8
|
+
private path;
|
|
9
|
+
constructor(httpClient: IHttpClient, path?: string);
|
|
10
|
+
send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse>;
|
|
11
|
+
shutdown(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Module } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IAnalyticsConfigurator } from './AnalyticsConfigurator.interface.js';
|
|
3
|
+
import type { IAnalyticsProvider } from './AnalyticsProvider.interface.js';
|
|
4
|
+
import { AnalyticsConfigurator } from './AnalyticsConfigurator.js';
|
|
5
|
+
/**
|
|
6
|
+
* Representes the Analytics module within the framework.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This type defines a module names `analytics` that integrates with the framwork's module system.
|
|
10
|
+
* It specifies the provider and configurator interfaces for analytics functionality, and declares
|
|
11
|
+
* its dependencies on itself (`AnalyticsModule`).
|
|
12
|
+
*
|
|
13
|
+
* @typeParam IAnalyticsProvider - The interface for the analytics provider implementation.
|
|
14
|
+
* @typeParam IAnalyticsConfigurator - The interface for configuring analytics behavior.
|
|
15
|
+
* @typeParam AnalyticsModule - Self-reference to allow for recursive or hierarchical module composition.
|
|
16
|
+
*/
|
|
17
|
+
export type AnalyticsModule = Module<'analytics', IAnalyticsProvider, IAnalyticsConfigurator, [
|
|
18
|
+
AnalyticsModule
|
|
19
|
+
]>;
|
|
20
|
+
/**
|
|
21
|
+
* Analytics module definition for the Fusion Framework.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This module provides analytics capabilities by configuring and initializing a analytics provider.
|
|
25
|
+
*
|
|
26
|
+
* @type {AnalyticsModule}
|
|
27
|
+
*
|
|
28
|
+
* @property {string} name - The name of the module ('analytics').
|
|
29
|
+
* @property {() => AnalyticsConfigurator} configure - Factory function to create a new AnalyticsConfigurator instance.
|
|
30
|
+
* @property {(args) => Promise<IAnalyticsProvider>} initialize - Asynchronous initializer that creates and returns a AnalyticsProvider.
|
|
31
|
+
* - @param args - Initialization arguments, including configuration and module dependencies.
|
|
32
|
+
* - @returns A promise that resolves to an instance of IAnalyticsProvider.
|
|
33
|
+
*/
|
|
34
|
+
export declare const module: {
|
|
35
|
+
name: "analytics";
|
|
36
|
+
configure: () => AnalyticsConfigurator;
|
|
37
|
+
initialize: (args: import("@equinor/fusion-framework-module").ModuleInitializerArgs<IAnalyticsConfigurator, [AnalyticsModule]>) => Promise<IAnalyticsProvider>;
|
|
38
|
+
};
|
|
39
|
+
export default module;
|
|
40
|
+
declare module '@equinor/fusion-framework-module' {
|
|
41
|
+
interface Modules {
|
|
42
|
+
analytics: AnalyticsModule;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type AnyValueScalar = string | number | boolean;
|
|
2
|
+
export type AnyValueArray = Array<AnyValue>;
|
|
3
|
+
/**
|
|
4
|
+
* AnyValueMap is a map from string to AnyValue (attribute value or a nested map)
|
|
5
|
+
*/
|
|
6
|
+
export interface AnyValueMap {
|
|
7
|
+
[attributeKey: string]: AnyValue;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* AnyValue can be one of the following:
|
|
11
|
+
* - a scalar value
|
|
12
|
+
* - a byte array
|
|
13
|
+
* - array of any value
|
|
14
|
+
* - map from string to any value
|
|
15
|
+
* - empty value
|
|
16
|
+
*/
|
|
17
|
+
export type AnyValue = AnyValueScalar | Uint8Array | AnyValueArray | AnyValueMap | null | undefined;
|
|
18
|
+
export type AnalyticsEvent<TValue extends AnyValue = AnyValue, TAttr extends AnyValueMap = AnyValueMap> = {
|
|
19
|
+
name: string;
|
|
20
|
+
value: TValue;
|
|
21
|
+
attributes?: TAttr;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.1.1";
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-framework-module-analytics",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Fusion module for collecting and exporting application analytics using OpenTelemetry standards",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/esm/index.js",
|
|
10
|
+
"types": "./dist/types/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./adapters": {
|
|
13
|
+
"import": "./dist/esm/adapters/index.js",
|
|
14
|
+
"types": "./dist/types/adapters/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./collectors": {
|
|
17
|
+
"import": "./dist/esm/collectors/index.js",
|
|
18
|
+
"types": "./dist/types/collectors/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./logExporters": {
|
|
21
|
+
"import": "./dist/esm/logExporters/index.js",
|
|
22
|
+
"types": "./dist/types/logExporters/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "dist/types/index.d.ts",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"analytics",
|
|
28
|
+
"fusion",
|
|
29
|
+
"utility"
|
|
30
|
+
],
|
|
31
|
+
"author": "",
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/equinor/fusion-framework.git",
|
|
39
|
+
"directory": "packages/modules/analytics"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@opentelemetry/api-logs": "^0.207.0",
|
|
43
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.207.0",
|
|
44
|
+
"@opentelemetry/otlp-exporter-base": "^0.207.0",
|
|
45
|
+
"@opentelemetry/otlp-transformer": "^0.208.0",
|
|
46
|
+
"@opentelemetry/resources": "^2.2.0",
|
|
47
|
+
"@opentelemetry/sdk-logs": "^0.207.0",
|
|
48
|
+
"deepmerge": "^4.3.1",
|
|
49
|
+
"rxjs": "^7.8.1",
|
|
50
|
+
"uuid": "^13.0.0",
|
|
51
|
+
"zod": "^4.1.11",
|
|
52
|
+
"@equinor/fusion-framework-module": "^5.0.5",
|
|
53
|
+
"@equinor/fusion-framework-module-event": "^4.4.0",
|
|
54
|
+
"@equinor/fusion-framework-module-http": "^7.0.5",
|
|
55
|
+
"@equinor/fusion-framework-module-app": "^7.2.1",
|
|
56
|
+
"@equinor/fusion-framework-module-context": "^7.0.2"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"typescript": "^5.8.2",
|
|
60
|
+
"vitest": "^3.2.4",
|
|
61
|
+
"@equinor/fusion-observable": "^8.5.7"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@equinor/fusion-framework-module": "^5.0.5",
|
|
65
|
+
"@equinor/fusion-framework-module-event": "^4.4.0",
|
|
66
|
+
"@equinor/fusion-observable": "^8.5.7"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsc -b",
|
|
70
|
+
"test": "vitest"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ConfigBuilderCallback } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { IAnalyticsCollector } from './collectors/AnalyticsCollector.interface.js';
|
|
3
|
+
import type { IAnalyticsAdapter } from './adapters/AnalyticsAdapter.interface.js';
|
|
4
|
+
import type { AnalyticsEvent } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for setting up analytics within the framework.
|
|
8
|
+
*
|
|
9
|
+
* @property collectors - Record of analytics collectors keyed by identifier to be used for reporting analytics data.
|
|
10
|
+
* @property adapters - Record of analytics adapters keyed by identifier to be used to handle events.
|
|
11
|
+
*/
|
|
12
|
+
export type AnalyticsConfig = {
|
|
13
|
+
collectors: Record<string, IAnalyticsCollector>;
|
|
14
|
+
adapters: Record<string, IAnalyticsAdapter>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Interface for configuring analytics within the module.
|
|
19
|
+
*
|
|
20
|
+
* Provides methods to set analytics adapters and collectors.
|
|
21
|
+
*
|
|
22
|
+
* @interface IAnalyticsConfigurator
|
|
23
|
+
*/
|
|
24
|
+
export interface IAnalyticsConfigurator {
|
|
25
|
+
/**
|
|
26
|
+
* Sets a analytics collector with the given identifier and configuration callback.
|
|
27
|
+
*
|
|
28
|
+
* @param identifier - The unique identifier for the collector.
|
|
29
|
+
* @param callBack - Configuration callback that returns the collector instance.
|
|
30
|
+
* @returns The configurator instance for method chaining.
|
|
31
|
+
*/
|
|
32
|
+
setCollector<T extends AnalyticsEvent>(
|
|
33
|
+
identifier: string,
|
|
34
|
+
callBack: ConfigBuilderCallback<IAnalyticsCollector<T>>,
|
|
35
|
+
): this;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets a analytics adapter with the given identifier and configuration callback.
|
|
39
|
+
*
|
|
40
|
+
* @param identifier - The unique identifier for the adapter.
|
|
41
|
+
* @param callBack - Configuration callback that returns the adapter instance.
|
|
42
|
+
* @returns The configurator instance for method chaining.
|
|
43
|
+
*/
|
|
44
|
+
setAdapter<T extends AnalyticsEvent>(
|
|
45
|
+
identifier: string,
|
|
46
|
+
callback: ConfigBuilderCallback<IAnalyticsAdapter<T>>,
|
|
47
|
+
): this;
|
|
48
|
+
}
|