@pingops/sdk 0.1.0 → 0.1.2

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 (44) hide show
  1. package/dist/index.cjs +248 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/{pingops.d.ts → index.d.cts} +12 -14
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.mts +83 -0
  6. package/dist/index.d.mts.map +1 -0
  7. package/dist/index.mjs +246 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +19 -7
  10. package/dist/config.d.ts +0 -7
  11. package/dist/config.d.ts.map +0 -1
  12. package/dist/config.js +0 -5
  13. package/dist/config.js.map +0 -1
  14. package/dist/index.d.ts +0 -6
  15. package/dist/index.d.ts.map +0 -1
  16. package/dist/index.js +0 -5
  17. package/dist/index.js.map +0 -1
  18. package/dist/init-state.d.ts +0 -17
  19. package/dist/init-state.d.ts.map +0 -1
  20. package/dist/init-state.js +0 -22
  21. package/dist/init-state.js.map +0 -1
  22. package/dist/initialize.d.ts +0 -20
  23. package/dist/initialize.d.ts.map +0 -1
  24. package/dist/initialize.js +0 -86
  25. package/dist/initialize.js.map +0 -1
  26. package/dist/instrumentation.d.ts +0 -14
  27. package/dist/instrumentation.d.ts.map +0 -1
  28. package/dist/instrumentation.js +0 -76
  29. package/dist/instrumentation.js.map +0 -1
  30. package/dist/logger.d.ts +0 -25
  31. package/dist/logger.d.ts.map +0 -1
  32. package/dist/logger.js +0 -40
  33. package/dist/logger.js.map +0 -1
  34. package/dist/pingops.d.ts.map +0 -1
  35. package/dist/pingops.js +0 -259
  36. package/dist/pingops.js.map +0 -1
  37. package/dist/span-wrapper.d.ts +0 -60
  38. package/dist/span-wrapper.d.ts.map +0 -1
  39. package/dist/span-wrapper.js +0 -118
  40. package/dist/span-wrapper.js.map +0 -1
  41. package/dist/tracer-provider.d.ts +0 -175
  42. package/dist/tracer-provider.d.ts.map +0 -1
  43. package/dist/tracer-provider.js +0 -537
  44. package/dist/tracer-provider.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["isSdkInitializedFlag","coreWrapHttp"],"sources":["../src/init-state.ts","../src/pingops.ts"],"sourcesContent":["/**\n * Shared state for tracking SDK initialization\n * This module exists to avoid circular dependencies between pingops.ts and instrumentation.ts\n */\n\nlet isSdkInitializedFlag = false;\n\n/**\n * Sets the SDK initialization flag.\n * Called by initializePingops when the SDK is initialized.\n */\nexport function setSdkInitialized(initialized: boolean): void {\n isSdkInitializedFlag = initialized;\n}\n\n/**\n * Checks if global instrumentation is enabled.\n * This is used to determine instrumentation behavior:\n * - If true: all HTTP requests are instrumented\n * - If false: only requests within wrapHttp blocks are instrumented\n */\nexport function isGlobalInstrumentationEnabled(): boolean {\n return isSdkInitializedFlag;\n}\n","/**\n * PingOps SDK singleton for manual instrumentation\n *\n * Provides initializePingops and shutdownPingops functions.\n * wrapHttp is available from @pingops/core and will auto-initialize\n * from environment variables if needed.\n */\n\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport { ATTR_SERVICE_NAME } from \"@opentelemetry/semantic-conventions\";\nimport { NodeTracerProvider } from \"@opentelemetry/sdk-trace-node\";\nimport type { PingopsProcessorConfig } from \"@pingops/otel\";\nimport {\n setPingopsTracerProvider,\n shutdownTracerProvider,\n PingopsSpanProcessor,\n} from \"@pingops/otel\";\nimport { createLogger } from \"@pingops/core\";\nimport {\n setSdkInitialized,\n isGlobalInstrumentationEnabled,\n} from \"./init-state\";\nimport {\n wrapHttp as coreWrapHttp,\n type WrapHttpAttributes,\n} from \"@pingops/core\";\nimport { getPingopsTracerProvider } from \"@pingops/otel\";\nimport { getInstrumentations } from \"@pingops/otel\";\n\nconst initLogger = createLogger(\"[PingOps Initialize]\");\nconst logger = createLogger(\"[PingOps Pingops]\");\n\nlet sdkInstance: NodeSDK | null = null;\nlet isSdkInitializedFlag = false;\n\n/**\n * Global state to track initialization\n */\nlet isInitialized = false;\nlet initializationPromise: Promise<void> | null = null;\n\n/**\n * Initializes PingOps SDK\n *\n * This function:\n * 1. Creates an OpenTelemetry NodeSDK instance\n * 2. Configures Resource with service.name\n * 3. Registers PingopsSpanProcessor\n * 4. Enables HTTP/fetch/GenAI instrumentation\n * 5. Starts the SDK\n *\n * @param config - Configuration for the SDK\n * @param explicit - Whether this is an explicit call (default: true).\n * Set to false when called internally by wrapHttp auto-initialization.\n */\nexport function initializePingops(\n config: PingopsProcessorConfig,\n explicit: boolean = true\n): void {\n if (isSdkInitializedFlag) {\n if (config.debug) {\n initLogger.warn(\"[PingOps] SDK already initialized, skipping\");\n }\n return;\n }\n\n // Create resource with service name\n const resource = resourceFromAttributes({\n [ATTR_SERVICE_NAME]: config.serviceName,\n });\n\n const processor = new PingopsSpanProcessor(config);\n const instrumentations = getInstrumentations(isGlobalInstrumentationEnabled);\n\n // Node.js SDK\n const nodeSdk = new NodeSDK({\n resource,\n spanProcessors: [processor],\n instrumentations,\n });\n\n nodeSdk.start();\n sdkInstance = nodeSdk;\n\n // Mark SDK as initialized\n isSdkInitializedFlag = true;\n\n // Only enable global instrumentation if this was an explicit call\n // If called via wrapHttp auto-initialization, global instrumentation stays disabled\n setSdkInitialized(explicit);\n\n // Initialize isolated TracerProvider for manual spans AFTER NodeSDK starts\n // This ensures manual spans created via startSpan are processed by the same processor\n // We register it after NodeSDK so it takes precedence as the global provider\n try {\n // In version 2.2.0, span processors are passed in the constructor\n const isolatedProvider = new NodeTracerProvider({\n resource,\n spanProcessors: [processor],\n });\n\n // Register the provider globally\n isolatedProvider.register();\n\n // Set it in global state\n setPingopsTracerProvider(isolatedProvider);\n } catch (error) {\n if (config.debug) {\n initLogger.error(\n \"[PingOps] Failed to create isolated TracerProvider:\",\n error instanceof Error ? error.message : String(error)\n );\n }\n // Continue without isolated provider - manual spans will use global provider\n }\n\n if (config.debug) {\n initLogger.info(\"[PingOps] SDK initialized\");\n }\n}\n\n/**\n * Shuts down the SDK and flushes remaining spans\n */\nexport async function shutdownPingops(): Promise<void> {\n // Shutdown isolated TracerProvider first\n await shutdownTracerProvider();\n\n if (!sdkInstance) {\n return;\n }\n\n await sdkInstance.shutdown();\n sdkInstance = null;\n isSdkInitializedFlag = false;\n setSdkInitialized(false);\n}\n\n/**\n * Checks if the SDK is already initialized by checking if a NodeTracerProvider is available\n */\nfunction isSdkInitialized(): boolean {\n try {\n const provider = getPingopsTracerProvider();\n // If we have a NodeTracerProvider (not the default NoOpTracerProvider), SDK is initialized\n const initialized = provider instanceof NodeTracerProvider;\n logger.debug(\"Checked SDK initialization status\", {\n initialized,\n providerType: provider.constructor.name,\n });\n return initialized;\n } catch (error) {\n logger.debug(\"Error checking SDK initialization status\", {\n error: error instanceof Error ? error.message : String(error),\n });\n return false;\n }\n}\n\n/**\n * Auto-initializes the SDK from environment variables if not already initialized\n */\nasync function ensureInitialized(): Promise<void> {\n // Check if SDK is already initialized (e.g., by calling initializePingops directly)\n if (isSdkInitialized()) {\n logger.debug(\"SDK already initialized, skipping auto-initialization\");\n isInitialized = true;\n return;\n }\n\n if (isInitialized) {\n logger.debug(\"SDK initialization flag already set, skipping\");\n return;\n }\n\n // If initialization is in progress, wait for it\n if (initializationPromise) {\n logger.debug(\"SDK initialization already in progress, waiting...\");\n return initializationPromise;\n }\n\n // Start initialization\n logger.info(\"Starting SDK auto-initialization from environment variables\");\n initializationPromise = Promise.resolve().then(() => {\n const apiKey = process.env.PINGOPS_API_KEY;\n const baseUrl = process.env.PINGOPS_BASE_URL;\n const serviceName = process.env.PINGOPS_SERVICE_NAME;\n const debug = process.env.PINGOPS_DEBUG === \"true\";\n\n logger.debug(\"Reading environment variables\", {\n hasApiKey: !!apiKey,\n hasBaseUrl: !!baseUrl,\n hasServiceName: !!serviceName,\n debug,\n });\n\n if (!apiKey || !baseUrl || !serviceName) {\n const missing = [\n !apiKey && \"PINGOPS_API_KEY\",\n !baseUrl && \"PINGOPS_BASE_URL\",\n !serviceName && \"PINGOPS_SERVICE_NAME\",\n ].filter(Boolean);\n\n logger.error(\n \"Missing required environment variables for auto-initialization\",\n {\n missing,\n }\n );\n\n throw new Error(\n `PingOps SDK auto-initialization requires PINGOPS_API_KEY, PINGOPS_BASE_URL, and PINGOPS_SERVICE_NAME environment variables. Missing: ${missing.join(\", \")}`\n );\n }\n\n const config: PingopsProcessorConfig = {\n apiKey,\n baseUrl,\n serviceName,\n debug,\n };\n\n logger.info(\"Initializing SDK with config\", {\n baseUrl,\n serviceName,\n debug,\n });\n\n // Call initializePingops with explicit=false since this is auto-initialization\n initializePingops(config, false);\n isInitialized = true;\n\n logger.info(\"SDK auto-initialization completed successfully\");\n });\n\n try {\n await initializationPromise;\n } catch (error) {\n logger.error(\"SDK auto-initialization failed\", {\n error: error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n initializationPromise = null;\n }\n}\n\n/**\n * Wraps a function to set attributes on HTTP spans created within the wrapped block.\n *\n * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry\n * context, which are automatically propagated to all spans created within the wrapped function.\n *\n * Instrumentation behavior:\n * - If `initializePingops` was called: All HTTP requests are instrumented by default.\n * `wrapHttp` only adds attributes to spans created within the wrapped block.\n * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks\n * are instrumented. Requests outside `wrapHttp` are not instrumented.\n *\n * @param options - Options including attributes to propagate to spans\n * @param fn - Function to execute within the attribute context\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * import { wrapHttp } from '@pingops/sdk';\n *\n * // Scenario 1: initializePingops was called\n * initializePingops({ ... });\n *\n * // All HTTP requests are instrumented, but this block adds attributes\n * const result = await wrapHttp({\n * attributes: {\n * userId: 'user-123',\n * sessionId: 'session-456',\n * tags: ['production', 'api'],\n * metadata: { environment: 'prod', version: '1.0.0' }\n * }\n * }, async () => {\n * // This HTTP request will be instrumented AND have the attributes set above\n * const response = await fetch('https://api.example.com/users/123');\n * return response.json();\n * });\n *\n * // HTTP requests outside wrapHttp are still instrumented, just without the attributes\n * const otherResponse = await fetch('https://api.example.com/other');\n *\n * // Scenario 2: initializePingops was NOT called\n * // Only requests within wrapHttp are instrumented\n * await wrapHttp({\n * attributes: { userId: 'user-123' }\n * }, async () => {\n * // This request IS instrumented\n * return fetch('https://api.example.com/data');\n * });\n *\n * // This request is NOT instrumented (outside wrapHttp)\n * await fetch('https://api.example.com/other');\n * ```\n */\nexport function wrapHttp<T>(\n options: { attributes?: WrapHttpAttributes },\n fn: () => T | Promise<T>\n): T | Promise<T> {\n return coreWrapHttp(\n {\n ...options,\n checkInitialized: isSdkInitialized,\n isGlobalInstrumentationEnabled: isGlobalInstrumentationEnabled,\n ensureInitialized: ensureInitialized,\n },\n fn\n );\n}\n"],"mappings":";;;;;;;;;;;;AAKA,IAAIA,yBAAuB;;;;;AAM3B,SAAgB,kBAAkB,aAA4B;AAC5D,0BAAuB;;;;;;;;AASzB,SAAgB,iCAA0C;AACxD,QAAOA;;;;;;;;;;;;ACQT,MAAM,aAAa,aAAa,uBAAuB;AACvD,MAAM,SAAS,aAAa,oBAAoB;AAEhD,IAAI,cAA8B;AAClC,IAAI,uBAAuB;;;;AAK3B,IAAI,gBAAgB;AACpB,IAAI,wBAA8C;;;;;;;;;;;;;;;AAgBlD,SAAgB,kBACd,QACA,WAAoB,MACd;AACN,KAAI,sBAAsB;AACxB,MAAI,OAAO,MACT,YAAW,KAAK,8CAA8C;AAEhE;;CAIF,MAAM,WAAW,uBAAuB,GACrC,oBAAoB,OAAO,aAC7B,CAAC;CAEF,MAAM,YAAY,IAAI,qBAAqB,OAAO;CAClD,MAAM,mBAAmB,oBAAoB,+BAA+B;CAG5E,MAAM,UAAU,IAAI,QAAQ;EAC1B;EACA,gBAAgB,CAAC,UAAU;EAC3B;EACD,CAAC;AAEF,SAAQ,OAAO;AACf,eAAc;AAGd,wBAAuB;AAIvB,mBAAkB,SAAS;AAK3B,KAAI;EAEF,MAAM,mBAAmB,IAAI,mBAAmB;G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C,aAAa;GACvC,MAAM,UAAU;IACd,CAAC,UAAU;IACX,CAAC,WAAW;IACZ,CAAC,eAAe;IACjB,CAAC,OAAO,QAAQ;AAEjB,UAAO,MACL,kEACA,EACE,SACD,CACF;AAED,SAAM,IAAI,MACR,wIAAwI,QAAQ,KAAK,KAAK,GAC3J;;EAGH,MAAM,SAAiC;GACrC;GACA;GACA;GACA;GACD;AAED,SAAO,KAAK,gCAAgC;GAC1C;GACA;GACA;GACD,CAAC;AAGF,oBAAkB,QAAQ,MAAM;AAChC,kBAAgB;AAEhB,SAAO,KAAK,iDAAiD;GAC7D;AAEF,KAAI;AACF,QAAM;UACC,OAAO;AACd,SAAO,MAAM,kCAAkC,EAC7C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAC9D,CAAC;AACF,QAAM;WACE;AACR,0BAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyD5B,SAAgB,SACd,SACA,IACgB;AAChB,QAAOC,WACL;EACE,GAAG;EACH,kBAAkB;EACc;EACb;EACpB,EACD,GACD"}
package/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "@pingops/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=20"
7
+ },
4
8
  "description": "PingOps SDK for Node.js",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.mts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
7
19
  "files": [
8
20
  "dist",
9
21
  "README.md"
@@ -26,16 +38,16 @@
26
38
  "@opentelemetry/sdk-node": "^0.208.0",
27
39
  "@opentelemetry/sdk-trace-node": "^2.2.0",
28
40
  "@opentelemetry/semantic-conventions": "^1.38.0",
29
- "@pingops/otel": "^0.1.0",
30
- "@pingops/core": "^0.1.0"
41
+ "@pingops/otel": "^0.1.2",
42
+ "@pingops/core": "^0.1.2"
31
43
  },
32
44
  "devDependencies": {
33
45
  "@types/node": "^20.11.0",
34
46
  "typescript": "^5.6.0"
35
47
  },
36
48
  "scripts": {
37
- "build": "tsc",
38
- "dev": "tsc --watch",
49
+ "build": "tsdown",
50
+ "dev": "tsdown --watch",
39
51
  "clean": "rm -rf dist"
40
52
  }
41
53
  }
package/dist/config.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Configuration types for @pingops/sdk
3
- */
4
- import type { PingopsProcessorConfig } from '@pingops/otel';
5
- export interface PingopsInitConfig extends PingopsProcessorConfig {
6
- }
7
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;CAAG"}
package/dist/config.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Configuration types for @pingops/sdk
3
- */
4
- export {};
5
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * @pingops/sdk - Public API
3
- */
4
- export { initializePingops, shutdownPingops, wrapHttp } from "./pingops";
5
- export type { WrapHttpAttributes } from "@pingops/core";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACzE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @pingops/sdk - Public API
3
- */
4
- export { initializePingops, shutdownPingops, wrapHttp } from "./pingops";
5
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Shared state for tracking SDK initialization
3
- * This module exists to avoid circular dependencies between pingops.ts and instrumentation.ts
4
- */
5
- /**
6
- * Sets the SDK initialization flag.
7
- * Called by initializePingops when the SDK is initialized.
8
- */
9
- export declare function setSdkInitialized(initialized: boolean): void;
10
- /**
11
- * Checks if global instrumentation is enabled.
12
- * This is used to determine instrumentation behavior:
13
- * - If true: all HTTP requests are instrumented
14
- * - If false: only requests within wrapHttp blocks are instrumented
15
- */
16
- export declare function isGlobalInstrumentationEnabled(): boolean;
17
- //# sourceMappingURL=init-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init-state.d.ts","sourceRoot":"","sources":["../src/init-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAExD"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Shared state for tracking SDK initialization
3
- * This module exists to avoid circular dependencies between pingops.ts and instrumentation.ts
4
- */
5
- let isSdkInitializedFlag = false;
6
- /**
7
- * Sets the SDK initialization flag.
8
- * Called by initializePingops when the SDK is initialized.
9
- */
10
- export function setSdkInitialized(initialized) {
11
- isSdkInitializedFlag = initialized;
12
- }
13
- /**
14
- * Checks if global instrumentation is enabled.
15
- * This is used to determine instrumentation behavior:
16
- * - If true: all HTTP requests are instrumented
17
- * - If false: only requests within wrapHttp blocks are instrumented
18
- */
19
- export function isGlobalInstrumentationEnabled() {
20
- return isSdkInitializedFlag;
21
- }
22
- //# sourceMappingURL=init-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init-state.js","sourceRoot":"","sources":["../src/init-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,IAAI,oBAAoB,GAAG,KAAK,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAoB;IACpD,oBAAoB,GAAG,WAAW,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Initializes PingOps SDK with OpenTelemetry
3
- */
4
- import type { PingopsProcessorConfig } from '@pingops/otel';
5
- /**
6
- * Initializes PingOps SDK
7
- *
8
- * This function:
9
- * 1. Creates an OpenTelemetry NodeSDK instance
10
- * 2. Configures Resource with service.name
11
- * 3. Registers PingopsSpanProcessor
12
- * 4. Enables HTTP/fetch/GenAI instrumentation
13
- * 5. Starts the SDK
14
- */
15
- export declare function initializePingops(config: PingopsProcessorConfig): void;
16
- /**
17
- * Shuts down the SDK and flushes remaining spans
18
- */
19
- export declare function shutdownPingops(): Promise<void>;
20
- //# sourceMappingURL=initialize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAe5D;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CA4DtE;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAWrD"}
@@ -1,86 +0,0 @@
1
- /**
2
- * Initializes PingOps SDK with OpenTelemetry
3
- */
4
- import { NodeSDK } from '@opentelemetry/sdk-node';
5
- import { resourceFromAttributes } from '@opentelemetry/resources';
6
- import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
7
- import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
8
- import { getInstrumentations } from './instrumentation';
9
- import { setPingopsTracerProvider, shutdownTracerProvider, PingopsSpanProcessor, } from '@pingops/otel';
10
- import { createLogger } from '@pingops/core';
11
- let sdkInstance = null;
12
- let isInitialized = false;
13
- const logger = createLogger('[PingOps Initialize]');
14
- /**
15
- * Initializes PingOps SDK
16
- *
17
- * This function:
18
- * 1. Creates an OpenTelemetry NodeSDK instance
19
- * 2. Configures Resource with service.name
20
- * 3. Registers PingopsSpanProcessor
21
- * 4. Enables HTTP/fetch/GenAI instrumentation
22
- * 5. Starts the SDK
23
- */
24
- export function initializePingops(config) {
25
- if (isInitialized) {
26
- if (config.debug) {
27
- logger.warn('[PingOps] SDK already initialized, skipping');
28
- }
29
- return;
30
- }
31
- // Create resource with service name
32
- const resource = resourceFromAttributes({
33
- [ATTR_SERVICE_NAME]: config.serviceName,
34
- });
35
- // Create PingopsSpanProcessor
36
- const processor = new PingopsSpanProcessor(config);
37
- // Get instrumentations only if autoInstrumentation is enabled (defaults to true)
38
- const autoInstrumentation = config.autoInstrumentation !== false;
39
- const instrumentations = autoInstrumentation ? getInstrumentations() : [];
40
- // Node.js SDK
41
- const nodeSdk = new NodeSDK({
42
- resource,
43
- spanProcessors: [processor],
44
- instrumentations,
45
- });
46
- nodeSdk.start();
47
- sdkInstance = nodeSdk;
48
- // Initialize isolated TracerProvider for manual spans AFTER NodeSDK starts
49
- // This ensures manual spans created via startSpan are processed by the same processor
50
- // We register it after NodeSDK so it takes precedence as the global provider
51
- try {
52
- // In version 2.2.0, span processors are passed in the constructor
53
- const isolatedProvider = new NodeTracerProvider({
54
- resource,
55
- spanProcessors: [processor],
56
- });
57
- // Register the provider globally
58
- isolatedProvider.register();
59
- // Set it in global state
60
- setPingopsTracerProvider(isolatedProvider);
61
- }
62
- catch (error) {
63
- if (config.debug) {
64
- logger.error('[PingOps] Failed to create isolated TracerProvider:', error instanceof Error ? error.message : String(error));
65
- }
66
- // Continue without isolated provider - manual spans will use global provider
67
- }
68
- if (config.debug) {
69
- logger.info('[PingOps] SDK initialized');
70
- }
71
- isInitialized = true;
72
- }
73
- /**
74
- * Shuts down the SDK and flushes remaining spans
75
- */
76
- export async function shutdownPingops() {
77
- // Shutdown isolated TracerProvider first
78
- await shutdownTracerProvider();
79
- if (!sdkInstance) {
80
- return;
81
- }
82
- await sdkInstance.shutdown();
83
- sdkInstance = null;
84
- isInitialized = false;
85
- }
86
- //# sourceMappingURL=initialize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,IAAI,WAAW,GAAmB,IAAI,CAAC;AACvC,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,MAAM,MAAM,GAAG,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA8B;IAC9D,IAAI,aAAa,EAAE,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AAK,CAAC,CACvD,CAAC;QACJ,CAAC;QACD,6EAA6E;IAC/E,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;IAED,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,yCAAyC;IACzC,MAAM,sBAAsB,EAAE,CAAC;IAE/B,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;IACT,CAAC;IAED,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC7B,WAAW,GAAG,IAAI,CAAC;IACnB,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Instrumentation setup for HTTP, fetch, undici, and GenAI
3
- */
4
- import type { Instrumentation } from '@opentelemetry/instrumentation';
5
- /**
6
- * Registers instrumentations for Node.js environment.
7
- * This function is idempotent and can be called multiple times safely.
8
- *
9
- * Instrumentation behavior:
10
- * - If global instrumentation is enabled: all HTTP requests are instrumented
11
- * - If global instrumentation is NOT enabled: only requests within wrapHttp blocks are instrumented
12
- */
13
- export declare function getInstrumentations(): Instrumentation[];
14
- //# sourceMappingURL=instrumentation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,EAAE,CAwEvD"}
@@ -1,76 +0,0 @@
1
- /**
2
- * Instrumentation setup for HTTP, fetch, undici, and GenAI
3
- */
4
- import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
5
- import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
6
- import { registerInstrumentations } from '@opentelemetry/instrumentation';
7
- import { context } from '@opentelemetry/api';
8
- import { PINGOPS_HTTP_ENABLED, normalizeHeaders } from '@pingops/core';
9
- import { isGlobalInstrumentationEnabled } from './init-state';
10
- let installed = false;
11
- /**
12
- * Registers instrumentations for Node.js environment.
13
- * This function is idempotent and can be called multiple times safely.
14
- *
15
- * Instrumentation behavior:
16
- * - If global instrumentation is enabled: all HTTP requests are instrumented
17
- * - If global instrumentation is NOT enabled: only requests within wrapHttp blocks are instrumented
18
- */
19
- export function getInstrumentations() {
20
- if (installed) {
21
- return [];
22
- }
23
- registerInstrumentations({
24
- instrumentations: [
25
- new HttpInstrumentation({
26
- ignoreIncomingRequestHook: () => true, // Only instrument outgoing requests
27
- ignoreOutgoingRequestHook: () => {
28
- // If global instrumentation is enabled, instrument all outgoing requests
29
- if (isGlobalInstrumentationEnabled()) {
30
- return false;
31
- }
32
- // If global instrumentation is NOT enabled, only instrument when PINGOPS_HTTP_ENABLED is true
33
- return context.active().getValue(PINGOPS_HTTP_ENABLED) !== true;
34
- },
35
- requestHook: (span, request) => {
36
- const headers = normalizeHeaders(request.headers);
37
- for (const [key, value] of Object.entries(headers)) {
38
- span.setAttribute(`http.request.header.${key.toLowerCase()}`, Array.isArray(value) ? value.join(',') : String(value));
39
- }
40
- },
41
- responseHook: (span, response) => {
42
- const headers = normalizeHeaders(response.headers);
43
- for (const [key, value] of Object.entries(headers)) {
44
- span.setAttribute(`http.response.header.${key.toLowerCase()}`, Array.isArray(value) ? value.join(',') : String(value));
45
- }
46
- },
47
- }),
48
- new UndiciInstrumentation({
49
- enabled: true,
50
- ignoreRequestHook: () => {
51
- // If global instrumentation is enabled, instrument all requests
52
- if (isGlobalInstrumentationEnabled()) {
53
- return false;
54
- }
55
- // If global instrumentation is NOT enabled, only instrument when PINGOPS_HTTP_ENABLED is true
56
- return context.active().getValue(PINGOPS_HTTP_ENABLED) !== true;
57
- },
58
- requestHook: (span, request) => {
59
- const headers = normalizeHeaders(request.headers);
60
- for (const [key, value] of Object.entries(headers)) {
61
- span.setAttribute(`http.request.header.${key.toLowerCase()}`, Array.isArray(value) ? value.join(',') : String(value));
62
- }
63
- },
64
- responseHook: (span, { response }) => {
65
- const headers = normalizeHeaders(response.headers);
66
- for (const [key, value] of Object.entries(headers)) {
67
- span.setAttribute(`http.response.header.${key.toLowerCase()}`, Array.isArray(value) ? value.join(',') : String(value));
68
- }
69
- },
70
- }),
71
- ],
72
- });
73
- installed = true;
74
- return [];
75
- }
76
- //# sourceMappingURL=instrumentation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAI9D,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wBAAwB,CAAC;QACvB,gBAAgB,EAAE;YAChB,IAAI,mBAAmB,CAAC;gBACtB,yBAAyB,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,oCAAoC;gBAC3E,yBAAyB,EAAE,GAAG,EAAE;oBAC9B,yEAAyE;oBACzE,IAAI,8BAA8B,EAAE,EAAE,CAAC;wBACrC,OAAO,KAAK,CAAC;oBACf,CAAC;oBACD,8FAA8F;oBAC9F,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oBA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,CAAC,QAAQ,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;gBAClE,CAAC;gBACD,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;oBAC7B,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBAElD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;wBACnD,IAAI,CAAC,YAAY,CACf,uBAAuB,GAAG,CAAC,WAAW,EAAE,EAAE,EAC1C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;oBACnC,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBACnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;wBACnD,IAAI,CAAC,YAAY,CACf,wBAAwB,GAAG,CAAC,WAAW,EAAE,EAAE,EAC3C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;oBACJ,CAAC;gBACH,CAAC;aACF,CAAC;SACH;KACF,CAAC,CAAC;IAEH,SAAS,GAAG,IAAI,CAAC;IACjB,OAAO,EAAE,CAAC;AACZ,CAAC"}
package/dist/logger.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Global logger utility for PingOps SDK
3
- *
4
- * Provides consistent logging across all SDK components with support for
5
- * different log levels and debug mode control via PINGOPS_DEBUG environment variable.
6
- */
7
- export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
8
- export interface Logger {
9
- debug(message: string, ...args: unknown[]): void;
10
- info(message: string, ...args: unknown[]): void;
11
- warn(message: string, ...args: unknown[]): void;
12
- error(message: string, ...args: unknown[]): void;
13
- }
14
- /**
15
- * Creates a logger instance with a specific prefix
16
- *
17
- * @param prefix - Prefix to add to all log messages (e.g., '[PingOps TracerProvider]')
18
- * @returns Logger instance
19
- */
20
- export declare function createLogger(prefix: string): Logger;
21
- /**
22
- * Default logger instance for general SDK logging
23
- */
24
- export declare const logger: Logger;
25
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwBnD;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAgC,CAAC"}
package/dist/logger.js DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- * Global logger utility for PingOps SDK
3
- *
4
- * Provides consistent logging across all SDK components with support for
5
- * different log levels and debug mode control via PINGOPS_DEBUG environment variable.
6
- */
7
- /**
8
- * Creates a logger instance with a specific prefix
9
- *
10
- * @param prefix - Prefix to add to all log messages (e.g., '[PingOps TracerProvider]')
11
- * @returns Logger instance
12
- */
13
- export function createLogger(prefix) {
14
- const isDebugEnabled = true;
15
- const formatMessage = (level, message) => {
16
- const timestamp = new Date().toISOString();
17
- return `[${timestamp}] ${prefix} [${level.toUpperCase()}] ${message}`;
18
- };
19
- return {
20
- debug(message, ...args) {
21
- if (isDebugEnabled) {
22
- console.debug(formatMessage('debug', message), ...args);
23
- }
24
- },
25
- info(message, ...args) {
26
- console.log(formatMessage('info', message), ...args);
27
- },
28
- warn(message, ...args) {
29
- console.warn(formatMessage('warn', message), ...args);
30
- },
31
- error(message, ...args) {
32
- console.error(formatMessage('error', message), ...args);
33
- },
34
- };
35
- }
36
- /**
37
- * Default logger instance for general SDK logging
38
- */
39
- export const logger = createLogger('[PingOps SDK]');
40
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,cAAc,GAAG,IAAI,CAAC;IAE5B,MAAM,aAAa,GAAG,CAAC,KAAe,EAAE,OAAe,EAAU,EAAE;QACjE,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,IAAI,SAAS,KAAK,MAAM,KAAK,KAAK,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC;IACxE,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;YACvC,IAAI,cAAc,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YAC1D,CA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