@osfactory/otel-hook 0.6.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 +156 -8
- package/dist/cli.js +219 -60
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +132 -1
- package/dist/config.js +171 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +208 -57
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +6 -1
- package/dist/integration.js +54 -55
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.js +7 -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 +45 -45
- package/dist/telemetry.js.map +1 -1
- package/package.json +9 -9
package/dist/integration.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { P as ProviderRegistry } from './registry-CIVvRlVK.js';
|
|
|
7
7
|
import { a as DeliveryOrigin, c as DeliveryUnavailableReason, H as HookIngestInput, e as HookIngestOutcome, U as UsageObservation, O as OtelHook } from './hook-Dh8OO4Wa.js';
|
|
8
8
|
import { C as Clock, I as IdGenerator, d as Logger, W as WorktreeLocator } from './ports-n7KFOpKo.js';
|
|
9
9
|
import { F as FilesystemStateStore } from './filesystem-store-r-nNA3BA.js';
|
|
10
|
-
import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink, b as DurableSpool, D as DurableLogSpool } from './otlp-log-sink-
|
|
10
|
+
import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink, b as DurableSpool, D as DurableLogSpool } from './otlp-log-sink-zuHojHSP.js';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import './primitives-CJ8-rn-f.js';
|
|
13
13
|
import './taxonomy-DwhTtuWd.js';
|
|
@@ -241,6 +241,11 @@ type HookRuntimeOptions = {
|
|
|
241
241
|
readonly providerNamespace: string;
|
|
242
242
|
/** Exporter header *values*, deliberately absent from the config snapshot. */
|
|
243
243
|
readonly headers?: Readonly<Record<string, string>>;
|
|
244
|
+
/**
|
|
245
|
+
* Header values for the logs signal only, when they differ from the traces
|
|
246
|
+
* signal's (`OTEL_EXPORTER_OTLP_LOGS_HEADERS`). Defaults to {@link headers}.
|
|
247
|
+
*/
|
|
248
|
+
readonly logHeaders?: Readonly<Record<string, string>>;
|
|
244
249
|
readonly clock?: Clock;
|
|
245
250
|
readonly ids?: IdGenerator;
|
|
246
251
|
readonly logger?: Logger;
|
package/dist/integration.js
CHANGED
|
@@ -655,27 +655,7 @@ var createLifecycleJanitor = (options) => {
|
|
|
655
655
|
// src/telemetry/semconv.ts
|
|
656
656
|
import { createHash } from "crypto";
|
|
657
657
|
import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
|
|
658
|
-
|
|
659
|
-
// node_modules/@opentelemetry/core/build/esm/common/time.js
|
|
660
|
-
var NANOSECOND_DIGITS = 9;
|
|
661
|
-
var NANOSECOND_DIGITS_IN_MILLIS = 6;
|
|
662
|
-
var MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
|
|
663
|
-
var SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
|
|
664
|
-
function millisToHrTime(epochMillis) {
|
|
665
|
-
const epochSeconds = epochMillis / 1e3;
|
|
666
|
-
const seconds = Math.trunc(epochSeconds);
|
|
667
|
-
const nanos = Math.round(epochMillis % 1e3 * MILLISECONDS_TO_NANOSECONDS);
|
|
668
|
-
return [seconds, nanos];
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// node_modules/@opentelemetry/core/build/esm/ExportResult.js
|
|
672
|
-
var ExportResultCode;
|
|
673
|
-
(function(ExportResultCode2) {
|
|
674
|
-
ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
|
|
675
|
-
ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
|
|
676
|
-
})(ExportResultCode || (ExportResultCode = {}));
|
|
677
|
-
|
|
678
|
-
// src/telemetry/semconv.ts
|
|
658
|
+
import { millisToHrTime } from "@opentelemetry/core";
|
|
679
659
|
import {
|
|
680
660
|
ATTR_ERROR_TYPE,
|
|
681
661
|
ATTR_GEN_AI_OPERATION_NAME,
|
|
@@ -692,7 +672,7 @@ import {
|
|
|
692
672
|
} from "@opentelemetry/semantic-conventions/incubating";
|
|
693
673
|
|
|
694
674
|
// src/version.ts
|
|
695
|
-
var VERSION = "0.
|
|
675
|
+
var VERSION = "0.8.0";
|
|
696
676
|
|
|
697
677
|
// src/telemetry/export-identity.ts
|
|
698
678
|
import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
|
|
@@ -1401,7 +1381,10 @@ var ATTR_OTELHOOK_INVOCATION_ID = "otelhook.invocation.id";
|
|
|
1401
1381
|
var ATTR_OTELHOOK_PROVIDER_ID = "otelhook.provider.id";
|
|
1402
1382
|
var ATTR_OTELHOOK_PROVIDER_VERSION = "otelhook.provider.version";
|
|
1403
1383
|
var ATTR_OTELHOOK_WORKSPACE_ID = "otelhook.workspace.id";
|
|
1404
|
-
var
|
|
1384
|
+
var EXTERNAL_SESSION_KEY_ATTRIBUTES = Object.freeze([
|
|
1385
|
+
ATTR_SESSION_ID,
|
|
1386
|
+
"har.session_key"
|
|
1387
|
+
]);
|
|
1405
1388
|
var ATTR_OTELHOOK_SUBAGENT_ID = "otelhook.subagent.id";
|
|
1406
1389
|
var ATTR_VCS_REF_HEAD_NAME = "vcs.ref.head.name";
|
|
1407
1390
|
var ATTR_OTELHOOK_TARGET_WORKSPACE_ID = "otelhook.target.workspace.id";
|
|
@@ -1424,21 +1407,26 @@ var targetAttributes = (event2) => {
|
|
|
1424
1407
|
};
|
|
1425
1408
|
var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
|
|
1426
1409
|
var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
1427
|
-
var
|
|
1410
|
+
var PASSTHROUGH_RESOURCE_PREFIXES = Object.freeze(["har.", "factory.", "vcs."]);
|
|
1411
|
+
var LOCAL_ONLY_RESOURCE_PREFIX = "factory.local.";
|
|
1412
|
+
var isPassthroughKey = (key) => PASSTHROUGH_RESOURCE_PREFIXES.some((prefix) => key.startsWith(prefix)) && !key.startsWith(LOCAL_ONLY_RESOURCE_PREFIX) && key !== "factory.local";
|
|
1413
|
+
var passthroughResourceAttributes = (resource) => {
|
|
1428
1414
|
const attributes = {};
|
|
1429
1415
|
for (const [key, value] of Object.entries(resource.attributes)) {
|
|
1430
|
-
if (key
|
|
1416
|
+
if (isPassthroughKey(key) && isPrimitiveAttribute(value)) {
|
|
1431
1417
|
attributes[key] = value;
|
|
1432
1418
|
}
|
|
1433
1419
|
}
|
|
1434
1420
|
return attributes;
|
|
1435
1421
|
};
|
|
1436
1422
|
var resolveExportedSessionId = (eventSessionId, resource) => {
|
|
1437
|
-
const
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1423
|
+
for (const key of EXTERNAL_SESSION_KEY_ATTRIBUTES) {
|
|
1424
|
+
const supplied = resource.attributes[key];
|
|
1425
|
+
if (typeof supplied === "string") {
|
|
1426
|
+
const trimmed = supplied.trim();
|
|
1427
|
+
if (trimmed.length > 0) {
|
|
1428
|
+
return { sessionId: trimmed, providerSessionId: eventSessionId };
|
|
1429
|
+
}
|
|
1442
1430
|
}
|
|
1443
1431
|
}
|
|
1444
1432
|
return { sessionId: eventSessionId, providerSessionId: eventSessionId };
|
|
@@ -1459,7 +1447,7 @@ var exportIdentityAttributes = (event2, resource, ids) => {
|
|
|
1459
1447
|
...event2.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event2.provenance.providerVersion },
|
|
1460
1448
|
[ATTR_OTELHOOK_WORKSPACE_ID]: event2.workspace.workspaceId,
|
|
1461
1449
|
...event2.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event2.subagentId },
|
|
1462
|
-
...
|
|
1450
|
+
...passthroughResourceAttributes(resource),
|
|
1463
1451
|
...hexTraceAttributes(ids)
|
|
1464
1452
|
};
|
|
1465
1453
|
};
|
|
@@ -1609,12 +1597,12 @@ var pickTarget = (attributes) => {
|
|
|
1609
1597
|
}
|
|
1610
1598
|
return picked;
|
|
1611
1599
|
};
|
|
1612
|
-
var withoutTarget = (attributes) => {
|
|
1600
|
+
var withoutTarget = (attributes, resource) => {
|
|
1613
1601
|
const rest = { ...attributes };
|
|
1614
1602
|
for (const key of TARGET_KEYS) {
|
|
1615
1603
|
delete rest[key];
|
|
1616
1604
|
}
|
|
1617
|
-
return rest;
|
|
1605
|
+
return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
|
|
1618
1606
|
};
|
|
1619
1607
|
var rankOf = (candidate) => {
|
|
1620
1608
|
const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
|
|
@@ -1719,7 +1707,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
1719
1707
|
name = "session";
|
|
1720
1708
|
kind = SpanKind.INTERNAL;
|
|
1721
1709
|
attributes = {
|
|
1722
|
-
...withoutTarget(attributes),
|
|
1710
|
+
...withoutTarget(attributes, resource),
|
|
1723
1711
|
...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
|
|
1724
1712
|
...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
|
|
1725
1713
|
...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
|
|
@@ -1760,7 +1748,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
1760
1748
|
kind = SpanKind.CLIENT;
|
|
1761
1749
|
attributes = {
|
|
1762
1750
|
// Target keys are re-chosen below as one unit, never mixed across edges.
|
|
1763
|
-
...withoutTarget(attributes),
|
|
1751
|
+
...withoutTarget(attributes, resource),
|
|
1764
1752
|
[ATTR_GEN_AI_TOOL_NAME]: toolName,
|
|
1765
1753
|
[ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
|
|
1766
1754
|
...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
|
|
@@ -5160,8 +5148,26 @@ var createFileDurableSpool = (options) => createSpoolQueue({
|
|
|
5160
5148
|
|
|
5161
5149
|
// src/telemetry/otlp-log-sink.ts
|
|
5162
5150
|
import { TraceFlags as TraceFlags3 } from "@opentelemetry/api";
|
|
5151
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
5152
|
+
import { millisToHrTime as millisToHrTime3 } from "@opentelemetry/core";
|
|
5163
5153
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
5164
5154
|
|
|
5155
|
+
// src/config/otlp-endpoint.ts
|
|
5156
|
+
var OTLP_ENDPOINT_VARIABLES = Object.freeze({
|
|
5157
|
+
generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
5158
|
+
traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
5159
|
+
logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
|
|
5160
|
+
});
|
|
5161
|
+
var OTLP_TRACES_PATH = "/v1/traces";
|
|
5162
|
+
var OTLP_LOGS_PATH = "/v1/logs";
|
|
5163
|
+
var withoutTrailingSlashes = (value) => {
|
|
5164
|
+
let end = value.length;
|
|
5165
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) {
|
|
5166
|
+
end -= 1;
|
|
5167
|
+
}
|
|
5168
|
+
return value.slice(0, end);
|
|
5169
|
+
};
|
|
5170
|
+
|
|
5165
5171
|
// src/telemetry/exporter-resource.ts
|
|
5166
5172
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
5167
5173
|
var resourceFromExporterPolicy = (policy) => resourceFromAttributes({
|
|
@@ -5198,8 +5204,8 @@ var replayResource = (attributes, policy) => {
|
|
|
5198
5204
|
};
|
|
5199
5205
|
|
|
5200
5206
|
// src/telemetry/log-records.ts
|
|
5201
|
-
import { TraceFlags as TraceFlags2 } from "@opentelemetry/api";
|
|
5202
|
-
import {
|
|
5207
|
+
import { SeverityNumber, TraceFlags as TraceFlags2 } from "@opentelemetry/api";
|
|
5208
|
+
import { millisToHrTime as millisToHrTime2 } from "@opentelemetry/core";
|
|
5203
5209
|
import {
|
|
5204
5210
|
ATTR_ERROR_TYPE as ATTR_ERROR_TYPE2,
|
|
5205
5211
|
ATTR_GEN_AI_OPERATION_NAME as ATTR_GEN_AI_OPERATION_NAME2,
|
|
@@ -5467,14 +5473,14 @@ var contentAttributes = (fact, body) => ({
|
|
|
5467
5473
|
});
|
|
5468
5474
|
var buildRecord = (input) => {
|
|
5469
5475
|
const severityNumber = severityFor(input.event);
|
|
5470
|
-
const
|
|
5476
|
+
const hrTime = millisToHrTime2(input.event.occurredAt);
|
|
5471
5477
|
return {
|
|
5472
|
-
hrTime
|
|
5478
|
+
hrTime,
|
|
5473
5479
|
// A hook observes an event that already happened, and this mapping is pure —
|
|
5474
5480
|
// there is no clock here to read a real observation time from. Reporting the
|
|
5475
5481
|
// occurrence time for both is the honest answer: it says "this is when it
|
|
5476
5482
|
// happened" twice rather than inventing a second, wrong timestamp.
|
|
5477
|
-
hrTimeObserved:
|
|
5483
|
+
hrTimeObserved: hrTime,
|
|
5478
5484
|
spanContext: input.spanContext,
|
|
5479
5485
|
severityNumber,
|
|
5480
5486
|
severityText: SEVERITY_TEXT[severityNumber] ?? "INFO",
|
|
@@ -5564,15 +5570,6 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
5564
5570
|
};
|
|
5565
5571
|
|
|
5566
5572
|
// src/telemetry/otlp-log-sink.ts
|
|
5567
|
-
var OTLP_TRACES_PATH = "/v1/traces";
|
|
5568
|
-
var OTLP_LOGS_PATH = "/v1/logs";
|
|
5569
|
-
var withoutTrailingSlashes = (value) => {
|
|
5570
|
-
let end = value.length;
|
|
5571
|
-
while (end > 0 && value.charCodeAt(end - 1) === 47) {
|
|
5572
|
-
end -= 1;
|
|
5573
|
-
}
|
|
5574
|
-
return value.slice(0, end);
|
|
5575
|
-
};
|
|
5576
5573
|
var resolveLogsEndpoint = (exporter) => {
|
|
5577
5574
|
if (exporter.logs.endpoint !== void 0) {
|
|
5578
5575
|
return { endpoint: exporter.logs.endpoint, derived: false };
|
|
@@ -5626,8 +5623,8 @@ var deserializeRecord = (serialized, resource, scope) => {
|
|
|
5626
5623
|
isRemote: false
|
|
5627
5624
|
};
|
|
5628
5625
|
return {
|
|
5629
|
-
hrTime:
|
|
5630
|
-
hrTimeObserved:
|
|
5626
|
+
hrTime: millisToHrTime3(serialized.timeMillis),
|
|
5627
|
+
hrTimeObserved: millisToHrTime3(serialized.observedTimeMillis),
|
|
5631
5628
|
...spanContext === void 0 ? {} : { spanContext },
|
|
5632
5629
|
severityNumber: serialized.severityNumber,
|
|
5633
5630
|
...serialized.severityText === void 0 ? {} : { severityText: serialized.severityText },
|
|
@@ -5842,6 +5839,7 @@ var createOtlpLogSink = (options) => {
|
|
|
5842
5839
|
};
|
|
5843
5840
|
|
|
5844
5841
|
// src/telemetry/otlp-sink.ts
|
|
5842
|
+
import { ExportResultCode as ExportResultCode2 } from "@opentelemetry/core";
|
|
5845
5843
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
5846
5844
|
var chunk2 = (items, size) => {
|
|
5847
5845
|
if (size <= 0 || items.length <= size) {
|
|
@@ -5929,7 +5927,7 @@ var createOtlpTraceSink = (options) => {
|
|
|
5929
5927
|
const batchResource = replayResource(batch.resourceAttributes, options.exporter);
|
|
5930
5928
|
const spans = batch.spans.map((span) => deserializeSpan(span, batchResource, batch.instrumentationScope));
|
|
5931
5929
|
const result = await exportSpans(spans);
|
|
5932
|
-
return result.code ===
|
|
5930
|
+
return result.code === ExportResultCode2.SUCCESS;
|
|
5933
5931
|
};
|
|
5934
5932
|
const resolveCorrelations = async (events) => {
|
|
5935
5933
|
if (options.correlate === void 0) {
|
|
@@ -5961,9 +5959,9 @@ var createOtlpTraceSink = (options) => {
|
|
|
5961
5959
|
try {
|
|
5962
5960
|
result = await exportSpans(batch);
|
|
5963
5961
|
} catch (thrown) {
|
|
5964
|
-
result = { code:
|
|
5962
|
+
result = { code: ExportResultCode2.FAILED, error: thrown instanceof Error ? thrown : new Error("export threw") };
|
|
5965
5963
|
}
|
|
5966
|
-
if (result.code ===
|
|
5964
|
+
if (result.code === ExportResultCode2.SUCCESS) {
|
|
5967
5965
|
accepted += batch.length;
|
|
5968
5966
|
health.recordSuccess(batch.length, options.clock.now());
|
|
5969
5967
|
continue;
|
|
@@ -6162,9 +6160,10 @@ var createHookRuntime = (options) => {
|
|
|
6162
6160
|
...spool === void 0 ? {} : { spool },
|
|
6163
6161
|
correlate
|
|
6164
6162
|
});
|
|
6163
|
+
const logHeaders = options.logHeaders ?? options.headers;
|
|
6165
6164
|
const logSink = createOtlpLogSink({
|
|
6166
6165
|
exporter: options.config.exporter,
|
|
6167
|
-
...
|
|
6166
|
+
...logHeaders === void 0 ? {} : { headers: logHeaders },
|
|
6168
6167
|
providerId: options.providerNamespace,
|
|
6169
6168
|
installationId: options.installationId,
|
|
6170
6169
|
clock,
|