@pingops/core 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 (53) hide show
  1. package/dist/index.cjs +824 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +306 -0
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.mts +306 -0
  6. package/dist/index.d.mts.map +1 -0
  7. package/dist/index.mjs +804 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +17 -5
  10. package/dist/context-keys.d.ts +0 -30
  11. package/dist/context-keys.d.ts.map +0 -1
  12. package/dist/context-keys.js +0 -31
  13. package/dist/context-keys.js.map +0 -1
  14. package/dist/filtering/domain-filter.d.ts +0 -9
  15. package/dist/filtering/domain-filter.d.ts.map +0 -1
  16. package/dist/filtering/domain-filter.js +0 -136
  17. package/dist/filtering/domain-filter.js.map +0 -1
  18. package/dist/filtering/header-filter.d.ts +0 -31
  19. package/dist/filtering/header-filter.d.ts.map +0 -1
  20. package/dist/filtering/header-filter.js +0 -187
  21. package/dist/filtering/header-filter.js.map +0 -1
  22. package/dist/filtering/span-filter.d.ts +0 -13
  23. package/dist/filtering/span-filter.d.ts.map +0 -1
  24. package/dist/filtering/span-filter.js +0 -46
  25. package/dist/filtering/span-filter.js.map +0 -1
  26. package/dist/index.d.ts +0 -13
  27. package/dist/index.d.ts.map +0 -1
  28. package/dist/index.js +0 -13
  29. package/dist/index.js.map +0 -1
  30. package/dist/logger.d.ts +0 -21
  31. package/dist/logger.d.ts.map +0 -1
  32. package/dist/logger.js +0 -36
  33. package/dist/logger.js.map +0 -1
  34. package/dist/transport/client.d.ts +0 -46
  35. package/dist/transport/client.d.ts.map +0 -1
  36. package/dist/transport/client.js +0 -110
  37. package/dist/transport/client.js.map +0 -1
  38. package/dist/types.d.ts +0 -34
  39. package/dist/types.d.ts.map +0 -1
  40. package/dist/types.js +0 -5
  41. package/dist/types.js.map +0 -1
  42. package/dist/utils/context-extractor.d.ts +0 -13
  43. package/dist/utils/context-extractor.d.ts.map +0 -1
  44. package/dist/utils/context-extractor.js +0 -44
  45. package/dist/utils/context-extractor.js.map +0 -1
  46. package/dist/utils/span-extractor.d.ts +0 -10
  47. package/dist/utils/span-extractor.d.ts.map +0 -1
  48. package/dist/utils/span-extractor.js +0 -125
  49. package/dist/utils/span-extractor.js.map +0 -1
  50. package/dist/wrap-http.d.ts +0 -55
  51. package/dist/wrap-http.d.ts.map +0 -1
  52. package/dist/wrap-http.js +0 -129
  53. package/dist/wrap-http.js.map +0 -1
@@ -1,55 +0,0 @@
1
- /**
2
- * wrapHttp - Wraps a function to set attributes on HTTP spans created within the wrapped block.
3
- *
4
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
5
- * context, which are automatically propagated to all spans created within the wrapped function.
6
- *
7
- * Instrumentation behavior:
8
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
9
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
10
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
11
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
12
- */
13
- import type { WrapHttpAttributes } from "./types";
14
- /**
15
- * Options for wrapHttp function
16
- */
17
- export interface WrapHttpOptions {
18
- attributes?: WrapHttpAttributes;
19
- /**
20
- * Callback to check if SDK is initialized.
21
- * Required to determine if global instrumentation is enabled.
22
- */
23
- checkInitialized: () => boolean;
24
- /**
25
- * Callback to check if global instrumentation is enabled.
26
- * Required to determine instrumentation behavior.
27
- */
28
- isGlobalInstrumentationEnabled: () => boolean;
29
- /**
30
- * Optional callback to ensure SDK is initialized (auto-initialization).
31
- * If not provided, wrapHttp will try to auto-initialize from environment variables.
32
- */
33
- ensureInitialized?: () => Promise<void>;
34
- }
35
- /**
36
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
37
- *
38
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
39
- * context, which are automatically propagated to all spans created within the wrapped function.
40
- *
41
- * Instrumentation behavior:
42
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
43
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
44
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
45
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
46
- *
47
- * Note: This is the low-level API. For a simpler API with automatic setup,
48
- * use `wrapHttp` from `@pingops/sdk` instead.
49
- *
50
- * @param options - Options including attributes and required callbacks
51
- * @param fn - Function to execute within the attribute context
52
- * @returns The result of the function
53
- */
54
- export declare function wrapHttp<T>(options: WrapHttpOptions, fn: () => T | Promise<T>): T | Promise<T>;
55
- //# sourceMappingURL=wrap-http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap-http.d.ts","sourceRoot":"","sources":["../src/wrap-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC;;;OAGG;IACH,gBAAgB,EAAE,MAAM,OAAO,CAAC;IAChC;;;OAGG;IACH,8BAA8B,EAAE,MAAM,OAAO,CAAC;IAC9C;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,OAAO,EAAE,eAAe,EACxB,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAoDhB"}
package/dist/wrap-http.js DELETED
@@ -1,129 +0,0 @@
1
- /**
2
- * wrapHttp - Wraps a function to set attributes on HTTP spans created within the wrapped block.
3
- *
4
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
5
- * context, which are automatically propagated to all spans created within the wrapped function.
6
- *
7
- * Instrumentation behavior:
8
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
9
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
10
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
11
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
12
- */
13
- import { context } from "@opentelemetry/api";
14
- import { createLogger } from "./logger";
15
- import { PINGOPS_HTTP_ENABLED, PINGOPS_USER_ID, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_METADATA, } from "./context-keys";
16
- const logger = createLogger("[PingOps wrapHttp]");
17
- /**
18
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
19
- *
20
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
21
- * context, which are automatically propagated to all spans created within the wrapped function.
22
- *
23
- * Instrumentation behavior:
24
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
25
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
26
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
27
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
28
- *
29
- * Note: This is the low-level API. For a simpler API with automatic setup,
30
- * use `wrapHttp` from `@pingops/sdk` instead.
31
- *
32
- * @param options - Options including attributes and required callbacks
33
- * @param fn - Function to execute within the attribute context
34
- * @returns The result of the function
35
- */
36
- export function wrapHttp(options, fn) {
37
- logger.debug("wrapHttp called", {
38
- hasAttributes: !!options.attributes,
39
- hasUserId: !!options.attributes?.userId,
40
- hasSessionId: !!options.attributes?.sessionId,
41
- hasTags: !!options.attributes?.tags,
42
- hasMetadata: !!options.attributes?.metadata,
43
- });
44
- // Normalize options - if just attributes provided, it means callbacks are required
45
- // This is a type error at compile time, but we handle it gracefully
46
- const normalizedOptions = "checkInitialized" in options && "isGlobalInstrumentationEnabled" in options
47
- ? options
48
- : (() => {
49
- throw new Error("wrapHttp requires checkInitialized and isGlobalInstrumentationEnabled callbacks. Use wrapHttp from @pingops/sdk for automatic setup.");
50
- })();
51
- const { checkInitialized, ensureInitialized } = normalizedOptions;
52
- // Ensure SDK is initialized so that span processor can extract attributes
53
- // If already initialized, execute synchronously
54
- if (checkInitialized()) {
55
- logger.debug("SDK already initialized, executing wrapHttp synchronously");
56
- return executeWrapHttpWithContext(normalizedOptions, fn);
57
- }
58
- // If not initialized, we need to initialize first (async)
59
- if (ensureInitialized) {
60
- logger.debug("SDK not initialized, using provided ensureInitialized callback");
61
- return ensureInitialized()
62
- .then(() => {
63
- logger.debug("SDK initialized, executing wrapHttp");
64
- return executeWrapHttpWithContext(normalizedOptions, fn);
65
- })
66
- .catch((error) => {
67
- logger.error("Failed to initialize SDK for wrapHttp", {
68
- error: error instanceof Error ? error.message : String(error),
69
- });
70
- throw error;
71
- });
72
- }
73
- // No ensureInitialized callback provided, execute without initialization
74
- logger.debug("SDK not initialized and no ensureInitialized callback provided, executing wrapHttp");
75
- return executeWrapHttpWithContext(normalizedOptions, fn);
76
- }
77
- function executeWrapHttpWithContext(options, fn) {
78
- const { attributes, isGlobalInstrumentationEnabled } = options;
79
- const globalInstrumentationEnabled = isGlobalInstrumentationEnabled();
80
- logger.debug("Executing wrapHttp context", {
81
- hasAttributes: !!attributes,
82
- globalInstrumentationEnabled,
83
- });
84
- const activeContext = context.active();
85
- // If global instrumentation is not enabled, enable HTTP instrumentation
86
- // for this block only. If it's enabled, all requests are already instrumented.
87
- let contextWithAttributes = activeContext;
88
- if (!globalInstrumentationEnabled) {
89
- contextWithAttributes = contextWithAttributes.setValue(PINGOPS_HTTP_ENABLED, true);
90
- }
91
- // Set attributes in context if provided
92
- // These will be propagated to all spans created within the wrapped function
93
- if (attributes) {
94
- if (attributes.userId !== undefined) {
95
- contextWithAttributes = contextWithAttributes.setValue(PINGOPS_USER_ID, attributes.userId);
96
- }
97
- if (attributes.sessionId !== undefined) {
98
- contextWithAttributes = contextWithAttributes.setValue(PINGOPS_SESSION_ID, attributes.sessionId);
99
- }
100
- if (attributes.tags !== undefined) {
101
- contextWithAttributes = contextWithAttributes.setValue(PINGOPS_TAGS, attributes.tags);
102
- }
103
- if (attributes.metadata !== undefined) {
104
- contextWithAttributes = contextWithAttributes.setValue(PINGOPS_METADATA, attributes.metadata);
105
- }
106
- }
107
- // Run user code inside the context with attributes
108
- return context.with(contextWithAttributes, () => {
109
- try {
110
- const result = fn();
111
- if (result instanceof Promise) {
112
- return result.catch((err) => {
113
- logger.error("Error in wrapHttp async execution", {
114
- error: err instanceof Error ? err.message : String(err),
115
- });
116
- throw err;
117
- });
118
- }
119
- return result;
120
- }
121
- catch (err) {
122
- logger.error("Error in wrapHttp sync execution", {
123
- error: err instanceof Error ? err.message : String(err),
124
- });
125
- throw err;
126
- }
127
- });
128
- }
129
- //# sourceMappingURL=wrap-http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap-http.js","sourceRoot":"","sources":["../src/wrap-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAwBlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAwB,EACxB,EAAwB;IAExB,MAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE;QAC9B,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU;QACnC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM;QACvC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS;QAC7C,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,E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