ai-perf-sdk 1.0.0

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/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "ai-perf-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Plug-and-play performance monitoring SDK using OpenTelemetry",
5
+ "license": "MIT",
6
+ "author": "Akash",
7
+ "type": "commonjs",
8
+ "main": "src/index.js",
9
+ "dependencies": {
10
+ "@opentelemetry/sdk-node": "^0.46.0",
11
+ "@opentelemetry/auto-instrumentations-node": "^0.46.0",
12
+ "@opentelemetry/exporter-trace-otlp-http": "^0.46.0"
13
+ }
14
+ }
package/src/config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ serviceName: "unknown-service",
3
+ collectorEndpoint: "http://localhost:3001/otel",
4
+ environment: "production"
5
+ };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ const { startSDK, shutdownSDK } = require("./sdk");
2
+
3
+ module.exports = {
4
+ initPerformanceSDK: startSDK,
5
+ shutdownPerformanceSDK: shutdownSDK
6
+ };
package/src/sdk.js ADDED
@@ -0,0 +1,41 @@
1
+ const { NodeSDK } = require("@opentelemetry/sdk-node");
2
+ const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
3
+ const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-http");
4
+ const defaults = require("./config");
5
+
6
+ let sdkInstance = null;
7
+
8
+ function startSDK(options = {}) {
9
+ if (sdkInstance) return;
10
+
11
+ const config = {
12
+ ...defaults,
13
+ ...options
14
+ };
15
+
16
+ const exporter = new OTLPTraceExporter({
17
+ url: config.collectorEndpoint
18
+ });
19
+
20
+ sdkInstance = new NodeSDK({
21
+ serviceName: config.serviceName,
22
+ traceExporter: exporter,
23
+ instrumentations: [getNodeAutoInstrumentations()]
24
+ });
25
+
26
+ sdkInstance.start();
27
+ console.log(`[AI-PERF] SDK started for ${config.serviceName}`);
28
+ }
29
+
30
+ function shutdownSDK() {
31
+ if (!sdkInstance) return;
32
+
33
+ sdkInstance.shutdown();
34
+ sdkInstance = null;
35
+ console.log("[AI-PERF] SDK shutdown");
36
+ }
37
+
38
+ module.exports = {
39
+ startSDK,
40
+ shutdownSDK
41
+ };