@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.
- package/dist/index.cjs +824 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +306 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +306 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +804 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +17 -5
- package/dist/context-keys.d.ts +0 -30
- package/dist/context-keys.d.ts.map +0 -1
- package/dist/context-keys.js +0 -31
- package/dist/context-keys.js.map +0 -1
- package/dist/filtering/domain-filter.d.ts +0 -9
- package/dist/filtering/domain-filter.d.ts.map +0 -1
- package/dist/filtering/domain-filter.js +0 -136
- package/dist/filtering/domain-filter.js.map +0 -1
- package/dist/filtering/header-filter.d.ts +0 -31
- package/dist/filtering/header-filter.d.ts.map +0 -1
- package/dist/filtering/header-filter.js +0 -187
- package/dist/filtering/header-filter.js.map +0 -1
- package/dist/filtering/span-filter.d.ts +0 -13
- package/dist/filtering/span-filter.d.ts.map +0 -1
- package/dist/filtering/span-filter.js +0 -46
- package/dist/filtering/span-filter.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -13
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -21
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -36
- package/dist/logger.js.map +0 -1
- package/dist/transport/client.d.ts +0 -46
- package/dist/transport/client.d.ts.map +0 -1
- package/dist/transport/client.js +0 -110
- package/dist/transport/client.js.map +0 -1
- package/dist/types.d.ts +0 -34
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils/context-extractor.d.ts +0 -13
- package/dist/utils/context-extractor.d.ts.map +0 -1
- package/dist/utils/context-extractor.js +0 -44
- package/dist/utils/context-extractor.js.map +0 -1
- package/dist/utils/span-extractor.d.ts +0 -10
- package/dist/utils/span-extractor.d.ts.map +0 -1
- package/dist/utils/span-extractor.js +0 -125
- package/dist/utils/span-extractor.js.map +0 -1
- package/dist/wrap-http.d.ts +0 -55
- package/dist/wrap-http.d.ts.map +0 -1
- package/dist/wrap-http.js +0 -129
- package/dist/wrap-http.js.map +0 -1
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Span filtering logic - determines if a span is eligible for capture
|
|
3
|
-
*/
|
|
4
|
-
import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
5
|
-
/**
|
|
6
|
-
* Checks if a span is eligible for capture based on span kind and attributes.
|
|
7
|
-
* A span is eligible if:
|
|
8
|
-
* 1. span.kind === SpanKind.CLIENT
|
|
9
|
-
* 2. AND has HTTP attributes (http.method, http.url, or server.address)
|
|
10
|
-
* OR has GenAI attributes (gen_ai.system, gen_ai.operation.name)
|
|
11
|
-
*/
|
|
12
|
-
export declare function isSpanEligible(span: ReadableSpan): boolean;
|
|
13
|
-
//# sourceMappingURL=span-filter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-filter.d.ts","sourceRoot":"","sources":["../../src/filtering/span-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAKlE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAqC1D"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Span filtering logic - determines if a span is eligible for capture
|
|
3
|
-
*/
|
|
4
|
-
import { SpanKind } from "@opentelemetry/api";
|
|
5
|
-
import { createLogger } from "../logger";
|
|
6
|
-
const log = createLogger("[PingOps SpanFilter]");
|
|
7
|
-
/**
|
|
8
|
-
* Checks if a span is eligible for capture based on span kind and attributes.
|
|
9
|
-
* A span is eligible if:
|
|
10
|
-
* 1. span.kind === SpanKind.CLIENT
|
|
11
|
-
* 2. AND has HTTP attributes (http.method, http.url, or server.address)
|
|
12
|
-
* OR has GenAI attributes (gen_ai.system, gen_ai.operation.name)
|
|
13
|
-
*/
|
|
14
|
-
export function isSpanEligible(span) {
|
|
15
|
-
log.debug("Checking span eligibility", {
|
|
16
|
-
spanName: span.name,
|
|
17
|
-
spanKind: span.kind,
|
|
18
|
-
spanId: span.spanContext().spanId,
|
|
19
|
-
traceId: span.spanContext().traceId,
|
|
20
|
-
});
|
|
21
|
-
// Must be a CLIENT span (outgoing request)
|
|
22
|
-
if (span.kind !== SpanKind.CLIENT) {
|
|
23
|
-
log.debug("Span not eligible: not CLIENT kind", {
|
|
24
|
-
spanName: span.name,
|
|
25
|
-
spanKind: span.kind,
|
|
26
|
-
});
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const attributes = span.attributes;
|
|
30
|
-
// Check for HTTP attributes
|
|
31
|
-
const hasHttpMethod = attributes["http.method"] !== undefined;
|
|
32
|
-
const hasHttpUrl = attributes["http.url"] !== undefined;
|
|
33
|
-
const hasServerAddress = attributes["server.address"] !== undefined;
|
|
34
|
-
const isEligible = hasHttpMethod || hasHttpUrl || hasServerAddress;
|
|
35
|
-
log.debug("Span eligibility check result", {
|
|
36
|
-
spanName: span.name,
|
|
37
|
-
isEligible,
|
|
38
|
-
httpAttributes: {
|
|
39
|
-
hasMethod: hasHttpMethod,
|
|
40
|
-
hasUrl: hasHttpUrl,
|
|
41
|
-
hasServerAddress,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
return isEligible;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=span-filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-filter.js","sourceRoot":"","sources":["../../src/filtering/span-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,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index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pingops/core - Internal shared utilities
|
|
3
|
-
*/
|
|
4
|
-
export * from "./types";
|
|
5
|
-
export * from "./filtering/span-filter";
|
|
6
|
-
export * from "./filtering/domain-filter";
|
|
7
|
-
export * from "./filtering/header-filter";
|
|
8
|
-
export * from "./utils/span-extractor";
|
|
9
|
-
export * from "./utils/context-extractor";
|
|
10
|
-
export * from "./logger";
|
|
11
|
-
export * from "./context-keys";
|
|
12
|
-
export * from "./wrap-http";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pingops/core - Internal shared utilities
|
|
3
|
-
*/
|
|
4
|
-
export * from "./types";
|
|
5
|
-
export * from "./filtering/span-filter";
|
|
6
|
-
export * from "./filtering/domain-filter";
|
|
7
|
-
export * from "./filtering/header-filter";
|
|
8
|
-
export * from "./utils/span-extractor";
|
|
9
|
-
export * from "./utils/context-extractor";
|
|
10
|
-
export * from "./logger";
|
|
11
|
-
export * from "./context-keys";
|
|
12
|
-
export * from "./wrap-http";
|
|
13
|
-
//# 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,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/logger.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global logger utility for PingOps Core
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent logging across all core 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 Filter]')
|
|
18
|
-
* @returns Logger instance
|
|
19
|
-
*/
|
|
20
|
-
export declare function createLogger(prefix: string): Logger;
|
|
21
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/logger.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global logger utility for PingOps Core
|
|
3
|
-
*
|
|
4
|
-
* Provides consistent logging across all core 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 Filter]')
|
|
11
|
-
* @returns Logger instance
|
|
12
|
-
*/
|
|
13
|
-
export function createLogger(prefix) {
|
|
14
|
-
const isDebugEnabled = process.env.PINGOPS_DEBUG === "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
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
DELETED
|
@@ -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,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM,CAAC;IAE5D,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,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;YACtC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;YACtC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;YACvC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP transport client for sending spans to PingOps backend
|
|
3
|
-
* Fire-and-forget, batched, with error handling
|
|
4
|
-
*/
|
|
5
|
-
import type { SpanPayload } from '../types';
|
|
6
|
-
export interface TransportConfig {
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
batchSize?: number;
|
|
10
|
-
batchTimeout?: number;
|
|
11
|
-
debug?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* HTTP client for PingOps backend
|
|
15
|
-
*/
|
|
16
|
-
export declare class PingopsTransportClient {
|
|
17
|
-
private config;
|
|
18
|
-
private batch;
|
|
19
|
-
private batchTimeoutId;
|
|
20
|
-
constructor(config: TransportConfig);
|
|
21
|
-
/**
|
|
22
|
-
* Adds a span to the batch and sends if batch is full
|
|
23
|
-
*/
|
|
24
|
-
addSpan(payload: SpanPayload): void;
|
|
25
|
-
/**
|
|
26
|
-
* Sends a span immediately (for immediate export mode)
|
|
27
|
-
*/
|
|
28
|
-
sendSpanImmediately(payload: SpanPayload): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Schedules a flush after batchTimeout
|
|
31
|
-
*/
|
|
32
|
-
private scheduleFlush;
|
|
33
|
-
/**
|
|
34
|
-
* Flushes the current batch to the backend
|
|
35
|
-
*/
|
|
36
|
-
flush(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Sends a batch of spans to the backend
|
|
39
|
-
*/
|
|
40
|
-
private sendBatch;
|
|
41
|
-
/**
|
|
42
|
-
* Forces a flush and waits for completion (for shutdown)
|
|
43
|
-
*/
|
|
44
|
-
shutdown(): Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,cAAc,CAA+B;gBAEzC,MAAM,EAAE,eAAe;IAanC;;OAEG;IACI,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAY1C;;OAEG;IACU,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;IACI,KAAK,IAAI,IAAI;IAsBpB;;OAEG;YACW,SAAS;IA4BvB;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAKvC"}
|
package/dist/transport/client.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP transport client for sending spans to PingOps backend
|
|
3
|
-
* Fire-and-forget, batched, with error handling
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* HTTP client for PingOps backend
|
|
7
|
-
*/
|
|
8
|
-
export class PingopsTransportClient {
|
|
9
|
-
config;
|
|
10
|
-
batch = [];
|
|
11
|
-
batchTimeoutId = null;
|
|
12
|
-
constructor(config) {
|
|
13
|
-
// Get API key from config or environment
|
|
14
|
-
const apiKey = config.apiKey || process.env.PINGOPS_API_KEY || '';
|
|
15
|
-
this.config = {
|
|
16
|
-
apiKey,
|
|
17
|
-
baseUrl: config.baseUrl,
|
|
18
|
-
batchSize: config.batchSize ?? 50,
|
|
19
|
-
batchTimeout: config.batchTimeout ?? 5000, // 5 seconds
|
|
20
|
-
debug: config.debug ?? false,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Adds a span to the batch and sends if batch is full
|
|
25
|
-
*/
|
|
26
|
-
addSpan(payload) {
|
|
27
|
-
this.batch.push(payload);
|
|
28
|
-
// Send immediately if batch is full
|
|
29
|
-
if (this.batch.length >= this.config.batchSize) {
|
|
30
|
-
this.flush();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// Set timeout for sending batch
|
|
34
|
-
this.scheduleFlush();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Sends a span immediately (for immediate export mode)
|
|
39
|
-
*/
|
|
40
|
-
async sendSpanImmediately(payload) {
|
|
41
|
-
await this.sendBatch([payload]);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Schedules a flush after batchTimeout
|
|
45
|
-
*/
|
|
46
|
-
scheduleFlush() {
|
|
47
|
-
if (this.batchTimeoutId) {
|
|
48
|
-
return; // Already scheduled
|
|
49
|
-
}
|
|
50
|
-
this.batchTimeoutId = setTimeout(() => {
|
|
51
|
-
this.batchTimeoutId = null;
|
|
52
|
-
this.flush();
|
|
53
|
-
}, this.config.batchTimeout);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Flushes the current batch to the backend
|
|
57
|
-
*/
|
|
58
|
-
flush() {
|
|
59
|
-
if (this.batch.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const batchToSend = [...this.batch];
|
|
63
|
-
this.batch = [];
|
|
64
|
-
if (this.batchTimeoutId) {
|
|
65
|
-
clearTimeout(this.batchTimeoutId);
|
|
66
|
-
this.batchTimeoutId = null;
|
|
67
|
-
}
|
|
68
|
-
// Fire-and-forget: don't await
|
|
69
|
-
this.sendBatch(batchToSend).catch((error) => {
|
|
70
|
-
// Error handling: log but don't crash
|
|
71
|
-
if (this.config.debug) {
|
|
72
|
-
console.error('[PingOps] Failed to send batch:', error);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Sends a batch of spans to the backend
|
|
78
|
-
*/
|
|
79
|
-
async sendBatch(spans) {
|
|
80
|
-
const url = `${this.config.baseUrl}/api/v1/spans`;
|
|
81
|
-
const headers = {
|
|
82
|
-
'Content-Type': 'application/json',
|
|
83
|
-
};
|
|
84
|
-
if (this.config.apiKey) {
|
|
85
|
-
headers['Authorization'] = `Bearer ${this.config.apiKey}`;
|
|
86
|
-
}
|
|
87
|
-
// Use native fetch (Node 20+) or fallback to undici if available
|
|
88
|
-
const response = await fetch(url, {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
headers,
|
|
91
|
-
body: JSON.stringify({ spans }),
|
|
92
|
-
});
|
|
93
|
-
if (!response.ok) {
|
|
94
|
-
const errorText = await response.text().catch(() => 'Unknown error');
|
|
95
|
-
throw new Error(`PingOps API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
96
|
-
}
|
|
97
|
-
if (this.config.debug) {
|
|
98
|
-
console.log(`[PingOps] Sent ${spans.length} spans successfully`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Forces a flush and waits for completion (for shutdown)
|
|
103
|
-
*/
|
|
104
|
-
async shutdown() {
|
|
105
|
-
this.flush();
|
|
106
|
-
// Give a small delay for the async send to complete
|
|
107
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;GAEG;AACH,MAAM,OAAO,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CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,MAAM,SAAS,EAAE,CAAC,CAAC;QACjG,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,MAAM,qBAAqB,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,oDAAoD;QACpD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared type definitions for PingOps SDK
|
|
3
|
-
*/
|
|
4
|
-
export interface DomainRule {
|
|
5
|
-
domain: string;
|
|
6
|
-
paths?: string[];
|
|
7
|
-
headersAllowList?: string[];
|
|
8
|
-
headersDenyList?: string[];
|
|
9
|
-
}
|
|
10
|
-
export interface SpanPayload {
|
|
11
|
-
traceId: string;
|
|
12
|
-
spanId: string;
|
|
13
|
-
parentSpanId?: string;
|
|
14
|
-
name: string;
|
|
15
|
-
kind: string;
|
|
16
|
-
startTime: string;
|
|
17
|
-
endTime: string;
|
|
18
|
-
duration: number;
|
|
19
|
-
attributes: Record<string, unknown>;
|
|
20
|
-
status: {
|
|
21
|
-
code: string;
|
|
22
|
-
message?: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Attributes to propagate to HTTP spans
|
|
27
|
-
*/
|
|
28
|
-
export interface WrapHttpAttributes {
|
|
29
|
-
userId?: string;
|
|
30
|
-
sessionId?: string;
|
|
31
|
-
tags?: string[];
|
|
32
|
-
metadata?: Record<string, string>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts propagated attributes from OpenTelemetry context
|
|
3
|
-
*/
|
|
4
|
-
import type { Context } from "@opentelemetry/api";
|
|
5
|
-
/**
|
|
6
|
-
* Extracts propagated attributes from the given context and returns them
|
|
7
|
-
* as span attributes that can be set on a span.
|
|
8
|
-
*
|
|
9
|
-
* @param parentContext - The OpenTelemetry context to extract attributes from
|
|
10
|
-
* @returns Record of attribute key-value pairs to set on spans
|
|
11
|
-
*/
|
|
12
|
-
export declare function getPropagatedAttributesFromContext(parentContext: Context): Record<string, string | string[]>;
|
|
13
|
-
//# sourceMappingURL=context-extractor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-extractor.d.ts","sourceRoot":"","sources":["../../src/utils/context-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQlD;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,OAAO,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAsCnC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts propagated attributes from OpenTelemetry context
|
|
3
|
-
*/
|
|
4
|
-
import { PINGOPS_USER_ID, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_METADATA, } from "../context-keys";
|
|
5
|
-
/**
|
|
6
|
-
* Extracts propagated attributes from the given context and returns them
|
|
7
|
-
* as span attributes that can be set on a span.
|
|
8
|
-
*
|
|
9
|
-
* @param parentContext - The OpenTelemetry context to extract attributes from
|
|
10
|
-
* @returns Record of attribute key-value pairs to set on spans
|
|
11
|
-
*/
|
|
12
|
-
export function getPropagatedAttributesFromContext(parentContext) {
|
|
13
|
-
const attributes = {};
|
|
14
|
-
// Extract userId
|
|
15
|
-
const userId = parentContext.getValue(PINGOPS_USER_ID);
|
|
16
|
-
if (userId !== undefined && typeof userId === "string") {
|
|
17
|
-
attributes["pingops.user_id"] = userId;
|
|
18
|
-
}
|
|
19
|
-
// Extract sessionId
|
|
20
|
-
const sessionId = parentContext.getValue(PINGOPS_SESSION_ID);
|
|
21
|
-
if (sessionId !== undefined && typeof sessionId === "string") {
|
|
22
|
-
attributes["pingops.session_id"] = sessionId;
|
|
23
|
-
}
|
|
24
|
-
// Extract tags
|
|
25
|
-
const tags = parentContext.getValue(PINGOPS_TAGS);
|
|
26
|
-
if (tags !== undefined && Array.isArray(tags)) {
|
|
27
|
-
attributes["pingops.tags"] = tags;
|
|
28
|
-
}
|
|
29
|
-
// Extract metadata
|
|
30
|
-
const metadata = parentContext.getValue(PINGOPS_METADATA);
|
|
31
|
-
if (metadata !== undefined &&
|
|
32
|
-
typeof metadata === "object" &&
|
|
33
|
-
metadata !== null &&
|
|
34
|
-
!Array.isArray(metadata)) {
|
|
35
|
-
// Flatten metadata object into span attributes with prefix
|
|
36
|
-
for (const [key, value] of Object.entries(metadata)) {
|
|
37
|
-
if (typeof value === "string") {
|
|
38
|
-
attributes[`pingops.metadata.${key}`] = value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return attributes;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=context-extractor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-extractor.js","sourceRoot":"","sources":["../../src/utils/context-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,UAAU,kCAAkC,CAChD,aAAsB;IAEtB,MAAM,UAAU,GAAsC,EAAE,CAAC;IAEzD,iBAAiB;IACjB,MAAM,MAAM,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data from spans for PingOps backend
|
|
3
|
-
*/
|
|
4
|
-
import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
5
|
-
import type { DomainRule, SpanPayload } from "../types";
|
|
6
|
-
/**
|
|
7
|
-
* Extracts structured payload from a span
|
|
8
|
-
*/
|
|
9
|
-
export declare function extractSpanPayload(span: ReadableSpan, domainAllowList?: DomainRule[], globalHeadersAllowList?: string[], globalHeadersDenyList?: string[]): SpanPayload | null;
|
|
10
|
-
//# sourceMappingURL=span-extractor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-extractor.d.ts","sourceRoot":"","sources":["../../src/utils/span-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA2CxD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,YAAY,EAClB,eAAe,CAAC,EAAE,UAAU,EAAE,EAC9B,sBAAsB,CAAC,EAAE,MAAM,EAAE,EACjC,qBAAqB,CAAC,EAAE,MAAM,EAAE,GAC/B,WAAW,GAAG,IAAI,CAwIpB"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts structured data from spans for PingOps backend
|
|
3
|
-
*/
|
|
4
|
-
import { filterHeaders, extractHeadersFromAttributes, } from "../filtering/header-filter";
|
|
5
|
-
/**
|
|
6
|
-
* Extracts domain from URL
|
|
7
|
-
*/
|
|
8
|
-
function extractDomainFromUrl(url) {
|
|
9
|
-
try {
|
|
10
|
-
const urlObj = new URL(url);
|
|
11
|
-
return urlObj.hostname;
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
const match = url.match(/^(?:https?:\/\/)?([^/]+)/);
|
|
15
|
-
return match ? match[1] : "";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Gets domain rule configuration for a given URL
|
|
20
|
-
*/
|
|
21
|
-
function getDomainRule(url, domainAllowList) {
|
|
22
|
-
if (!domainAllowList) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
const domain = extractDomainFromUrl(url);
|
|
26
|
-
for (const rule of domainAllowList) {
|
|
27
|
-
if (domain === rule.domain ||
|
|
28
|
-
domain.endsWith(`.${rule.domain}`) ||
|
|
29
|
-
domain === rule.domain.slice(1)) {
|
|
30
|
-
return rule;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Extracts structured payload from a span
|
|
37
|
-
*/
|
|
38
|
-
export function extractSpanPayload(span, domainAllowList, globalHeadersAllowList, globalHeadersDenyList) {
|
|
39
|
-
const attributes = span.attributes;
|
|
40
|
-
const url = attributes["http.url"] || attributes["url.full"];
|
|
41
|
-
// Get domain-specific rule if available
|
|
42
|
-
const domainRule = url ? getDomainRule(url, domainAllowList) : undefined;
|
|
43
|
-
// Merge global and domain-specific header rules
|
|
44
|
-
const headersAllowList = domainRule?.headersAllowList ?? globalHeadersAllowList;
|
|
45
|
-
const headersDenyList = domainRule?.headersDenyList ?? globalHeadersDenyList;
|
|
46
|
-
// Extract HTTP headers if available
|
|
47
|
-
let requestHeaders = {};
|
|
48
|
-
let responseHeaders = {};
|
|
49
|
-
// First, try to extract flat array format headers (e.g., 'http.request.header.0', 'http.request.header.1')
|
|
50
|
-
const flatRequestHeaders = extractHeadersFromAttributes(attributes, "http.request.header");
|
|
51
|
-
const flatResponseHeaders = extractHeadersFromAttributes(attributes, "http.response.header");
|
|
52
|
-
// Try to get headers from attributes (format may vary by instrumentation)
|
|
53
|
-
const httpRequestHeadersValue = attributes["http.request.header"];
|
|
54
|
-
const httpResponseHeadersValue = attributes["http.response.header"];
|
|
55
|
-
// Type guard: check if value is a record/object with string keys
|
|
56
|
-
const isHeadersRecord = (value) => {
|
|
57
|
-
return (typeof value === "object" &&
|
|
58
|
-
value !== null &&
|
|
59
|
-
!Array.isArray(value) &&
|
|
60
|
-
Object.values(value).every((v) => typeof v === "string" ||
|
|
61
|
-
(Array.isArray(v) && v.every((item) => typeof item === "string")) ||
|
|
62
|
-
v === undefined));
|
|
63
|
-
};
|
|
64
|
-
// Use flat array format if available, otherwise use direct attribute
|
|
65
|
-
if (flatRequestHeaders) {
|
|
66
|
-
requestHeaders = filterHeaders(flatRequestHeaders, headersAllowList, headersDenyList);
|
|
67
|
-
}
|
|
68
|
-
else if (isHeadersRecord(httpRequestHeadersValue)) {
|
|
69
|
-
requestHeaders = filterHeaders(httpRequestHeadersValue, headersAllowList, headersDenyList);
|
|
70
|
-
}
|
|
71
|
-
if (flatResponseHeaders) {
|
|
72
|
-
responseHeaders = filterHeaders(flatResponseHeaders, headersAllowList, headersDenyList);
|
|
73
|
-
}
|
|
74
|
-
else if (isHeadersRecord(httpResponseHeadersValue)) {
|
|
75
|
-
responseHeaders = filterHeaders(httpResponseHeadersValue, headersAllowList, headersDenyList);
|
|
76
|
-
}
|
|
77
|
-
// Build attributes object
|
|
78
|
-
const extractedAttributes = {
|
|
79
|
-
...attributes,
|
|
80
|
-
};
|
|
81
|
-
// Remove flat array format headers (e.g., 'http.request.header.0', 'http.request.header.1', etc.)
|
|
82
|
-
// We'll replace them with the proper key-value format
|
|
83
|
-
for (const key in extractedAttributes) {
|
|
84
|
-
if ((key.startsWith("http.request.header.") &&
|
|
85
|
-
key !== "http.request.header") ||
|
|
86
|
-
(key.startsWith("http.response.header.") &&
|
|
87
|
-
key !== "http.response.header")) {
|
|
88
|
-
// Check if it's a numeric index (flat array format)
|
|
89
|
-
const match = key.match(/^(http\.(?:request|response)\.header)\.(\d+)$/);
|
|
90
|
-
if (match) {
|
|
91
|
-
delete extractedAttributes[key];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Add filtered headers in proper key-value format
|
|
96
|
-
if (Object.keys(requestHeaders).length > 0) {
|
|
97
|
-
extractedAttributes["http.request.header"] = requestHeaders;
|
|
98
|
-
}
|
|
99
|
-
if (Object.keys(responseHeaders).length > 0) {
|
|
100
|
-
extractedAttributes["http.response.header"] = responseHeaders;
|
|
101
|
-
}
|
|
102
|
-
// Build span payload
|
|
103
|
-
const spanContext = span.spanContext();
|
|
104
|
-
// parentSpanId may not be available in all versions of ReadableSpan
|
|
105
|
-
const parentSpanId = "parentSpanId" in span
|
|
106
|
-
? span.parentSpanId
|
|
107
|
-
: undefined;
|
|
108
|
-
return {
|
|
109
|
-
traceId: spanContext.traceId,
|
|
110
|
-
spanId: spanContext.spanId,
|
|
111
|
-
parentSpanId,
|
|
112
|
-
name: span.name,
|
|
113
|
-
kind: span.kind.toString(),
|
|
114
|
-
startTime: new Date(span.startTime[0] * 1000 + span.startTime[1] / 1000000).toISOString(),
|
|
115
|
-
endTime: new Date(span.endTime[0] * 1000 + span.endTime[1] / 1000000).toISOString(),
|
|
116
|
-
duration: (span.endTime[0] - span.startTime[0]) * 1000 +
|
|
117
|
-
(span.endTime[1] - span.startTime[1]) / 1000000,
|
|
118
|
-
attributes: extractedAttributes,
|
|
119
|
-
status: {
|
|
120
|
-
code: span.status.code.toString(),
|
|
121
|
-
message: span.status.message,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=span-extractor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-extractor.js","sourceRoot":"","sources":["../../src/utils/span-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,aAAa,EACb,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,SAAS,oBAAoB,CAAC,GAAW;IACvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC;IACz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