@foam-ai/node 0.1.0-alpha.1 → 0.1.0-alpha.11
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/README.md +656 -0
- package/dist/before-send.d.ts +27 -0
- package/dist/before-send.js +46 -0
- package/dist/constants.d.ts +44 -0
- package/dist/constants.js +67 -0
- package/dist/endpoint.d.ts +2 -0
- package/dist/endpoint.js +11 -0
- package/dist/exporters.d.ts +34 -0
- package/dist/exporters.js +208 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +28 -0
- package/dist/ingest.d.ts +12 -0
- package/dist/ingest.js +70 -0
- package/dist/init.d.ts +26 -0
- package/dist/init.js +171 -0
- package/dist/instrumentations.d.ts +4 -0
- package/dist/instrumentations.js +120 -0
- package/dist/library-versions.d.ts +1 -0
- package/dist/library-versions.js +59 -0
- package/dist/logs.d.ts +10 -0
- package/dist/logs.js +61 -0
- package/dist/metrics.d.ts +5 -0
- package/dist/metrics.js +29 -0
- package/dist/network-capture/collector.d.ts +27 -0
- package/dist/network-capture/collector.js +411 -0
- package/dist/network-capture/http.d.ts +5 -0
- package/dist/network-capture/http.js +221 -0
- package/dist/network-capture/index.d.ts +3 -0
- package/dist/network-capture/index.js +20 -0
- package/dist/network-capture/redact.d.ts +9 -0
- package/dist/network-capture/redact.js +401 -0
- package/dist/network-capture/support.d.ts +2 -0
- package/dist/network-capture/support.js +38 -0
- package/dist/network-capture/undici.d.ts +5 -0
- package/dist/network-capture/undici.js +177 -0
- package/dist/otlp.d.ts +8 -0
- package/dist/otlp.js +46 -0
- package/dist/propagation.d.ts +5 -0
- package/dist/propagation.js +47 -0
- package/dist/redaction-keys.d.ts +4 -0
- package/dist/redaction-keys.js +480 -0
- package/dist/redaction.d.ts +24 -0
- package/dist/redaction.js +281 -0
- package/dist/report.d.ts +9 -0
- package/dist/report.js +56 -0
- package/dist/resource.d.ts +3 -0
- package/dist/resource.js +24 -0
- package/dist/state.d.ts +26 -0
- package/dist/state.js +61 -0
- package/dist/traces.d.ts +1 -0
- package/dist/traces.js +21 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +20 -0
- package/package.json +47 -19
- package/dist/node/src/capture-exception.d.ts +0 -9
- package/dist/node/src/capture-exception.js +0 -31
- package/dist/node/src/index.d.ts +0 -9
- package/dist/node/src/index.js +0 -12
- package/dist/node/src/init.d.ts +0 -27
- package/dist/node/src/init.js +0 -203
- package/dist/shared/constants.d.ts +0 -1
- package/dist/shared/constants.js +0 -4
- package/dist/shared/util.d.ts +0 -9
- package/dist/shared/util.js +0 -21
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBeforeSend = resolveBeforeSend;
|
|
4
|
+
exports.invokeBeforeSend = invokeBeforeSend;
|
|
5
|
+
function resolveBeforeSend(hook) {
|
|
6
|
+
if (hook === undefined || hook === null)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (typeof hook !== "function") {
|
|
9
|
+
throw new TypeError("[foam] beforeSend must be a function");
|
|
10
|
+
}
|
|
11
|
+
return hook;
|
|
12
|
+
}
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function isEvent(value, expectedType) {
|
|
17
|
+
if (!isRecord(value) || value.type !== expectedType || !isRecord(value.attributes)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (expectedType === "span") {
|
|
21
|
+
return (typeof value.name === "string" &&
|
|
22
|
+
Array.isArray(value.events) &&
|
|
23
|
+
value.events.every((entry) => isRecord(entry) && typeof entry.name === "string") &&
|
|
24
|
+
Array.isArray(value.links) &&
|
|
25
|
+
value.links.every((entry) => isRecord(entry) && isRecord(entry.context)));
|
|
26
|
+
}
|
|
27
|
+
return value.severityText === undefined || typeof value.severityText === "string";
|
|
28
|
+
}
|
|
29
|
+
function invokeBeforeSend(hook, event) {
|
|
30
|
+
let copy;
|
|
31
|
+
try {
|
|
32
|
+
copy = structuredClone(event);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const result = hook(copy);
|
|
39
|
+
if (result === null)
|
|
40
|
+
return null;
|
|
41
|
+
return isEvent(result, event.type) ? result : undefined;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
2
|
+
export declare const FOAM_ENDPOINT = "https://otel.api.foam.ai";
|
|
3
|
+
export declare const FOAM_INGEST_HOST: string;
|
|
4
|
+
export declare const ATTR_FOAM_INGEST_HOST = "foam.ingest.host";
|
|
5
|
+
export declare const FOAM_IDENTIFIER_NAME = "[foam-otel]";
|
|
6
|
+
export declare const FOAM_DISTRO_NAME = "@foam-ai/node";
|
|
7
|
+
export declare const FOAM_DISTRO_VERSION = "0.1.0-alpha.11";
|
|
8
|
+
export declare const FOAM_OTLP_TRACES_PATH = "/v1/traces";
|
|
9
|
+
export declare const FOAM_OTLP_LOGS_PATH = "/v1/logs";
|
|
10
|
+
export declare const FOAM_OTLP_METRICS_PATH = "/v1/metrics";
|
|
11
|
+
export declare const NETWORK_BODY_CHUNK_BYTES: number;
|
|
12
|
+
export declare const NETWORK_BODY_MAX_CAPTURE_BYTES: number;
|
|
13
|
+
export declare const NETWORK_BODY_MAX_DECODE_BYTES: number;
|
|
14
|
+
export declare const NETWORK_CAPTURE_EVENT = "foam.http.body.chunk";
|
|
15
|
+
export declare const NETWORK_CAPTURE_EVENT_BODY = "HTTP body chunk";
|
|
16
|
+
export declare const NETWORK_CAPTURE_DEADLINE_MS = 60000;
|
|
17
|
+
export declare const MAX_ACTIVE_CAPTURES = 128;
|
|
18
|
+
export declare const ATTR_HTTP_REQUEST_BODY_SIZE = "http.request.body.size";
|
|
19
|
+
export declare const ATTR_HTTP_RESPONSE_BODY_SIZE = "http.response.body.size";
|
|
20
|
+
export declare const ATTR_HTTP_REQUEST_BODY_CONTENT = "http.request.body.content";
|
|
21
|
+
export declare const ATTR_HTTP_RESPONSE_BODY_CONTENT = "http.response.body.content";
|
|
22
|
+
export declare const ATTR_FOAM_HTTP_BODY_ID = "foam.http.body.id";
|
|
23
|
+
export declare const ATTR_FOAM_HTTP_BODY_SIDE = "foam.http.body.side";
|
|
24
|
+
export declare const ATTR_FOAM_HTTP_BODY_DIRECTION = "foam.http.body.direction";
|
|
25
|
+
export declare const ATTR_FOAM_HTTP_BODY_COMPLETE = "foam.http.body.complete";
|
|
26
|
+
export declare const ATTR_FOAM_HTTP_BODY_TRUNCATED = "foam.http.body.truncated";
|
|
27
|
+
export declare const ATTR_FOAM_HTTP_BODY_OUTCOME = "foam.http.body.outcome";
|
|
28
|
+
export declare const ATTR_FOAM_HTTP_BODY_CAPTURED_BYTES = "foam.http.body.captured_bytes";
|
|
29
|
+
export declare const ATTR_FOAM_HTTP_BODY_CHUNK_COUNT = "foam.http.body.chunk.count";
|
|
30
|
+
export declare const ATTR_FOAM_HTTP_BODY_CHUNK_INDEX = "foam.http.body.chunk.index";
|
|
31
|
+
export declare const ATTR_FOAM_HTTP_BODY_CHUNK_BYTES = "foam.http.body.chunk.bytes";
|
|
32
|
+
export declare const ATTR_FOAM_HTTP_BODY_CHUNK_CONTENT = "foam.http.body.chunk.content";
|
|
33
|
+
export declare const ATTR_FOAM_HTTP_REQUEST_BODY_CAPTURE_ID = "foam.http.request.body.capture_id";
|
|
34
|
+
export declare const ATTR_FOAM_HTTP_RESPONSE_BODY_CAPTURE_ID = "foam.http.response.body.capture_id";
|
|
35
|
+
export declare const ATTR_FOAM_HTTP_REQUEST_BODY_COMPLETE = "foam.http.request.body.complete";
|
|
36
|
+
export declare const ATTR_FOAM_HTTP_RESPONSE_BODY_COMPLETE = "foam.http.response.body.complete";
|
|
37
|
+
export declare const ATTR_FOAM_HTTP_REQUEST_BODY_TRUNCATED = "foam.http.request.body.truncated";
|
|
38
|
+
export declare const ATTR_FOAM_HTTP_RESPONSE_BODY_TRUNCATED = "foam.http.response.body.truncated";
|
|
39
|
+
export declare const SAFE_NETWORK_HEADERS: readonly ["content-type", "content-length", "content-encoding"];
|
|
40
|
+
export declare const REDACTED_VALUE = "[REDACTED]";
|
|
41
|
+
export declare const FULL_MASK = "********";
|
|
42
|
+
export declare const TAIL_MASK_THRESHOLD = 12;
|
|
43
|
+
export declare const DIAG_LOG_LEVEL = "OTEL_LOG_LEVEL";
|
|
44
|
+
export declare const SEVERITY_TEXT: Partial<Record<SeverityNumber, string>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEVERITY_TEXT = exports.DIAG_LOG_LEVEL = exports.TAIL_MASK_THRESHOLD = exports.FULL_MASK = exports.REDACTED_VALUE = exports.SAFE_NETWORK_HEADERS = exports.ATTR_FOAM_HTTP_RESPONSE_BODY_TRUNCATED = exports.ATTR_FOAM_HTTP_REQUEST_BODY_TRUNCATED = exports.ATTR_FOAM_HTTP_RESPONSE_BODY_COMPLETE = exports.ATTR_FOAM_HTTP_REQUEST_BODY_COMPLETE = exports.ATTR_FOAM_HTTP_RESPONSE_BODY_CAPTURE_ID = exports.ATTR_FOAM_HTTP_REQUEST_BODY_CAPTURE_ID = exports.ATTR_FOAM_HTTP_BODY_CHUNK_CONTENT = exports.ATTR_FOAM_HTTP_BODY_CHUNK_BYTES = exports.ATTR_FOAM_HTTP_BODY_CHUNK_INDEX = exports.ATTR_FOAM_HTTP_BODY_CHUNK_COUNT = exports.ATTR_FOAM_HTTP_BODY_CAPTURED_BYTES = exports.ATTR_FOAM_HTTP_BODY_OUTCOME = exports.ATTR_FOAM_HTTP_BODY_TRUNCATED = exports.ATTR_FOAM_HTTP_BODY_COMPLETE = exports.ATTR_FOAM_HTTP_BODY_DIRECTION = exports.ATTR_FOAM_HTTP_BODY_SIDE = exports.ATTR_FOAM_HTTP_BODY_ID = exports.ATTR_HTTP_RESPONSE_BODY_CONTENT = exports.ATTR_HTTP_REQUEST_BODY_CONTENT = exports.ATTR_HTTP_RESPONSE_BODY_SIZE = exports.ATTR_HTTP_REQUEST_BODY_SIZE = exports.MAX_ACTIVE_CAPTURES = exports.NETWORK_CAPTURE_DEADLINE_MS = exports.NETWORK_CAPTURE_EVENT_BODY = exports.NETWORK_CAPTURE_EVENT = exports.NETWORK_BODY_MAX_DECODE_BYTES = exports.NETWORK_BODY_MAX_CAPTURE_BYTES = exports.NETWORK_BODY_CHUNK_BYTES = exports.FOAM_OTLP_METRICS_PATH = exports.FOAM_OTLP_LOGS_PATH = exports.FOAM_OTLP_TRACES_PATH = exports.FOAM_DISTRO_VERSION = exports.FOAM_DISTRO_NAME = exports.FOAM_IDENTIFIER_NAME = exports.ATTR_FOAM_INGEST_HOST = exports.FOAM_INGEST_HOST = exports.FOAM_ENDPOINT = void 0;
|
|
4
|
+
const api_logs_1 = require("@opentelemetry/api-logs");
|
|
5
|
+
exports.FOAM_ENDPOINT = "https://otel.api.foam.ai";
|
|
6
|
+
exports.FOAM_INGEST_HOST = new URL(exports.FOAM_ENDPOINT).hostname;
|
|
7
|
+
exports.ATTR_FOAM_INGEST_HOST = "foam.ingest.host";
|
|
8
|
+
exports.FOAM_IDENTIFIER_NAME = "[foam-otel]";
|
|
9
|
+
exports.FOAM_DISTRO_NAME = "@foam-ai/node";
|
|
10
|
+
exports.FOAM_DISTRO_VERSION = "0.1.0-alpha.11";
|
|
11
|
+
exports.FOAM_OTLP_TRACES_PATH = "/v1/traces";
|
|
12
|
+
exports.FOAM_OTLP_LOGS_PATH = "/v1/logs";
|
|
13
|
+
exports.FOAM_OTLP_METRICS_PATH = "/v1/metrics";
|
|
14
|
+
exports.NETWORK_BODY_CHUNK_BYTES = 64 * 1024; // pcga11: 64Kib
|
|
15
|
+
exports.NETWORK_BODY_MAX_CAPTURE_BYTES = 1024 * 1024; // pcga11: 1Mib
|
|
16
|
+
// Bounds sync zlib output when decoding captured bodies. 1 MiB of captured
|
|
17
|
+
// gzip can legally inflate to ~1 GiB (worst case ~1032:1), which would be
|
|
18
|
+
// allocated synchronously on the event loop and could OOM-abort the host
|
|
19
|
+
// app. Past this bound zlib throws instead, and the capture falls back to
|
|
20
|
+
// the compressed wire bytes. 16x covers typical text compression ratios.
|
|
21
|
+
exports.NETWORK_BODY_MAX_DECODE_BYTES = 16 * exports.NETWORK_BODY_MAX_CAPTURE_BYTES;
|
|
22
|
+
exports.NETWORK_CAPTURE_EVENT = "foam.http.body.chunk";
|
|
23
|
+
exports.NETWORK_CAPTURE_EVENT_BODY = "HTTP body chunk";
|
|
24
|
+
exports.NETWORK_CAPTURE_DEADLINE_MS = 60_000;
|
|
25
|
+
exports.MAX_ACTIVE_CAPTURES = 128;
|
|
26
|
+
// pcga11: Do not change these.
|
|
27
|
+
// Spec names copied from OpenTelemetry HTTP semantic conventions. 1.43.0 does
|
|
28
|
+
// not export BODY_CONTENT, and OTel JS recommends copying unstable names
|
|
29
|
+
// instead of importing `@opentelemetry/semantic-conventions/incubating`.
|
|
30
|
+
exports.ATTR_HTTP_REQUEST_BODY_SIZE = "http.request.body.size";
|
|
31
|
+
exports.ATTR_HTTP_RESPONSE_BODY_SIZE = "http.response.body.size";
|
|
32
|
+
exports.ATTR_HTTP_REQUEST_BODY_CONTENT = "http.request.body.content";
|
|
33
|
+
exports.ATTR_HTTP_RESPONSE_BODY_CONTENT = "http.response.body.content";
|
|
34
|
+
exports.ATTR_FOAM_HTTP_BODY_ID = "foam.http.body.id";
|
|
35
|
+
exports.ATTR_FOAM_HTTP_BODY_SIDE = "foam.http.body.side";
|
|
36
|
+
exports.ATTR_FOAM_HTTP_BODY_DIRECTION = "foam.http.body.direction";
|
|
37
|
+
exports.ATTR_FOAM_HTTP_BODY_COMPLETE = "foam.http.body.complete";
|
|
38
|
+
exports.ATTR_FOAM_HTTP_BODY_TRUNCATED = "foam.http.body.truncated";
|
|
39
|
+
exports.ATTR_FOAM_HTTP_BODY_OUTCOME = "foam.http.body.outcome";
|
|
40
|
+
exports.ATTR_FOAM_HTTP_BODY_CAPTURED_BYTES = "foam.http.body.captured_bytes";
|
|
41
|
+
exports.ATTR_FOAM_HTTP_BODY_CHUNK_COUNT = "foam.http.body.chunk.count";
|
|
42
|
+
exports.ATTR_FOAM_HTTP_BODY_CHUNK_INDEX = "foam.http.body.chunk.index";
|
|
43
|
+
exports.ATTR_FOAM_HTTP_BODY_CHUNK_BYTES = "foam.http.body.chunk.bytes";
|
|
44
|
+
exports.ATTR_FOAM_HTTP_BODY_CHUNK_CONTENT = "foam.http.body.chunk.content";
|
|
45
|
+
exports.ATTR_FOAM_HTTP_REQUEST_BODY_CAPTURE_ID = "foam.http.request.body.capture_id";
|
|
46
|
+
exports.ATTR_FOAM_HTTP_RESPONSE_BODY_CAPTURE_ID = "foam.http.response.body.capture_id";
|
|
47
|
+
exports.ATTR_FOAM_HTTP_REQUEST_BODY_COMPLETE = "foam.http.request.body.complete";
|
|
48
|
+
exports.ATTR_FOAM_HTTP_RESPONSE_BODY_COMPLETE = "foam.http.response.body.complete";
|
|
49
|
+
exports.ATTR_FOAM_HTTP_REQUEST_BODY_TRUNCATED = "foam.http.request.body.truncated";
|
|
50
|
+
exports.ATTR_FOAM_HTTP_RESPONSE_BODY_TRUNCATED = "foam.http.response.body.truncated";
|
|
51
|
+
exports.SAFE_NETWORK_HEADERS = [
|
|
52
|
+
"content-type",
|
|
53
|
+
"content-length",
|
|
54
|
+
"content-encoding",
|
|
55
|
+
];
|
|
56
|
+
exports.REDACTED_VALUE = "[REDACTED]";
|
|
57
|
+
exports.FULL_MASK = "********";
|
|
58
|
+
exports.TAIL_MASK_THRESHOLD = 12;
|
|
59
|
+
exports.DIAG_LOG_LEVEL = "OTEL_LOG_LEVEL";
|
|
60
|
+
exports.SEVERITY_TEXT = {
|
|
61
|
+
[api_logs_1.SeverityNumber.TRACE]: "TRACE",
|
|
62
|
+
[api_logs_1.SeverityNumber.DEBUG]: "DEBUG",
|
|
63
|
+
[api_logs_1.SeverityNumber.INFO]: "INFO",
|
|
64
|
+
[api_logs_1.SeverityNumber.WARN]: "WARN",
|
|
65
|
+
[api_logs_1.SeverityNumber.ERROR]: "ERROR",
|
|
66
|
+
[api_logs_1.SeverityNumber.FATAL]: "FATAL",
|
|
67
|
+
};
|
package/dist/endpoint.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setEndpoint = exports.endpoint = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
// pcga11: Defaults to Foam's endpoint and changes only on an explicit setEndpoint
|
|
6
|
+
// call. Exported as a live binding so importers always read the current value.
|
|
7
|
+
exports.endpoint = constants_js_1.FOAM_ENDPOINT;
|
|
8
|
+
const setEndpoint = (value) => {
|
|
9
|
+
exports.endpoint = value;
|
|
10
|
+
};
|
|
11
|
+
exports.setEndpoint = setEndpoint;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import { type ExportResult } from "@opentelemetry/core";
|
|
3
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
4
|
+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
5
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
6
|
+
import type { ReadableLogRecord } from "@opentelemetry/sdk-logs";
|
|
7
|
+
import type { ResourceMetrics } from "@opentelemetry/sdk-metrics";
|
|
8
|
+
import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
9
|
+
import { type BeforeSendHook } from "./before-send.js";
|
|
10
|
+
import { type RedactionConfig } from "./redaction.js";
|
|
11
|
+
type Stamp = Attributes | undefined;
|
|
12
|
+
export interface FoamExporterOptions {
|
|
13
|
+
readonly redaction?: RedactionConfig;
|
|
14
|
+
readonly beforeSend?: BeforeSendHook;
|
|
15
|
+
}
|
|
16
|
+
export declare class FoamTraceExporter extends OTLPTraceExporter {
|
|
17
|
+
private readonly stamp?;
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(token: string, stamp?: Stamp, options?: FoamExporterOptions);
|
|
20
|
+
export(spans: ReadableSpan[], callback: (result: ExportResult) => void): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class FoamLogExporter extends OTLPLogExporter {
|
|
23
|
+
private readonly stamp?;
|
|
24
|
+
private readonly options;
|
|
25
|
+
constructor(token: string, stamp?: Stamp, options?: FoamExporterOptions);
|
|
26
|
+
export(records: ReadableLogRecord[], callback: (result: ExportResult) => void): void;
|
|
27
|
+
}
|
|
28
|
+
export declare class FoamMetricExporter extends OTLPMetricExporter {
|
|
29
|
+
private readonly stamp?;
|
|
30
|
+
private readonly options;
|
|
31
|
+
constructor(token: string, stamp?: Stamp, options?: FoamExporterOptions);
|
|
32
|
+
export(resourceMetrics: ResourceMetrics, callback: (result: ExportResult) => void): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FoamMetricExporter = exports.FoamLogExporter = exports.FoamTraceExporter = void 0;
|
|
4
|
+
const core_1 = require("@opentelemetry/core");
|
|
5
|
+
const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
|
|
6
|
+
const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
7
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
8
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
9
|
+
const before_send_js_1 = require("./before-send.js");
|
|
10
|
+
const constants_js_1 = require("./constants.js");
|
|
11
|
+
const endpoint_js_1 = require("./endpoint.js");
|
|
12
|
+
const redaction_js_1 = require("./redaction.js");
|
|
13
|
+
function redactionConfig(options) {
|
|
14
|
+
return options.redaction ?? (0, redaction_js_1.getActiveRedactionConfig)();
|
|
15
|
+
}
|
|
16
|
+
// Snapshotting attributes here is safe: every SDK processor (batch/simple
|
|
17
|
+
// span, batch log, periodic metric reader) awaits the resource's
|
|
18
|
+
// waitForAsyncAttributes() before calling the exporter, so detector
|
|
19
|
+
// promises are already resolved.
|
|
20
|
+
function redactedResource(resource, overlay, config) {
|
|
21
|
+
const merged = overlay ? resource.merge(overlay) : resource;
|
|
22
|
+
return (0, resources_1.resourceFromAttributes)((0, redaction_js_1.redactAttributesCopy)(merged.attributes, config), { schemaUrl: merged.schemaUrl });
|
|
23
|
+
}
|
|
24
|
+
function copySpan(span, name, attributes, events, links, resource) {
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
kind: span.kind,
|
|
28
|
+
spanContext: span.spanContext.bind(span),
|
|
29
|
+
parentSpanContext: span.parentSpanContext,
|
|
30
|
+
startTime: span.startTime,
|
|
31
|
+
endTime: span.endTime,
|
|
32
|
+
status: span.status,
|
|
33
|
+
attributes,
|
|
34
|
+
links,
|
|
35
|
+
events,
|
|
36
|
+
duration: span.duration,
|
|
37
|
+
ended: span.ended,
|
|
38
|
+
resource,
|
|
39
|
+
instrumentationScope: span.instrumentationScope,
|
|
40
|
+
droppedAttributesCount: span.droppedAttributesCount,
|
|
41
|
+
droppedEventsCount: span.droppedEventsCount,
|
|
42
|
+
droppedLinksCount: span.droppedLinksCount,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
class FoamTraceExporter extends exporter_trace_otlp_http_1.OTLPTraceExporter {
|
|
46
|
+
stamp;
|
|
47
|
+
options;
|
|
48
|
+
constructor(token, stamp, options = {}) {
|
|
49
|
+
super({
|
|
50
|
+
url: `${endpoint_js_1.endpoint}${constants_js_1.FOAM_OTLP_TRACES_PATH}`,
|
|
51
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
52
|
+
});
|
|
53
|
+
this.stamp = stamp;
|
|
54
|
+
this.options = options;
|
|
55
|
+
}
|
|
56
|
+
export(spans, callback) {
|
|
57
|
+
const config = redactionConfig(this.options);
|
|
58
|
+
const overlay = this.stamp ? (0, resources_1.resourceFromAttributes)(this.stamp) : undefined;
|
|
59
|
+
const output = [];
|
|
60
|
+
for (const span of spans) {
|
|
61
|
+
let name = span.name;
|
|
62
|
+
let sourceAttributes = span.attributes;
|
|
63
|
+
let sourceEvents = span.events ?? [];
|
|
64
|
+
let sourceLinks = span.links ?? [];
|
|
65
|
+
if (this.options.beforeSend) {
|
|
66
|
+
const result = (0, before_send_js_1.invokeBeforeSend)(this.options.beforeSend, {
|
|
67
|
+
type: "span",
|
|
68
|
+
name,
|
|
69
|
+
attributes: sourceAttributes,
|
|
70
|
+
events: sourceEvents,
|
|
71
|
+
links: sourceLinks,
|
|
72
|
+
});
|
|
73
|
+
if (result === null)
|
|
74
|
+
continue;
|
|
75
|
+
if (result?.type === "span") {
|
|
76
|
+
name = result.name;
|
|
77
|
+
sourceAttributes = result.attributes;
|
|
78
|
+
// Hook-added events may omit time; default it to the span start so
|
|
79
|
+
// OTLP serialization stays valid.
|
|
80
|
+
sourceEvents = result.events.map((entry) => ({
|
|
81
|
+
time: span.startTime,
|
|
82
|
+
...entry,
|
|
83
|
+
}));
|
|
84
|
+
sourceLinks = result.links;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const attributes = (0, redaction_js_1.redactAttributesCopy)(sourceAttributes, config);
|
|
88
|
+
const events = sourceEvents.map((event) => event.attributes
|
|
89
|
+
? {
|
|
90
|
+
...event,
|
|
91
|
+
attributes: (0, redaction_js_1.redactAttributesCopy)(event.attributes, config),
|
|
92
|
+
}
|
|
93
|
+
: event);
|
|
94
|
+
const links = sourceLinks.map((link) => link.attributes
|
|
95
|
+
? {
|
|
96
|
+
...link,
|
|
97
|
+
attributes: (0, redaction_js_1.redactAttributesCopy)(link.attributes, config),
|
|
98
|
+
}
|
|
99
|
+
: link);
|
|
100
|
+
output.push(copySpan(span, name, attributes, events, links, redactedResource(span.resource, overlay, config)));
|
|
101
|
+
}
|
|
102
|
+
if (output.length === 0) {
|
|
103
|
+
callback({ code: core_1.ExportResultCode.SUCCESS });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
super.export(output, callback);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.FoamTraceExporter = FoamTraceExporter;
|
|
110
|
+
function copyLog(record, body, severityText, attributes, resource) {
|
|
111
|
+
return {
|
|
112
|
+
hrTime: record.hrTime,
|
|
113
|
+
hrTimeObserved: record.hrTimeObserved,
|
|
114
|
+
spanContext: record.spanContext,
|
|
115
|
+
severityText,
|
|
116
|
+
severityNumber: record.severityNumber,
|
|
117
|
+
body,
|
|
118
|
+
eventName: record.eventName,
|
|
119
|
+
resource,
|
|
120
|
+
instrumentationScope: record.instrumentationScope,
|
|
121
|
+
attributes,
|
|
122
|
+
droppedAttributesCount: record.droppedAttributesCount,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function redactBody(body, config) {
|
|
126
|
+
if (body === undefined)
|
|
127
|
+
return undefined;
|
|
128
|
+
if (typeof body === "string")
|
|
129
|
+
return (0, redaction_js_1.redactString)(body, config);
|
|
130
|
+
return (0, redaction_js_1.redactDeep)(body, config);
|
|
131
|
+
}
|
|
132
|
+
class FoamLogExporter extends exporter_logs_otlp_http_1.OTLPLogExporter {
|
|
133
|
+
stamp;
|
|
134
|
+
options;
|
|
135
|
+
constructor(token, stamp, options = {}) {
|
|
136
|
+
super({
|
|
137
|
+
url: `${endpoint_js_1.endpoint}${constants_js_1.FOAM_OTLP_LOGS_PATH}`,
|
|
138
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
139
|
+
});
|
|
140
|
+
this.stamp = stamp;
|
|
141
|
+
this.options = options;
|
|
142
|
+
}
|
|
143
|
+
export(records, callback) {
|
|
144
|
+
const config = redactionConfig(this.options);
|
|
145
|
+
const overlay = this.stamp ? (0, resources_1.resourceFromAttributes)(this.stamp) : undefined;
|
|
146
|
+
const output = [];
|
|
147
|
+
for (const record of records) {
|
|
148
|
+
let sourceBody = record.body;
|
|
149
|
+
let severityText = record.severityText;
|
|
150
|
+
let sourceAttributes = record.attributes;
|
|
151
|
+
if (this.options.beforeSend) {
|
|
152
|
+
const result = (0, before_send_js_1.invokeBeforeSend)(this.options.beforeSend, {
|
|
153
|
+
type: "log",
|
|
154
|
+
body: sourceBody,
|
|
155
|
+
severityText,
|
|
156
|
+
attributes: sourceAttributes,
|
|
157
|
+
});
|
|
158
|
+
if (result === null)
|
|
159
|
+
continue;
|
|
160
|
+
if (result?.type === "log") {
|
|
161
|
+
sourceBody = result.body;
|
|
162
|
+
severityText = result.severityText;
|
|
163
|
+
sourceAttributes = result.attributes;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const body = redactBody(sourceBody, config);
|
|
167
|
+
const attributes = (0, redaction_js_1.redactAttributesCopy)(sourceAttributes, config);
|
|
168
|
+
output.push(copyLog(record, body, severityText, attributes, redactedResource(record.resource, overlay, config)));
|
|
169
|
+
}
|
|
170
|
+
if (output.length === 0) {
|
|
171
|
+
callback({ code: core_1.ExportResultCode.SUCCESS });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
super.export(output, callback);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.FoamLogExporter = FoamLogExporter;
|
|
178
|
+
class FoamMetricExporter extends exporter_metrics_otlp_http_1.OTLPMetricExporter {
|
|
179
|
+
stamp;
|
|
180
|
+
options;
|
|
181
|
+
constructor(token, stamp, options = {}) {
|
|
182
|
+
super({
|
|
183
|
+
url: `${endpoint_js_1.endpoint}${constants_js_1.FOAM_OTLP_METRICS_PATH}`,
|
|
184
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
185
|
+
});
|
|
186
|
+
this.stamp = stamp;
|
|
187
|
+
this.options = options;
|
|
188
|
+
}
|
|
189
|
+
export(resourceMetrics, callback) {
|
|
190
|
+
const config = redactionConfig(this.options);
|
|
191
|
+
const overlay = this.stamp ? (0, resources_1.resourceFromAttributes)(this.stamp) : undefined;
|
|
192
|
+
super.export({
|
|
193
|
+
...resourceMetrics,
|
|
194
|
+
resource: redactedResource(resourceMetrics.resource, overlay, config),
|
|
195
|
+
scopeMetrics: resourceMetrics.scopeMetrics.map((scope) => ({
|
|
196
|
+
...scope,
|
|
197
|
+
metrics: scope.metrics.map((metric) => ({
|
|
198
|
+
...metric,
|
|
199
|
+
dataPoints: metric.dataPoints.map((point) => ({
|
|
200
|
+
...point,
|
|
201
|
+
attributes: (0, redaction_js_1.redactAttributesCopy)(point.attributes, config),
|
|
202
|
+
})),
|
|
203
|
+
})),
|
|
204
|
+
})),
|
|
205
|
+
}, callback);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.FoamMetricExporter = FoamMetricExporter;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { init, type InitOptions } from "./init.js";
|
|
2
|
+
export type { BeforeSendEvent, BeforeSendHook, } from "./before-send.js";
|
|
3
|
+
export type { RedactOptions } from "./redaction.js";
|
|
4
|
+
export { getState } from "./state.js";
|
|
5
|
+
export { setEndpoint } from "./endpoint.js";
|
|
6
|
+
export { createFoamIngestLogRecordProcessor, createFoamIngestMetricReader, createFoamIngestSpanProcessor, type FoamIngestOptions, } from "./ingest.js";
|
|
7
|
+
export { extractTraceContext, getBaggage, injectTraceContext, setBaggage, } from "./propagation.js";
|
|
8
|
+
export { addUpDownCounter, incrementCounter, recordHistogram, setMetric, } from "./metrics.js";
|
|
9
|
+
export { log, SeverityNumber } from "./logs.js";
|
|
10
|
+
export { recordException } from "./traces.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordException = exports.SeverityNumber = exports.log = exports.setMetric = exports.recordHistogram = exports.incrementCounter = exports.addUpDownCounter = exports.setBaggage = exports.injectTraceContext = exports.getBaggage = exports.extractTraceContext = exports.createFoamIngestSpanProcessor = exports.createFoamIngestMetricReader = exports.createFoamIngestLogRecordProcessor = exports.setEndpoint = exports.getState = exports.init = void 0;
|
|
4
|
+
var init_js_1 = require("./init.js");
|
|
5
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_js_1.init; } });
|
|
6
|
+
var state_js_1 = require("./state.js");
|
|
7
|
+
Object.defineProperty(exports, "getState", { enumerable: true, get: function () { return state_js_1.getState; } });
|
|
8
|
+
var endpoint_js_1 = require("./endpoint.js");
|
|
9
|
+
Object.defineProperty(exports, "setEndpoint", { enumerable: true, get: function () { return endpoint_js_1.setEndpoint; } });
|
|
10
|
+
var ingest_js_1 = require("./ingest.js");
|
|
11
|
+
Object.defineProperty(exports, "createFoamIngestLogRecordProcessor", { enumerable: true, get: function () { return ingest_js_1.createFoamIngestLogRecordProcessor; } });
|
|
12
|
+
Object.defineProperty(exports, "createFoamIngestMetricReader", { enumerable: true, get: function () { return ingest_js_1.createFoamIngestMetricReader; } });
|
|
13
|
+
Object.defineProperty(exports, "createFoamIngestSpanProcessor", { enumerable: true, get: function () { return ingest_js_1.createFoamIngestSpanProcessor; } });
|
|
14
|
+
var propagation_js_1 = require("./propagation.js");
|
|
15
|
+
Object.defineProperty(exports, "extractTraceContext", { enumerable: true, get: function () { return propagation_js_1.extractTraceContext; } });
|
|
16
|
+
Object.defineProperty(exports, "getBaggage", { enumerable: true, get: function () { return propagation_js_1.getBaggage; } });
|
|
17
|
+
Object.defineProperty(exports, "injectTraceContext", { enumerable: true, get: function () { return propagation_js_1.injectTraceContext; } });
|
|
18
|
+
Object.defineProperty(exports, "setBaggage", { enumerable: true, get: function () { return propagation_js_1.setBaggage; } });
|
|
19
|
+
var metrics_js_1 = require("./metrics.js");
|
|
20
|
+
Object.defineProperty(exports, "addUpDownCounter", { enumerable: true, get: function () { return metrics_js_1.addUpDownCounter; } });
|
|
21
|
+
Object.defineProperty(exports, "incrementCounter", { enumerable: true, get: function () { return metrics_js_1.incrementCounter; } });
|
|
22
|
+
Object.defineProperty(exports, "recordHistogram", { enumerable: true, get: function () { return metrics_js_1.recordHistogram; } });
|
|
23
|
+
Object.defineProperty(exports, "setMetric", { enumerable: true, get: function () { return metrics_js_1.setMetric; } });
|
|
24
|
+
var logs_js_1 = require("./logs.js");
|
|
25
|
+
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logs_js_1.log; } });
|
|
26
|
+
Object.defineProperty(exports, "SeverityNumber", { enumerable: true, get: function () { return logs_js_1.SeverityNumber; } });
|
|
27
|
+
var traces_js_1 = require("./traces.js");
|
|
28
|
+
Object.defineProperty(exports, "recordException", { enumerable: true, get: function () { return traces_js_1.recordException; } });
|
package/dist/ingest.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
3
|
+
import { type SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
4
|
+
import { type BeforeSendHook } from "./before-send.js";
|
|
5
|
+
import { type RedactOptions } from "./redaction.js";
|
|
6
|
+
export interface FoamIngestOptions {
|
|
7
|
+
readonly redact?: RedactOptions;
|
|
8
|
+
readonly beforeSend?: BeforeSendHook;
|
|
9
|
+
}
|
|
10
|
+
export declare function createFoamIngestSpanProcessor(name: string, environment: string, token: string, options?: FoamIngestOptions): SpanProcessor;
|
|
11
|
+
export declare function createFoamIngestLogRecordProcessor(name: string, environment: string, token: string, options?: FoamIngestOptions): LogRecordProcessor;
|
|
12
|
+
export declare function createFoamIngestMetricReader(name: string, environment: string, token: string, options?: FoamIngestOptions): PeriodicExportingMetricReader;
|
package/dist/ingest.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFoamIngestSpanProcessor = createFoamIngestSpanProcessor;
|
|
4
|
+
exports.createFoamIngestLogRecordProcessor = createFoamIngestLogRecordProcessor;
|
|
5
|
+
exports.createFoamIngestMetricReader = createFoamIngestMetricReader;
|
|
6
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
7
|
+
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
8
|
+
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
9
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
10
|
+
const api_logs_1 = require("@opentelemetry/api-logs");
|
|
11
|
+
const before_send_js_1 = require("./before-send.js");
|
|
12
|
+
const constants_js_1 = require("./constants.js");
|
|
13
|
+
const report_js_1 = require("./report.js");
|
|
14
|
+
const exporters_js_1 = require("./exporters.js");
|
|
15
|
+
const logs_js_1 = require("./logs.js");
|
|
16
|
+
const redaction_js_1 = require("./redaction.js");
|
|
17
|
+
const state_js_1 = require("./state.js");
|
|
18
|
+
function prepareOptions(options) {
|
|
19
|
+
return {
|
|
20
|
+
redaction: (0, redaction_js_1.resolveRedactionConfig)(options.redact),
|
|
21
|
+
beforeSend: (0, before_send_js_1.resolveBeforeSend)(options.beforeSend),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function prepareStamp(name, environment, token) {
|
|
25
|
+
if (!name?.trim() || !environment?.trim() || !token) {
|
|
26
|
+
throw new Error(`${constants_js_1.FOAM_IDENTIFIER_NAME}: name, environment, and token are required`);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
stamp: {
|
|
30
|
+
[semantic_conventions_1.ATTR_SERVICE_NAME]: name,
|
|
31
|
+
[semantic_conventions_1.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]: environment,
|
|
32
|
+
[constants_js_1.ATTR_FOAM_INGEST_HOST]: constants_js_1.FOAM_INGEST_HOST,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function reportIngestSignal(signal, name, environment, token) {
|
|
37
|
+
(0, state_js_1.setSignal)(signal, state_js_1.SignalSources.ingest);
|
|
38
|
+
// pcga11: report() prefixes the identifier itself; adding it here would double it.
|
|
39
|
+
(0, report_js_1.report)({
|
|
40
|
+
token: token,
|
|
41
|
+
name: name,
|
|
42
|
+
environment: environment,
|
|
43
|
+
severity: api_logs_1.SeverityNumber.INFO,
|
|
44
|
+
message: `ingest ${signal} processor attached`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function createFoamIngestSpanProcessor(name, environment, token, options = {}) {
|
|
48
|
+
const { stamp } = prepareStamp(name, environment, token);
|
|
49
|
+
const processor = new sdk_trace_base_1.BatchSpanProcessor(new exporters_js_1.FoamTraceExporter(token, stamp, prepareOptions(options)));
|
|
50
|
+
reportIngestSignal(state_js_1.Signals.traces, name, environment, token);
|
|
51
|
+
return processor;
|
|
52
|
+
}
|
|
53
|
+
function createFoamIngestLogRecordProcessor(name, environment, token, options = {}) {
|
|
54
|
+
const { stamp } = prepareStamp(name, environment, token);
|
|
55
|
+
const prepared = prepareOptions(options);
|
|
56
|
+
const processor = new sdk_logs_1.BatchLogRecordProcessor({
|
|
57
|
+
exporter: new exporters_js_1.FoamLogExporter(token, stamp, prepared),
|
|
58
|
+
});
|
|
59
|
+
(0, logs_js_1.ensureFoamLoggerProvider)(name, environment, token, stamp, prepared);
|
|
60
|
+
reportIngestSignal(state_js_1.Signals.logs, name, environment, token);
|
|
61
|
+
return processor;
|
|
62
|
+
}
|
|
63
|
+
function createFoamIngestMetricReader(name, environment, token, options = {}) {
|
|
64
|
+
const { stamp } = prepareStamp(name, environment, token);
|
|
65
|
+
const reader = new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
66
|
+
exporter: new exporters_js_1.FoamMetricExporter(token, stamp, prepareOptions(options)),
|
|
67
|
+
});
|
|
68
|
+
reportIngestSignal(state_js_1.Signals.metrics, name, environment, token);
|
|
69
|
+
return reader;
|
|
70
|
+
}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Attributes } from "@opentelemetry/api";
|
|
2
|
+
import { type Instrumentation } from "@opentelemetry/instrumentation";
|
|
3
|
+
import { type LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
4
|
+
import { type MetricReader } from "@opentelemetry/sdk-metrics";
|
|
5
|
+
import { type SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
6
|
+
import { type BeforeSendHook } from "./before-send.js";
|
|
7
|
+
import { type RedactOptions } from "./redaction.js";
|
|
8
|
+
export interface InitOptions {
|
|
9
|
+
name: string;
|
|
10
|
+
environment: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
sampleRate?: number;
|
|
14
|
+
disableLogSending?: boolean;
|
|
15
|
+
networkCapture?: "off" | "basic" | "advanced";
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
redact?: RedactOptions;
|
|
18
|
+
beforeSend?: BeforeSendHook;
|
|
19
|
+
additionalInstrumentations?: readonly Instrumentation[];
|
|
20
|
+
additionalSpanProcessors?: readonly SpanProcessor[];
|
|
21
|
+
additionalLogRecordProcessors?: readonly LogRecordProcessor[];
|
|
22
|
+
additionalMetricReaders?: readonly MetricReader[];
|
|
23
|
+
additionalResourceAttributes?: Attributes;
|
|
24
|
+
ignoredOutboundHosts?: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export declare function init(options: InitOptions): void;
|