@osfactory/otel-hook 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -2
- package/dist/cli.js +59 -50
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +48 -1
- package/dist/config.js +36 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +61 -50
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +1 -1
- package/dist/integration.js +41 -48
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.js +3 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/{otlp-log-sink-eUEjaLhk.d.ts → otlp-log-sink-zuHojHSP.d.ts} +16 -0
- package/dist/telemetry.d.ts +2 -2
- package/dist/telemetry.js +34 -39
- package/dist/telemetry.js.map +1 -1
- package/package.json +9 -9
|
@@ -368,6 +368,22 @@ interface DurableLogSpool {
|
|
|
368
368
|
}
|
|
369
369
|
declare const createFileDurableLogSpool: (options: DurableLogSpoolOptions) => DurableLogSpool;
|
|
370
370
|
|
|
371
|
+
/**
|
|
372
|
+
* OTLP HTTP/protobuf log sink.
|
|
373
|
+
*
|
|
374
|
+
* The logs counterpart of `otlp-sink.ts`, and deliberately its mirror image:
|
|
375
|
+
* semantic mapping lives entirely in `log-records.ts`, and this module owns only
|
|
376
|
+
* batching, delivery, bounded flush/shutdown, health tracking, and — when a spool
|
|
377
|
+
* is configured — persisting what a down collector rejected. Every failure mode
|
|
378
|
+
* (disabled config, missing or underivable endpoint, export failure, timeout,
|
|
379
|
+
* spool write failure) degrades to a reported diagnostic rather than a thrown
|
|
380
|
+
* error, preserving the hook's fail-open contract.
|
|
381
|
+
*
|
|
382
|
+
* The two sinks are separate objects rather than one exporter with two encoders
|
|
383
|
+
* because they fail independently: a collector that has no logs receiver, or an
|
|
384
|
+
* operator who pointed logs at the wrong port, must cost the logs signal and
|
|
385
|
+
* nothing else. The trace pipeline is the one an installation already depends on.
|
|
386
|
+
*/
|
|
371
387
|
/**
|
|
372
388
|
* Where log records are posted.
|
|
373
389
|
*
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { b as SpanCorrelationResolver } from './semconv-fPRb-dpU.js';
|
|
2
2
|
export { D as DEFAULT_INSTRUMENTATION_SCOPE, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, S as SemanticMappingOptions, a as SpanCorrelation, c as SpanDisposition, d as SpanFamily, e as SpanOrphanClassification, f as SpanPairing, g as SpanScopeRef, h as canonicalEventTraceIdentities, i as canonicalEventsToReadableSpans, p as parentScopeRefOf, s as spanScopeRefOf, j as startOnlySpanAttributes } from './semconv-fPRb-dpU.js';
|
|
3
|
-
import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink } from './otlp-log-sink-
|
|
4
|
-
export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableSpool, c as DurableSpoolOptions, L as LOG_MAPPING_VERSION, d as LOG_SIGNALS, e as LogContentPolicy, f as LogMappingOptions, g as LogMappingResult, h as LogSignal, i as LogSpoolBatch, j as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, k as MAX_LOG_RECORDS_PER_BATCH, l as MAX_LOG_RECORDS_PER_EVENT, m as MCP_TOOL_NAME_PATTERN, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, p as OtlpTraceSinkOptions, S as SerializedLogRecord, q as SerializedSpan, r as SpoolBatch, s as SpoolDrainResult, t as SpoolEnqueueResult, u as canonicalEventsToLogRecords, v as createFileDurableLogSpool, w as createFileDurableSpool, x as createOtlpLogSink, y as createOtlpTraceSink, z as describeLogsDeliverability, A as logSignalOf, B as logSignalsForLifecycleEvents, E as resolveLogsEndpoint } from './otlp-log-sink-
|
|
3
|
+
import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink } from './otlp-log-sink-zuHojHSP.js';
|
|
4
|
+
export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableSpool, c as DurableSpoolOptions, L as LOG_MAPPING_VERSION, d as LOG_SIGNALS, e as LogContentPolicy, f as LogMappingOptions, g as LogMappingResult, h as LogSignal, i as LogSpoolBatch, j as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, k as MAX_LOG_RECORDS_PER_BATCH, l as MAX_LOG_RECORDS_PER_EVENT, m as MCP_TOOL_NAME_PATTERN, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, p as OtlpTraceSinkOptions, S as SerializedLogRecord, q as SerializedSpan, r as SpoolBatch, s as SpoolDrainResult, t as SpoolEnqueueResult, u as canonicalEventsToLogRecords, v as createFileDurableLogSpool, w as createFileDurableSpool, x as createOtlpLogSink, y as createOtlpTraceSink, z as describeLogsDeliverability, A as logSignalOf, B as logSignalsForLifecycleEvents, E as resolveLogsEndpoint } from './otlp-log-sink-zuHojHSP.js';
|
|
5
5
|
import { DeliveryHealthSnapshot } from './diagnostics.js';
|
|
6
6
|
import { g as TelemetrySink } from './ports-n7KFOpKo.js';
|
|
7
7
|
import '@opentelemetry/api';
|
package/dist/telemetry.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
// src/telemetry/semconv.ts
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
3
|
import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
|
|
4
|
-
|
|
5
|
-
// node_modules/@opentelemetry/core/build/esm/common/time.js
|
|
6
|
-
var NANOSECOND_DIGITS = 9;
|
|
7
|
-
var NANOSECOND_DIGITS_IN_MILLIS = 6;
|
|
8
|
-
var MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
|
|
9
|
-
var SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
|
|
10
|
-
function millisToHrTime(epochMillis) {
|
|
11
|
-
const epochSeconds = epochMillis / 1e3;
|
|
12
|
-
const seconds = Math.trunc(epochSeconds);
|
|
13
|
-
const nanos = Math.round(epochMillis % 1e3 * MILLISECONDS_TO_NANOSECONDS);
|
|
14
|
-
return [seconds, nanos];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// node_modules/@opentelemetry/core/build/esm/ExportResult.js
|
|
18
|
-
var ExportResultCode;
|
|
19
|
-
(function(ExportResultCode2) {
|
|
20
|
-
ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
|
|
21
|
-
ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
|
|
22
|
-
})(ExportResultCode || (ExportResultCode = {}));
|
|
23
|
-
|
|
24
|
-
// src/telemetry/semconv.ts
|
|
4
|
+
import { millisToHrTime } from "@opentelemetry/core";
|
|
25
5
|
import {
|
|
26
6
|
ATTR_ERROR_TYPE,
|
|
27
7
|
ATTR_GEN_AI_OPERATION_NAME,
|
|
@@ -38,7 +18,7 @@ import {
|
|
|
38
18
|
} from "@opentelemetry/semantic-conventions/incubating";
|
|
39
19
|
|
|
40
20
|
// src/version.ts
|
|
41
|
-
var VERSION = "0.
|
|
21
|
+
var VERSION = "0.8.0";
|
|
42
22
|
|
|
43
23
|
// src/telemetry/export-identity.ts
|
|
44
24
|
import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
|
|
@@ -851,10 +831,13 @@ var targetAttributes = (event2) => {
|
|
|
851
831
|
};
|
|
852
832
|
var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
|
|
853
833
|
var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
854
|
-
var
|
|
834
|
+
var PASSTHROUGH_RESOURCE_PREFIXES = Object.freeze(["har.", "factory.", "vcs."]);
|
|
835
|
+
var LOCAL_ONLY_RESOURCE_PREFIX = "factory.local.";
|
|
836
|
+
var isPassthroughKey = (key) => PASSTHROUGH_RESOURCE_PREFIXES.some((prefix) => key.startsWith(prefix)) && !key.startsWith(LOCAL_ONLY_RESOURCE_PREFIX) && key !== "factory.local";
|
|
837
|
+
var passthroughResourceAttributes = (resource) => {
|
|
855
838
|
const attributes = {};
|
|
856
839
|
for (const [key, value] of Object.entries(resource.attributes)) {
|
|
857
|
-
if (key
|
|
840
|
+
if (isPassthroughKey(key) && isPrimitiveAttribute(value)) {
|
|
858
841
|
attributes[key] = value;
|
|
859
842
|
}
|
|
860
843
|
}
|
|
@@ -888,7 +871,7 @@ var exportIdentityAttributes = (event2, resource, ids) => {
|
|
|
888
871
|
...event2.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event2.provenance.providerVersion },
|
|
889
872
|
[ATTR_OTELHOOK_WORKSPACE_ID]: event2.workspace.workspaceId,
|
|
890
873
|
...event2.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event2.subagentId },
|
|
891
|
-
...
|
|
874
|
+
...passthroughResourceAttributes(resource),
|
|
892
875
|
...hexTraceAttributes(ids)
|
|
893
876
|
};
|
|
894
877
|
};
|
|
@@ -1038,12 +1021,12 @@ var pickTarget = (attributes) => {
|
|
|
1038
1021
|
}
|
|
1039
1022
|
return picked;
|
|
1040
1023
|
};
|
|
1041
|
-
var withoutTarget = (attributes) => {
|
|
1024
|
+
var withoutTarget = (attributes, resource) => {
|
|
1042
1025
|
const rest = { ...attributes };
|
|
1043
1026
|
for (const key of TARGET_KEYS) {
|
|
1044
1027
|
delete rest[key];
|
|
1045
1028
|
}
|
|
1046
|
-
return rest;
|
|
1029
|
+
return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
|
|
1047
1030
|
};
|
|
1048
1031
|
var rankOf = (candidate) => {
|
|
1049
1032
|
const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
|
|
@@ -1148,7 +1131,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
1148
1131
|
name = "session";
|
|
1149
1132
|
kind = SpanKind.INTERNAL;
|
|
1150
1133
|
attributes = {
|
|
1151
|
-
...withoutTarget(attributes),
|
|
1134
|
+
...withoutTarget(attributes, resource),
|
|
1152
1135
|
...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
|
|
1153
1136
|
...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
|
|
1154
1137
|
...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
|
|
@@ -1189,7 +1172,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
1189
1172
|
kind = SpanKind.CLIENT;
|
|
1190
1173
|
attributes = {
|
|
1191
1174
|
// Target keys are re-chosen below as one unit, never mixed across edges.
|
|
1192
|
-
...withoutTarget(attributes),
|
|
1175
|
+
...withoutTarget(attributes, resource),
|
|
1193
1176
|
[ATTR_GEN_AI_TOOL_NAME]: toolName,
|
|
1194
1177
|
[ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
|
|
1195
1178
|
...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
|
|
@@ -1660,6 +1643,7 @@ var createFileDurableSpool = (options) => createSpoolQueue({
|
|
|
1660
1643
|
});
|
|
1661
1644
|
|
|
1662
1645
|
// src/telemetry/otlp-sink.ts
|
|
1646
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
1663
1647
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
1664
1648
|
|
|
1665
1649
|
// src/errors/index.ts
|
|
@@ -2115,8 +2099,8 @@ var createOtlpTraceSink = (options) => {
|
|
|
2115
2099
|
};
|
|
2116
2100
|
|
|
2117
2101
|
// src/telemetry/log-records.ts
|
|
2118
|
-
import { TraceFlags as TraceFlags2 } from "@opentelemetry/api";
|
|
2119
|
-
import {
|
|
2102
|
+
import { SeverityNumber, TraceFlags as TraceFlags2 } from "@opentelemetry/api";
|
|
2103
|
+
import { millisToHrTime as millisToHrTime2 } from "@opentelemetry/core";
|
|
2120
2104
|
import {
|
|
2121
2105
|
ATTR_ERROR_TYPE as ATTR_ERROR_TYPE2,
|
|
2122
2106
|
ATTR_GEN_AI_OPERATION_NAME as ATTR_GEN_AI_OPERATION_NAME2,
|
|
@@ -2437,14 +2421,14 @@ var contentAttributes = (fact, body) => ({
|
|
|
2437
2421
|
});
|
|
2438
2422
|
var buildRecord = (input) => {
|
|
2439
2423
|
const severityNumber = severityFor(input.event);
|
|
2440
|
-
const
|
|
2424
|
+
const hrTime = millisToHrTime2(input.event.occurredAt);
|
|
2441
2425
|
return {
|
|
2442
|
-
hrTime
|
|
2426
|
+
hrTime,
|
|
2443
2427
|
// A hook observes an event that already happened, and this mapping is pure —
|
|
2444
2428
|
// there is no clock here to read a real observation time from. Reporting the
|
|
2445
2429
|
// occurrence time for both is the honest answer: it says "this is when it
|
|
2446
2430
|
// happened" twice rather than inventing a second, wrong timestamp.
|
|
2447
|
-
hrTimeObserved:
|
|
2431
|
+
hrTimeObserved: hrTime,
|
|
2448
2432
|
spanContext: input.spanContext,
|
|
2449
2433
|
severityNumber,
|
|
2450
2434
|
severityText: SEVERITY_TEXT[severityNumber] ?? "INFO",
|
|
@@ -2634,7 +2618,16 @@ var createFileDurableLogSpool = (options) => createSpoolQueue({
|
|
|
2634
2618
|
|
|
2635
2619
|
// src/telemetry/otlp-log-sink.ts
|
|
2636
2620
|
import { TraceFlags as TraceFlags3 } from "@opentelemetry/api";
|
|
2621
|
+
import { ExportResultCode as ExportResultCode2 } from "@opentelemetry/core";
|
|
2622
|
+
import { millisToHrTime as millisToHrTime3 } from "@opentelemetry/core";
|
|
2637
2623
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
2624
|
+
|
|
2625
|
+
// src/config/otlp-endpoint.ts
|
|
2626
|
+
var OTLP_ENDPOINT_VARIABLES = Object.freeze({
|
|
2627
|
+
generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
2628
|
+
traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
2629
|
+
logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
|
|
2630
|
+
});
|
|
2638
2631
|
var OTLP_TRACES_PATH = "/v1/traces";
|
|
2639
2632
|
var OTLP_LOGS_PATH = "/v1/logs";
|
|
2640
2633
|
var withoutTrailingSlashes = (value) => {
|
|
@@ -2644,6 +2637,8 @@ var withoutTrailingSlashes = (value) => {
|
|
|
2644
2637
|
}
|
|
2645
2638
|
return value.slice(0, end);
|
|
2646
2639
|
};
|
|
2640
|
+
|
|
2641
|
+
// src/telemetry/otlp-log-sink.ts
|
|
2647
2642
|
var resolveLogsEndpoint = (exporter) => {
|
|
2648
2643
|
if (exporter.logs.endpoint !== void 0) {
|
|
2649
2644
|
return { endpoint: exporter.logs.endpoint, derived: false };
|
|
@@ -2697,8 +2692,8 @@ var deserializeRecord = (serialized, resource, scope) => {
|
|
|
2697
2692
|
isRemote: false
|
|
2698
2693
|
};
|
|
2699
2694
|
return {
|
|
2700
|
-
hrTime:
|
|
2701
|
-
hrTimeObserved:
|
|
2695
|
+
hrTime: millisToHrTime3(serialized.timeMillis),
|
|
2696
|
+
hrTimeObserved: millisToHrTime3(serialized.observedTimeMillis),
|
|
2702
2697
|
...spanContext === void 0 ? {} : { spanContext },
|
|
2703
2698
|
severityNumber: serialized.severityNumber,
|
|
2704
2699
|
...serialized.severityText === void 0 ? {} : { severityText: serialized.severityText },
|
|
@@ -2799,7 +2794,7 @@ var createOtlpLogSink = (options) => {
|
|
|
2799
2794
|
(record) => deserializeRecord(record, batchResource, batch.instrumentationScope)
|
|
2800
2795
|
);
|
|
2801
2796
|
const result = await exportRecords(records);
|
|
2802
|
-
return result.code ===
|
|
2797
|
+
return result.code === ExportResultCode2.SUCCESS;
|
|
2803
2798
|
};
|
|
2804
2799
|
const resolveCorrelations = async (events) => {
|
|
2805
2800
|
if (options.correlate === void 0) {
|
|
@@ -2841,11 +2836,11 @@ var createOtlpLogSink = (options) => {
|
|
|
2841
2836
|
result = await exportRecords(batch);
|
|
2842
2837
|
} catch (thrown) {
|
|
2843
2838
|
result = {
|
|
2844
|
-
code:
|
|
2839
|
+
code: ExportResultCode2.FAILED,
|
|
2845
2840
|
error: thrown instanceof Error ? thrown : new Error("export threw")
|
|
2846
2841
|
};
|
|
2847
2842
|
}
|
|
2848
|
-
if (result.code ===
|
|
2843
|
+
if (result.code === ExportResultCode2.SUCCESS) {
|
|
2849
2844
|
accepted += batch.length;
|
|
2850
2845
|
health.recordSuccess(batch.length, options.clock.now());
|
|
2851
2846
|
continue;
|