@smthrs/observability 0.34.0 → 1.0.0-rc.3
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/CHANGELOG.md +56 -0
- package/LICENSE +1 -1
- package/README.md +84 -0
- package/dist/cjs/BrowserOtel.d.ts +37 -0
- package/dist/cjs/BrowserOtel.d.ts.map +1 -0
- package/dist/cjs/BrowserOtel.js +47 -0
- package/dist/cjs/BrowserOtel.js.map +7 -0
- package/dist/cjs/Endpoint.d.ts +70 -0
- package/dist/cjs/Endpoint.d.ts.map +1 -0
- package/dist/cjs/Endpoint.js +85 -0
- package/dist/cjs/Endpoint.js.map +7 -0
- package/dist/cjs/JournalLogger.d.ts +232 -0
- package/dist/cjs/JournalLogger.d.ts.map +1 -0
- package/dist/cjs/JournalLogger.js +388 -0
- package/dist/cjs/JournalLogger.js.map +7 -0
- package/dist/cjs/Logger.d.ts +55 -0
- package/dist/cjs/Logger.d.ts.map +1 -0
- package/dist/cjs/Logger.js +72 -0
- package/dist/cjs/Logger.js.map +7 -0
- package/dist/cjs/Metric.d.ts +67 -0
- package/dist/cjs/Metric.d.ts.map +1 -0
- package/dist/cjs/Metric.js +68 -0
- package/dist/cjs/Metric.js.map +7 -0
- package/dist/cjs/NodeOtel.d.ts +42 -0
- package/dist/cjs/NodeOtel.d.ts.map +1 -0
- package/dist/cjs/NodeOtel.js +78 -0
- package/dist/cjs/NodeOtel.js.map +7 -0
- package/dist/cjs/Otel.d.ts +62 -0
- package/dist/cjs/Otel.d.ts.map +1 -0
- package/dist/cjs/Otel.js +75 -0
- package/dist/cjs/Otel.js.map +7 -0
- package/dist/cjs/Otlp.d.ts +200 -0
- package/dist/cjs/Otlp.d.ts.map +1 -0
- package/dist/cjs/Otlp.js +235 -0
- package/dist/cjs/Otlp.js.map +7 -0
- package/dist/cjs/Resource.d.ts +162 -0
- package/dist/cjs/Resource.d.ts.map +1 -0
- package/dist/cjs/Resource.js +186 -0
- package/dist/cjs/Resource.js.map +7 -0
- package/dist/cjs/index.d.ts +61 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/schemaIssuePath.d.ts +31 -0
- package/dist/cjs/internal/schemaIssuePath.d.ts.map +1 -0
- package/dist/cjs/internal/schemaIssuePath.js +49 -0
- package/dist/cjs/internal/schemaIssuePath.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/BrowserOtel.d.ts +37 -0
- package/dist/esm/BrowserOtel.d.ts.map +1 -0
- package/dist/esm/BrowserOtel.js +24 -0
- package/dist/esm/BrowserOtel.js.map +1 -0
- package/dist/esm/Endpoint.d.ts +70 -0
- package/dist/esm/Endpoint.d.ts.map +1 -0
- package/dist/esm/Endpoint.js +110 -0
- package/dist/esm/Endpoint.js.map +1 -0
- package/dist/esm/JournalLogger.d.ts +232 -0
- package/dist/esm/JournalLogger.d.ts.map +1 -0
- package/dist/esm/JournalLogger.js +482 -0
- package/dist/esm/JournalLogger.js.map +1 -0
- package/dist/esm/Logger.d.ts +55 -0
- package/dist/esm/Logger.d.ts.map +1 -0
- package/dist/esm/Logger.js +60 -0
- package/dist/esm/Logger.js.map +1 -0
- package/dist/esm/Metric.d.ts +67 -0
- package/dist/esm/Metric.d.ts.map +1 -0
- package/dist/esm/Metric.js +80 -0
- package/dist/esm/Metric.js.map +1 -0
- package/dist/esm/NodeOtel.d.ts +42 -0
- package/dist/esm/NodeOtel.d.ts.map +1 -0
- package/dist/esm/NodeOtel.js +56 -0
- package/dist/esm/NodeOtel.js.map +1 -0
- package/dist/esm/Otel.d.ts +62 -0
- package/dist/esm/Otel.d.ts.map +1 -0
- package/dist/esm/Otel.js +51 -0
- package/dist/esm/Otel.js.map +1 -0
- package/dist/esm/Otlp.d.ts +200 -0
- package/dist/esm/Otlp.d.ts.map +1 -0
- package/dist/esm/Otlp.js +350 -0
- package/dist/esm/Otlp.js.map +1 -0
- package/dist/esm/Resource.d.ts +162 -0
- package/dist/esm/Resource.d.ts.map +1 -0
- package/dist/esm/Resource.js +237 -0
- package/dist/esm/Resource.js.map +1 -0
- package/dist/esm/index.d.ts +61 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +61 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/schemaIssuePath.d.ts +31 -0
- package/dist/esm/internal/schemaIssuePath.d.ts.map +1 -0
- package/dist/esm/internal/schemaIssuePath.js +59 -0
- package/dist/esm/internal/schemaIssuePath.js.map +1 -0
- package/docs/README.md +162 -0
- package/docs/api.md +768 -0
- package/docs/concepts/instrumentation-and-export.md +68 -0
- package/docs/concepts/layer-map.md +72 -0
- package/docs/concepts/validated-acquisition.md +105 -0
- package/docs/guides/export-to-a-collector.md +167 -0
- package/docs/guides/forward-logs-to-the-journal.md +226 -0
- package/docs/guides/install-a-logger.md +111 -0
- package/docs/guides/read-runtime-metrics.md +83 -0
- package/docs/guides/testing.md +134 -0
- package/docs/guides/wire-an-opentelemetry-sdk.md +220 -0
- package/docs/installation.md +98 -0
- package/docs/quickstart.md +145 -0
- package/docs/troubleshooting.md +168 -0
- package/package.json +221 -32
- package/src/BrowserOtel.ts +51 -0
- package/src/Endpoint.ts +131 -0
- package/src/JournalLogger.ts +596 -0
- package/src/Logger.ts +106 -0
- package/src/Metric.ts +88 -0
- package/src/NodeOtel.ts +90 -0
- package/src/Otel.ts +117 -0
- package/src/Otlp.ts +477 -0
- package/src/Resource.ts +324 -0
- package/src/index.ts +67 -0
- package/src/internal/schemaIssuePath.ts +65 -0
- package/docker-compose.otel.yml +0 -104
- package/grafana/dashboards/smithers-dashboard.json +0 -453
- package/grafana/provisioning/dashboards/dashboards.yml +0 -12
- package/grafana/provisioning/datasources/datasources.yml +0 -49
- package/loki/loki-config.yaml +0 -35
- package/otel-collector-config.yml +0 -38
- package/prometheus/prometheus.yml +0 -8
- package/src/MetricName.ts +0 -1
- package/src/MetricsServiceLive.js +0 -9
- package/src/README.md +0 -28
- package/src/ResolvedSmithersObservabilityOptions.ts +0 -12
- package/src/SmithersEvent.ts +0 -798
- package/src/SmithersLogFormat.ts +0 -1
- package/src/SmithersMetricDefinition.ts +0 -15
- package/src/SmithersMetricType.ts +0 -1
- package/src/SmithersMetricUnit.ts +0 -1
- package/src/SmithersObservability.js +0 -15
- package/src/SmithersObservabilityOptions.ts +0 -12
- package/src/SmithersObservabilityService.ts +0 -13
- package/src/_coreCorrelation/CorrelationContext.ts +0 -10
- package/src/_coreCorrelation/CorrelationContextLive.js +0 -11
- package/src/_coreCorrelation/CorrelationContextService.js +0 -15
- package/src/_coreCorrelation/CorrelationContextServiceShape.ts +0 -12
- package/src/_coreCorrelation/CorrelationPatch.ts +0 -3
- package/src/_coreCorrelation/README.md +0 -20
- package/src/_coreCorrelation/_correlationStorage.js +0 -4
- package/src/_coreCorrelation/correlationContextFiberRef.js +0 -5
- package/src/_coreCorrelation/correlationContextToLogAnnotations.js +0 -18
- package/src/_coreCorrelation/getCurrentCorrelationContext.js +0 -9
- package/src/_coreCorrelation/getCurrentCorrelationContextEffect.js +0 -11
- package/src/_coreCorrelation/index.js +0 -14
- package/src/_coreCorrelation/mergeCorrelationContext.js +0 -51
- package/src/_coreCorrelation/runWithCorrelationContext.js +0 -14
- package/src/_coreCorrelation/updateCurrentCorrelationContext.js +0 -17
- package/src/_coreCorrelation/withCorrelationContext.js +0 -38
- package/src/_coreCorrelation/withCurrentCorrelationContext.js +0 -11
- package/src/_coreMetrics.js +0 -14
- package/src/_coreMetricsShape.ts +0 -44
- package/src/_corePrometheus.js +0 -91
- package/src/_corePrometheusShape.ts +0 -11
- package/src/_coreTracing.js +0 -132
- package/src/_coreTracingShape.ts +0 -17
- package/src/_otelLogBuilders.js +0 -102
- package/src/_sessionFileResolvers.js +0 -164
- package/src/_smithersSpanAttributeAliases.js +0 -19
- package/src/_smithersTraceSpanStorage.js +0 -3
- package/src/_traceEventNormalizers.js +0 -499
- package/src/_traceRedaction.js +0 -162
- package/src/agentSessionEventToOtelLogRecord.js +0 -55
- package/src/agentTrace.ts +0 -144
- package/src/agentTraceCapabilities.js +0 -151
- package/src/annotateSmithersTrace.js +0 -11
- package/src/canonicalTraceEventToOtelLogRecord.js +0 -55
- package/src/correlation.js +0 -56
- package/src/createSmithersObservabilityLayer.js +0 -59
- package/src/createSmithersOtelLayer.js +0 -23
- package/src/createSmithersRuntimeLayer.js +0 -2
- package/src/detectAgentFamily.js +0 -26
- package/src/detectCaptureMode.js +0 -29
- package/src/emitOtelLogRecord.js +0 -19
- package/src/getCurrentSmithersTraceAnnotations.js +0 -14
- package/src/getCurrentSmithersTraceSpan.js +0 -7
- package/src/index.d.ts +0 -1343
- package/src/index.js +0 -136
- package/src/kindPhase.js +0 -17
- package/src/logging.js +0 -248
- package/src/makeSmithersSpanAttributes.js +0 -20
- package/src/metrics/README.md +0 -22
- package/src/metrics/SmithersMetricDefinition.ts +0 -17
- package/src/metrics/SmithersMetricType.ts +0 -1
- package/src/metrics/SmithersMetricUnit.ts +0 -1
- package/src/metrics/_asyncExternalWaitCounts.js +0 -4
- package/src/metrics/_buckets.js +0 -37
- package/src/metrics/_incrementGauge.js +0 -11
- package/src/metrics/_processStartMs.js +0 -1
- package/src/metrics/activeNodes.js +0 -2
- package/src/metrics/activeRuns.js +0 -2
- package/src/metrics/agentActionsTotal.js +0 -2
- package/src/metrics/agentDurationMs.js +0 -3
- package/src/metrics/agentErrorsTotal.js +0 -2
- package/src/metrics/agentEventsTotal.js +0 -2
- package/src/metrics/agentInvocationsTotal.js +0 -2
- package/src/metrics/agentRetriesTotal.js +0 -2
- package/src/metrics/agentSessionsTotal.js +0 -2
- package/src/metrics/agentTokensTotal.js +0 -2
- package/src/metrics/alertDeliveriesAttempted.js +0 -2
- package/src/metrics/alertDeliveriesSuppressed.js +0 -2
- package/src/metrics/alertsAcknowledgedTotal.js +0 -2
- package/src/metrics/alertsActive.js +0 -2
- package/src/metrics/alertsEscalatedTotal.js +0 -2
- package/src/metrics/alertsFiredTotal.js +0 -2
- package/src/metrics/alertsReopenedTotal.js +0 -2
- package/src/metrics/alertsResolvedTotal.js +0 -2
- package/src/metrics/alertsSilencedTotal.js +0 -2
- package/src/metrics/approvalPending.js +0 -2
- package/src/metrics/approvalWaitDuration.js +0 -5
- package/src/metrics/approvalsDenied.js +0 -2
- package/src/metrics/approvalsGranted.js +0 -2
- package/src/metrics/approvalsRequested.js +0 -2
- package/src/metrics/attemptDuration.js +0 -3
- package/src/metrics/attentionBacklog.js +0 -2
- package/src/metrics/cacheHits.js +0 -2
- package/src/metrics/cacheMisses.js +0 -2
- package/src/metrics/dbQueryDuration.js +0 -3
- package/src/metrics/dbRetries.js +0 -2
- package/src/metrics/dbTransactionDuration.js +0 -3
- package/src/metrics/dbTransactionRetries.js +0 -2
- package/src/metrics/dbTransactionRollbacks.js +0 -2
- package/src/metrics/devtoolsActiveSubscribers.js +0 -2
- package/src/metrics/devtoolsBackpressureDisconnectTotal.js +0 -2
- package/src/metrics/devtoolsDeltaBuildMs.js +0 -3
- package/src/metrics/devtoolsEventBytes.js +0 -3
- package/src/metrics/devtoolsEventTotal.js +0 -2
- package/src/metrics/devtoolsSnapshotBuildMs.js +0 -5
- package/src/metrics/devtoolsSubscribeTotal.js +0 -2
- package/src/metrics/errorsTotal.js +0 -2
- package/src/metrics/eventsEmittedTotal.js +0 -2
- package/src/metrics/externalWaitAsyncPending.js +0 -2
- package/src/metrics/gatewayApprovalDecisionsTotal.js +0 -2
- package/src/metrics/gatewayAuthEventsTotal.js +0 -2
- package/src/metrics/gatewayConnectionsActive.js +0 -2
- package/src/metrics/gatewayConnectionsClosedTotal.js +0 -2
- package/src/metrics/gatewayConnectionsTotal.js +0 -2
- package/src/metrics/gatewayCronTriggersTotal.js +0 -2
- package/src/metrics/gatewayErrorsTotal.js +0 -2
- package/src/metrics/gatewayHeartbeatTicksTotal.js +0 -2
- package/src/metrics/gatewayMessagesReceivedTotal.js +0 -2
- package/src/metrics/gatewayMessagesSentTotal.js +0 -2
- package/src/metrics/gatewayRpcCallsTotal.js +0 -2
- package/src/metrics/gatewayRpcDuration.js +0 -3
- package/src/metrics/gatewayRunEventBackpressureDisconnectTotal.js +0 -4
- package/src/metrics/gatewayRunsCompletedTotal.js +0 -2
- package/src/metrics/gatewayRunsStartedTotal.js +0 -2
- package/src/metrics/gatewaySignalsTotal.js +0 -2
- package/src/metrics/gatewayWebhooksReceivedTotal.js +0 -2
- package/src/metrics/gatewayWebhooksRejectedTotal.js +0 -2
- package/src/metrics/gatewayWebhooksVerifiedTotal.js +0 -2
- package/src/metrics/heartbeatDataSizeBytes.js +0 -5
- package/src/metrics/heartbeatIntervalMs.js +0 -3
- package/src/metrics/hotReloadDuration.js +0 -3
- package/src/metrics/hotReloadFailures.js +0 -2
- package/src/metrics/hotReloads.js +0 -2
- package/src/metrics/httpRequestDuration.js +0 -3
- package/src/metrics/httpRequests.js +0 -2
- package/src/metrics/index.d.ts +0 -1185
- package/src/metrics/index.js +0 -168
- package/src/metrics/memoryFactReads.js +0 -3
- package/src/metrics/memoryFactWrites.js +0 -3
- package/src/metrics/memoryMessageSaves.js +0 -3
- package/src/metrics/memoryRecallDuration.js +0 -11
- package/src/metrics/memoryRecallQueries.js +0 -3
- package/src/metrics/metricsServiceAdapter.js +0 -181
- package/src/metrics/nodeDuration.js +0 -3
- package/src/metrics/nodeRetriesTotal.js +0 -2
- package/src/metrics/nodesFailed.js +0 -2
- package/src/metrics/nodesFinished.js +0 -2
- package/src/metrics/nodesStarted.js +0 -2
- package/src/metrics/openApiToolCallErrorsTotal.js +0 -3
- package/src/metrics/openApiToolCallsTotal.js +0 -3
- package/src/metrics/openApiToolDuration.js +0 -9
- package/src/metrics/processHeapUsedBytes.js +0 -2
- package/src/metrics/processMemoryRssBytes.js +0 -2
- package/src/metrics/processUptimeSeconds.js +0 -2
- package/src/metrics/promptSizeBytes.js +0 -3
- package/src/metrics/replaysStarted.js +0 -3
- package/src/metrics/responseSizeBytes.js +0 -3
- package/src/metrics/rewindDurationMs.js +0 -3
- package/src/metrics/rewindFramesDeleted.js +0 -3
- package/src/metrics/rewindRollbackTotal.js +0 -2
- package/src/metrics/rewindSandboxesReverted.js +0 -3
- package/src/metrics/rewindTotal.js +0 -2
- package/src/metrics/runDuration.js +0 -3
- package/src/metrics/runForksCreated.js +0 -3
- package/src/metrics/runsAncestryDepth.js +0 -3
- package/src/metrics/runsCancelledTotal.js +0 -2
- package/src/metrics/runsCarriedStateBytes.js +0 -5
- package/src/metrics/runsContinuedTotal.js +0 -2
- package/src/metrics/runsFailedTotal.js +0 -2
- package/src/metrics/runsFinishedTotal.js +0 -2
- package/src/metrics/runsResumedTotal.js +0 -2
- package/src/metrics/runsTotal.js +0 -2
- package/src/metrics/sandboxActive.js +0 -2
- package/src/metrics/sandboxBundleSizeBytes.js +0 -5
- package/src/metrics/sandboxCompletedTotal.js +0 -2
- package/src/metrics/sandboxCreatedTotal.js +0 -2
- package/src/metrics/sandboxDurationMs.js +0 -3
- package/src/metrics/sandboxPatchCount.js +0 -3
- package/src/metrics/sandboxTransportDurationMs.js +0 -5
- package/src/metrics/schedulerConcurrencyUtilization.js +0 -2
- package/src/metrics/schedulerQueueDepth.js +0 -2
- package/src/metrics/schedulerWaitDuration.js +0 -5
- package/src/metrics/scorerDuration.js +0 -9
- package/src/metrics/scorerEventsFailed.js +0 -2
- package/src/metrics/scorerEventsFinished.js +0 -2
- package/src/metrics/scorerEventsStarted.js +0 -2
- package/src/metrics/scorersFailed.js +0 -3
- package/src/metrics/scorersFinished.js +0 -3
- package/src/metrics/scorersStarted.js +0 -3
- package/src/metrics/smithersMetricCatalog.js +0 -893
- package/src/metrics/smithersMetricCatalogByKey.js +0 -2
- package/src/metrics/smithersMetricCatalogByName.js +0 -2
- package/src/metrics/smithersMetricCatalogByPrometheusName.js +0 -4
- package/src/metrics/snapshotDuration.js +0 -9
- package/src/metrics/snapshotsCaptured.js +0 -3
- package/src/metrics/supervisorPollDuration.js +0 -5
- package/src/metrics/supervisorPollsTotal.js +0 -2
- package/src/metrics/supervisorResumeLag.js +0 -5
- package/src/metrics/supervisorResumedTotal.js +0 -2
- package/src/metrics/supervisorSkippedTotal.js +0 -2
- package/src/metrics/supervisorStaleDetected.js +0 -2
- package/src/metrics/taskHeartbeatTimeoutTotal.js +0 -2
- package/src/metrics/taskHeartbeatsTotal.js +0 -2
- package/src/metrics/timerDelayDuration.js +0 -3
- package/src/metrics/timersCancelled.js +0 -2
- package/src/metrics/timersCreated.js +0 -2
- package/src/metrics/timersFired.js +0 -2
- package/src/metrics/timersPending.js +0 -2
- package/src/metrics/toPrometheusMetricName.js +0 -8
- package/src/metrics/tokensCacheReadTotal.js +0 -2
- package/src/metrics/tokensCacheWriteTotal.js +0 -2
- package/src/metrics/tokensContextWindowBucketTotal.js +0 -2
- package/src/metrics/tokensContextWindowPerCall.js +0 -5
- package/src/metrics/tokensInputPerCall.js +0 -3
- package/src/metrics/tokensInputTotal.js +0 -2
- package/src/metrics/tokensOutputPerCall.js +0 -3
- package/src/metrics/tokensOutputTotal.js +0 -2
- package/src/metrics/tokensReasoningTotal.js +0 -2
- package/src/metrics/toolCallErrorsTotal.js +0 -2
- package/src/metrics/toolCallsTotal.js +0 -2
- package/src/metrics/toolDuration.js +0 -3
- package/src/metrics/toolOutputTruncatedTotal.js +0 -2
- package/src/metrics/trackEvent.js +0 -608
- package/src/metrics/updateAsyncExternalWaitPending.js +0 -18
- package/src/metrics/updateProcessMetrics.js +0 -20
- package/src/metrics/vcsDuration.js +0 -3
- package/src/normalizeStructuredEvent.js +0 -15
- package/src/prometheusContentType.js +0 -1
- package/src/renderPrometheusMetrics.js +0 -212
- package/src/resolveAgentTraceCapabilities.js +0 -59
- package/src/resolveSmithersObservabilityOptions.js +0 -109
- package/src/smithersMetrics.js +0 -2
- package/src/smithersSpanNames.js +0 -6
- package/src/unsupportedKindsForCapabilities.js +0 -32
- package/src/withSmithersSpan.js +0 -17
- package/tempo/tempo.yml +0 -17
|
@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;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Otlp_exports = {};
|
|
30
|
+
__export(Otlp_exports, {
|
|
31
|
+
defaultServiceName: () => defaultServiceName,
|
|
32
|
+
defaultServiceVersion: () => defaultServiceVersion,
|
|
33
|
+
layer: () => layer,
|
|
34
|
+
layerEnvironment: () => layerEnvironment,
|
|
35
|
+
layerFetch: () => layerFetch,
|
|
36
|
+
layerNoop: () => layerNoop,
|
|
37
|
+
maxRequestBytes: () => maxRequestBytes,
|
|
38
|
+
maximumEnvelopeBytes: () => maximumEnvelopeBytes,
|
|
39
|
+
parseHeaders: () => parseHeaders,
|
|
40
|
+
reservedBatchBytes: () => reservedBatchBytes
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(Otlp_exports);
|
|
43
|
+
var Redaction = __toESM(require("@smthrs/journal/Redaction"), 1);
|
|
44
|
+
var Cause = __toESM(require("effect/Cause"), 1);
|
|
45
|
+
var import_Clock = require("effect/Clock");
|
|
46
|
+
var ConfigProvider = __toESM(require("effect/ConfigProvider"), 1);
|
|
47
|
+
var Effect = __toESM(require("effect/Effect"), 1);
|
|
48
|
+
var Exit = __toESM(require("effect/Exit"), 1);
|
|
49
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
50
|
+
var Logger = __toESM(require("effect/Logger"), 1);
|
|
51
|
+
var Metric = __toESM(require("effect/Metric"), 1);
|
|
52
|
+
var Option = __toESM(require("effect/Option"), 1);
|
|
53
|
+
var References = __toESM(require("effect/References"), 1);
|
|
54
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
55
|
+
var Semaphore = __toESM(require("effect/Semaphore"), 1);
|
|
56
|
+
var Tracer = __toESM(require("effect/Tracer"), 1);
|
|
57
|
+
var FetchHttpClient = __toESM(require("effect/unstable/http/FetchHttpClient"), 1);
|
|
58
|
+
var Headers = __toESM(require("effect/unstable/http/Headers"), 1);
|
|
59
|
+
var HttpClient = __toESM(require("effect/unstable/http/HttpClient"), 1);
|
|
60
|
+
var HttpClientResponse = __toESM(require("effect/unstable/http/HttpClientResponse"), 1);
|
|
61
|
+
var Otlp = __toESM(require("effect/unstable/observability/Otlp"), 1);
|
|
62
|
+
var Endpoint = __toESM(require("./Endpoint.js"), 1);
|
|
63
|
+
var Resource = __toESM(require("./Resource.js"), 1);
|
|
64
|
+
const defaultServiceName = "flows";
|
|
65
|
+
const defaultServiceVersion = "1.0.0-rc.3";
|
|
66
|
+
const maxBatchSize = 1e3;
|
|
67
|
+
const maxInFlight = 4;
|
|
68
|
+
const maxRequestBytes = 1024 * 1024;
|
|
69
|
+
const requestTimeout = "10 seconds";
|
|
70
|
+
const diagnosticIntervalMillis = 6e4;
|
|
71
|
+
const maximumEnvelopeBytes = 8 * 1024;
|
|
72
|
+
const reservedBatchBytes = maxRequestBytes - Resource.maximumResourceBytes - maximumEnvelopeBytes;
|
|
73
|
+
const boundedClient = Layer.effect(
|
|
74
|
+
HttpClient.HttpClient,
|
|
75
|
+
Effect.gen(function* () {
|
|
76
|
+
const client = yield* HttpClient.HttpClient;
|
|
77
|
+
const clock = yield* import_Clock.Clock;
|
|
78
|
+
const ambientLoggers = yield* Effect.withFiber((fiber) => Effect.succeed(fiber.getRef(Logger.CurrentLoggers)));
|
|
79
|
+
const permits = Semaphore.makeUnsafe(maxInFlight);
|
|
80
|
+
const droppedExports = Metric.counter("flows_observability_otlp_dropped");
|
|
81
|
+
let nextDiagnosticAt = -Infinity;
|
|
82
|
+
const discard = (reason, request, bytes) => Metric.update(droppedExports, 1).pipe(
|
|
83
|
+
Effect.andThen(Effect.suspend(() => {
|
|
84
|
+
const now = clock.currentTimeMillisUnsafe();
|
|
85
|
+
if (now < nextDiagnosticAt) return Effect.void;
|
|
86
|
+
nextDiagnosticAt = now + diagnosticIntervalMillis;
|
|
87
|
+
return Metric.value(droppedExports).pipe(
|
|
88
|
+
Effect.flatMap(
|
|
89
|
+
(dropped) => Effect.logWarning("An OTLP export batch was discarded").pipe(
|
|
90
|
+
Effect.provideService(References.CurrentLogSpans, []),
|
|
91
|
+
Effect.provideService(References.CurrentLogAnnotations, {
|
|
92
|
+
code: "otlp_export_discarded",
|
|
93
|
+
reason,
|
|
94
|
+
bytes,
|
|
95
|
+
limit: maxRequestBytes,
|
|
96
|
+
dropped: dropped.count
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
),
|
|
100
|
+
Effect.provideService(Logger.CurrentLoggers, ambientLoggers)
|
|
101
|
+
);
|
|
102
|
+
})),
|
|
103
|
+
Effect.as(HttpClientResponse.fromWeb(request, new Response(null, { status: 204 })))
|
|
104
|
+
);
|
|
105
|
+
return HttpClient.transform(client, (requestEffect, request) => Effect.suspend(() => {
|
|
106
|
+
const bytes = request.body.contentLength;
|
|
107
|
+
if (bytes > maxRequestBytes) return discard("oversized", request, bytes);
|
|
108
|
+
const confinedRequest = Effect.flatMap(Effect.serviceOption(FetchHttpClient.RequestInit), (init) => requestEffect.pipe(
|
|
109
|
+
Effect.provideService(FetchHttpClient.RequestInit, {
|
|
110
|
+
...Option.getOrUndefined(init),
|
|
111
|
+
redirect: "manual"
|
|
112
|
+
})
|
|
113
|
+
));
|
|
114
|
+
return confinedRequest.pipe(
|
|
115
|
+
Effect.timeoutOrElse({
|
|
116
|
+
duration: requestTimeout,
|
|
117
|
+
orElse: () => discard("stalled", request, bytes)
|
|
118
|
+
}),
|
|
119
|
+
permits.withPermitsIfAvailable(1),
|
|
120
|
+
Effect.flatMap(Option.match({
|
|
121
|
+
onNone: () => discard("saturated", request, bytes),
|
|
122
|
+
onSome: Effect.succeed
|
|
123
|
+
}))
|
|
124
|
+
);
|
|
125
|
+
}));
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
const loopbackIpv4 = /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
|
|
129
|
+
const isLoopback = (endpoint) => {
|
|
130
|
+
const hostname = new URL(endpoint).hostname;
|
|
131
|
+
return hostname === "localhost" || hostname === "[::1]" || loopbackIpv4.test(hostname);
|
|
132
|
+
};
|
|
133
|
+
const vendorCredentialHeaders = /* @__PURE__ */ new Set(["x-honeycomb-team"]);
|
|
134
|
+
const isCredentialHeader = (name) => Redaction.isSensitiveKey(name) || vendorCredentialHeaders.has(name.toLowerCase());
|
|
135
|
+
const refusePlaintextCredentials = (baseUrl, headers) => {
|
|
136
|
+
if (!baseUrl.toLowerCase().startsWith("http:") || isLoopback(baseUrl)) return Effect.void;
|
|
137
|
+
const credential = Object.keys(Headers.fromInput(headers)).some(isCredentialHeader);
|
|
138
|
+
return credential ? Effect.fail(
|
|
139
|
+
new Endpoint.InvalidExporterEndpoint({
|
|
140
|
+
code: "invalid_exporter_endpoint",
|
|
141
|
+
path: "baseUrl",
|
|
142
|
+
message: "OTLP collector baseUrl must use https:// when headers carry credentials, unless it is a loopback address"
|
|
143
|
+
})
|
|
144
|
+
) : Effect.void;
|
|
145
|
+
};
|
|
146
|
+
const redactText = (text) => String(Redaction.redact(text));
|
|
147
|
+
class RedactedSpanError extends Schema.TaggedError()("@smthrs/observability/RedactedSpanError", {
|
|
148
|
+
message: Schema.String
|
|
149
|
+
}) {
|
|
150
|
+
}
|
|
151
|
+
const redactedExit = (exit) => {
|
|
152
|
+
if (exit._tag === "Success" || Cause.hasInterruptsOnly(exit.cause)) return exit;
|
|
153
|
+
const errors = Cause.prettyErrors(exit.cause, { includeCauseInStack: true }).map((error) => {
|
|
154
|
+
const redacted = new RedactedSpanError({ message: redactText(error.message) });
|
|
155
|
+
Object.defineProperty(redacted, "name", { value: redactText(error.name), configurable: true, writable: true });
|
|
156
|
+
redacted.stack = redactText(String(error.stack));
|
|
157
|
+
return redacted;
|
|
158
|
+
});
|
|
159
|
+
return Exit.failCause(errors.map(Cause.fail).reduce(Cause.combine, Cause.empty));
|
|
160
|
+
};
|
|
161
|
+
const redactedSpans = Layer.effect(Tracer.Tracer)(
|
|
162
|
+
Effect.map(Effect.tracer, (tracer) => Tracer.make({
|
|
163
|
+
...tracer,
|
|
164
|
+
span(options) {
|
|
165
|
+
const span = tracer.span(options);
|
|
166
|
+
const end = span.end.bind(span);
|
|
167
|
+
const attribute = span.attribute.bind(span);
|
|
168
|
+
span.end = (endTime, exit) => end(endTime, redactedExit(exit));
|
|
169
|
+
span.attribute = (key, value) => attribute(key, typeof value === "string" ? redactText(value) : value);
|
|
170
|
+
return span;
|
|
171
|
+
}
|
|
172
|
+
}))
|
|
173
|
+
);
|
|
174
|
+
const layer = (options) => Layer.unwrap(
|
|
175
|
+
Effect.map(
|
|
176
|
+
Effect.all([
|
|
177
|
+
Resource.decode({
|
|
178
|
+
serviceName: options.serviceName ?? defaultServiceName,
|
|
179
|
+
serviceVersion: options.serviceVersion ?? defaultServiceVersion,
|
|
180
|
+
...options.attributes === void 0 ? {} : { attributes: options.attributes }
|
|
181
|
+
}),
|
|
182
|
+
Endpoint.decode(options.baseUrl, "baseUrl").pipe(
|
|
183
|
+
Effect.tap((baseUrl) => refusePlaintextCredentials(baseUrl, options.headers))
|
|
184
|
+
)
|
|
185
|
+
]),
|
|
186
|
+
([decoded, baseUrl]) => {
|
|
187
|
+
const resource = Resource.toOpenTelemetryConfiguration(decoded);
|
|
188
|
+
return Otlp.layerJson({
|
|
189
|
+
baseUrl,
|
|
190
|
+
resource: {
|
|
191
|
+
serviceName: resource.serviceName,
|
|
192
|
+
// `serviceVersion` is supplied above before Resource decoding.
|
|
193
|
+
serviceVersion: resource.serviceVersion,
|
|
194
|
+
...resource.attributes === void 0 ? {} : { attributes: resource.attributes }
|
|
195
|
+
},
|
|
196
|
+
headers: options.headers,
|
|
197
|
+
maxBatchSize,
|
|
198
|
+
loggerExportInterval: options.exportInterval,
|
|
199
|
+
metricsExportInterval: options.exportInterval,
|
|
200
|
+
tracerExportInterval: options.exportInterval,
|
|
201
|
+
shutdownTimeout: options.shutdownTimeout
|
|
202
|
+
}).pipe(
|
|
203
|
+
Layer.provide(boundedClient),
|
|
204
|
+
// Upstream merges OTEL_RESOURCE_ATTRIBUTES even with explicit
|
|
205
|
+
// options. Keep unvalidated ambient metadata out of every request.
|
|
206
|
+
Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))),
|
|
207
|
+
(exporter) => Layer.provideMerge(redactedSpans, exporter)
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
const layerFetch = (options) => layer(options).pipe(Layer.provide(FetchHttpClient.layer));
|
|
213
|
+
const parseHeaders = (value) => {
|
|
214
|
+
const headers = {};
|
|
215
|
+
for (const pair of (value ?? "").split(",")) {
|
|
216
|
+
const separator = pair.indexOf("=");
|
|
217
|
+
const key = pair.slice(0, separator).trim();
|
|
218
|
+
if (separator < 0 || key === "") continue;
|
|
219
|
+
const raw = pair.slice(separator + 1).trim();
|
|
220
|
+
let decoded = raw;
|
|
221
|
+
try {
|
|
222
|
+
decoded = decodeURIComponent(raw);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
headers[key] = decoded;
|
|
226
|
+
}
|
|
227
|
+
return headers;
|
|
228
|
+
};
|
|
229
|
+
const layerEnvironment = (environment, options = {}) => {
|
|
230
|
+
const endpoint = environment["OTEL_EXPORTER_OTLP_ENDPOINT"]?.trim();
|
|
231
|
+
if (endpoint === void 0 || endpoint === "") return layerNoop;
|
|
232
|
+
return layerFetch({ ...options, baseUrl: endpoint, headers: parseHeaders(environment["OTEL_EXPORTER_OTLP_HEADERS"]) });
|
|
233
|
+
};
|
|
234
|
+
const layerNoop = Layer.empty;
|
|
235
|
+
//# sourceMappingURL=Otlp.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Otlp.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Default OTLP export wiring for flows telemetry.\n *\n * The store packages already open spans through Effect's tracer and update\n * `Metric` counters on their hot paths; what they deliberately do not do is\n * ship an exporter. This module is that exporter: one layer that installs\n * Effect's own OTLP logger, metrics exporter, and tracer\n * (`effect/unstable/observability/Otlp`) against a collector endpoint, with\n * the flows service identity filled in. Nothing beyond `effect` is involved;\n * no OpenTelemetry SDK dependency.\n *\n * Browser support is met by construction rather than by a no-op variant:\n * export happens over Effect's `HttpClient`, and {@link layerFetch} binds the\n * `fetch` implementation the host already has, so no entry point here ever\n * resolves a `node:` built-in. See the\n * {@link https://smithers.sh/docs/reference/api/observability | observability API contract}.\n *\n * @since 0.1.0\n */\n\nimport * as Redaction from \"@smthrs/journal/Redaction\"\nimport * as Cause from \"effect/Cause\"\nimport { Clock } from \"effect/Clock\"\nimport * as ConfigProvider from \"effect/ConfigProvider\"\nimport type * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Layer from \"effect/Layer\"\nimport * as Logger from \"effect/Logger\"\nimport * as Metric from \"effect/Metric\"\nimport * as Option from \"effect/Option\"\nimport * as References from \"effect/References\"\nimport * as Schema from \"effect/Schema\"\nimport * as Semaphore from \"effect/Semaphore\"\nimport * as Tracer from \"effect/Tracer\"\nimport * as FetchHttpClient from \"effect/unstable/http/FetchHttpClient\"\nimport * as Headers from \"effect/unstable/http/Headers\"\nimport type * as HttpBody from \"effect/unstable/http/HttpBody\"\nimport * as HttpClient from \"effect/unstable/http/HttpClient\"\nimport type * as HttpClientRequest from \"effect/unstable/http/HttpClientRequest\"\nimport * as HttpClientResponse from \"effect/unstable/http/HttpClientResponse\"\nimport * as Otlp from \"effect/unstable/observability/Otlp\"\nimport * as Endpoint from \"./Endpoint.ts\"\nimport * as Resource from \"./Resource.ts\"\n\n/**\n * The `service.name` resource attribute installed when the caller supplies\n * none: the flows distribution itself. Override it per application with\n * {@link Options.serviceName}.\n *\n * @category resource\n * @since 0.1.0\n */\nexport const defaultServiceName = \"flows\"\n\n/**\n * The `service.version` resource attribute installed when the caller supplies\n * none. Mirrors the release version in this package's `package.json`.\n *\n * A published package cannot read its own manifest on every runtime it\n * supports, so the version lives here as a literal.\n * `scripts/set-release-version.mjs` rewrites this declaration with the\n * manifests, and its `--check` mode reports drift, so a release bump cannot\n * leave it behind.\n *\n * @category resource\n * @since 0.1.0\n */\nexport const defaultServiceVersion = \"1.0.0-rc.3\"\n\n// The upstream logger and tracer each buffer at most one 1,000-record batch.\n// Do not queue at the transport: upstream forks every full batch independently.\nconst maxBatchSize = 1000\nconst maxInFlight = 4\n/**\n * Maximum encoded export request size, in bytes.\n * @category transport\n * @since 1.0.0-rc.0\n */\nexport const maxRequestBytes = 1024 * 1024\nconst requestTimeout = \"10 seconds\"\nconst diagnosticIntervalMillis = 60_000\n// The envelope around the resource in every request repeats `service.name` as\n// the instrumentation scope name: at most 1,024 code units, at most six bytes\n// each once JSON-escaped, so under 8 KiB together with the envelope's own keys.\n/**\n * Reserved bytes for request wrappers and the escaped instrumentation scope.\n * @category transport\n * @since 1.0.0-rc.0\n */\nexport const maximumEnvelopeBytes = 8 * 1024\n\n/**\n * Bytes of every export request kept free for the signal batch itself.\n *\n * The transport discards a request over 1 MiB, and the resource rides in every\n * request, so the largest resource `Resource.decode` admits\n * (`Resource.maximumResourceBytes`, 128 KiB) and the envelope that repeats the\n * service name (under 8 KiB) come off the top. The 888 KiB left gives each\n * record of a full 1,000-record logger or tracer batch about 900 bytes, three\n * to four times a bare log record or span, and gives the metrics snapshot room\n * for several thousand series. Every resource the decoder accepts therefore\n * leaves an ordinary batch of any signal exportable; what this reserve does\n * not bound is a single application record or a registry large enough to\n * exceed it on its own.\n *\n * @category transport\n * @since 1.0.0-rc.0\n */\nexport const reservedBatchBytes = maxRequestBytes - Resource.maximumResourceBytes - maximumEnvelopeBytes\n\ntype DiscardReason = \"oversized\" | \"stalled\" | \"saturated\"\n\nconst boundedClient = Layer.effect(\n HttpClient.HttpClient,\n Effect.gen(function*() {\n const client = yield* HttpClient.HttpClient\n const clock = yield* Clock\n // The loggers installed when this transport is acquired. The OTLP logger\n // the same acquisition installs does not exist yet, so a diagnostic pinned\n // to this set cannot enter the exporter it describes, whichever fiber runs\n // the export: the interval and shutdown fibers inherit this set anyway,\n // but a flush requested from application code runs with the application's\n // loggers, which by then include this exporter.\n const ambientLoggers = yield* Effect.withFiber((fiber) => Effect.succeed(fiber.getRef(Logger.CurrentLoggers)))\n const permits = Semaphore.makeUnsafe(maxInFlight)\n // The counter lives with the transport it describes.\n const droppedExports = Metric.counter(\"flows_observability_otlp_dropped\")\n let nextDiagnosticAt = -Infinity\n // A local discard is terminal, so the upstream retry loop must not retain\n // or retry its payload, and the counter records batches, not records. The\n // warning is the diagnostic the counter cannot be: the counter is exported\n // through this same transport and shares every outage with it. One\n // warning per minute keeps a sustained outage from flooding the ambient\n // loggers; the running total in its annotations carries the volume.\n // Replace ambient annotations and log spans to bound the diagnostic itself.\n const discard = (reason: DiscardReason, request: HttpClientRequest.HttpClientRequest, bytes: number) =>\n Metric.update(droppedExports, 1).pipe(\n Effect.andThen(Effect.suspend(() => {\n const now = clock.currentTimeMillisUnsafe()\n if (now < nextDiagnosticAt) return Effect.void\n nextDiagnosticAt = now + diagnosticIntervalMillis\n return Metric.value(droppedExports).pipe(\n Effect.flatMap((dropped) =>\n Effect.logWarning(\"An OTLP export batch was discarded\").pipe(\n Effect.provideService(References.CurrentLogSpans, []),\n Effect.provideService(References.CurrentLogAnnotations, {\n code: \"otlp_export_discarded\",\n reason,\n bytes,\n limit: maxRequestBytes,\n dropped: dropped.count\n })\n )\n ),\n Effect.provideService(Logger.CurrentLoggers, ambientLoggers)\n )\n })),\n Effect.as(HttpClientResponse.fromWeb(request, new Response(null, { status: 204 })))\n )\n return HttpClient.transform(client, (requestEffect, request) =>\n Effect.suspend(() => {\n // layerJson always supplies a Uint8Array body with a byte length.\n const bytes = (request.body as HttpBody.Uint8Array).contentLength\n if (bytes > maxRequestBytes) return discard(\"oversized\", request, bytes)\n // Fetch must expose redirects before any credential or signal body\n // leaves the configured endpoint, even when the caller enables follow.\n const confinedRequest = Effect.flatMap(Effect.serviceOption(FetchHttpClient.RequestInit), (init) =>\n requestEffect.pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n ...Option.getOrUndefined(init),\n redirect: \"manual\"\n })\n ))\n return confinedRequest.pipe(\n Effect.timeoutOrElse({\n duration: requestTimeout,\n orElse: () =>\n discard(\"stalled\", request, bytes)\n }),\n permits.withPermitsIfAvailable(1),\n Effect.flatMap(Option.match({\n onNone: () =>\n discard(\"saturated\", request, bytes),\n onSome: Effect.succeed\n }))\n )\n }))\n })\n)\n\nconst loopbackIpv4 = /^127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/\n\n/** Whether a decoded endpoint's host never leaves this machine. */\nconst isLoopback = (endpoint: string): boolean => {\n const hostname = new URL(endpoint).hostname\n return hostname === \"localhost\" || hostname === \"[::1]\" || loopbackIpv4.test(hostname)\n}\n\n/**\n * Refuses a credential header bound for a plaintext collector off this\n * machine. Anyone on the network path could read the token from every export\n * request, and the exporter would never report it. Loopback `http://` stays\n * allowed for a local collector or sidecar; non-credential headers such as a\n * tenant id stay allowed on any endpoint.\n */\n/**\n * Vendor credential headers whose names `Redaction.isSensitiveKey` does not\n * recognize. Honeycomb sends its ingest key as `x-honeycomb-team`.\n */\nconst vendorCredentialHeaders: ReadonlySet<string> = new Set([\"x-honeycomb-team\"])\n\nconst isCredentialHeader = (name: string): boolean =>\n Redaction.isSensitiveKey(name) || vendorCredentialHeaders.has(name.toLowerCase())\n\nconst refusePlaintextCredentials = (\n baseUrl: string,\n headers: Headers.Input | undefined\n): Effect.Effect<void, Endpoint.InvalidExporterEndpoint> => {\n if (!baseUrl.toLowerCase().startsWith(\"http:\") || isLoopback(baseUrl)) return Effect.void\n const credential = Object.keys(Headers.fromInput(headers)).some(isCredentialHeader)\n return credential\n ? Effect.fail(\n new Endpoint.InvalidExporterEndpoint({\n code: \"invalid_exporter_endpoint\",\n path: \"baseUrl\",\n message:\n \"OTLP collector baseUrl must use https:// when headers carry credentials, unless it is a loopback address\"\n })\n )\n : Effect.void\n}\n\nconst redactText = (text: string): string => String(Redaction.redact(text))\n\n/**\n * A failed span's error rebuilt with its text redacted. It keeps the original\n * error's `name` and `stack` (redacted) so the collector's exception type and\n * trace stay readable; it is exported to the collector and never thrown.\n */\nclass RedactedSpanError extends Schema.TaggedError<RedactedSpanError>()(\"@smthrs/observability/RedactedSpanError\", {\n message: Schema.String\n}) {}\n\n/**\n * A span failure rendered with credentials removed. The exporter serializes a\n * failed span's cause into its status message and `exception` events, which\n * would otherwise carry any token an error message quoted to the collector.\n */\nconst redactedExit = (exit: Exit.Exit<unknown, unknown>): Exit.Exit<unknown, unknown> => {\n if (exit._tag === \"Success\" || Cause.hasInterruptsOnly(exit.cause)) return exit\n const errors = Cause.prettyErrors(exit.cause, { includeCauseInStack: true }).map((error) => {\n const redacted = new RedactedSpanError({ message: redactText(error.message) })\n Object.defineProperty(redacted, \"name\", { value: redactText(error.name), configurable: true, writable: true })\n // `prettyErrors` always renders a stack.\n redacted.stack = redactText(String(error.stack))\n return redacted\n })\n return Exit.failCause(errors.map(Cause.fail).reduce(Cause.combine, Cause.empty as Cause.Cause<unknown>))\n}\n\n/**\n * Wraps the installed tracer so every exported span's failure and string\n * attributes pass through the journal redaction rules first.\n */\nconst redactedSpans = Layer.effect(Tracer.Tracer)(\n Effect.map(Effect.tracer, (tracer) =>\n Tracer.make({\n ...tracer,\n span(options) {\n const span = tracer.span(options)\n const end = span.end.bind(span)\n const attribute = span.attribute.bind(span)\n span.end = (endTime, exit) => end(endTime, redactedExit(exit))\n span.attribute = (key, value) => attribute(key, typeof value === \"string\" ? redactText(value) : value)\n return span\n }\n }))\n)\n\n/**\n * Configuration for the default OTLP wiring.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Options {\n /**\n * The collector base URL, for example `http://localhost:4318`. Signals are\n * posted below it at `/v1/logs`, `/v1/metrics`, and `/v1/traces`. It must be\n * an absolute `http://` or `https://` URL without credentials, a query,\n * fragment, backslashes, spaces, or controls. A base path is allowed. Invalid\n * values fail acquisition with {@link Endpoint.InvalidExporterEndpoint}.\n * Use {@link Options.headers} for authentication.\n */\n readonly baseUrl: string\n /** Overrides {@link defaultServiceName} as the `service.name` attribute. */\n readonly serviceName?: string | undefined\n /** Overrides {@link defaultServiceVersion} as the `service.version` attribute. */\n readonly serviceVersion?: string | undefined\n /**\n * Additional resource attributes attached to every exported signal, decoded\n * by `Resource.Attributes`. The whole resource must encode to at most\n * `Resource.maximumResourceBytes`; a larger one fails acquisition with\n * {@link Resource.InvalidResourceConfiguration} rather than making every\n * request oversized.\n */\n readonly attributes?: Record<string, unknown> | undefined\n /**\n * Headers sent with every export request, for example vendor auth. A header\n * whose name names a credential (`authorization`, `x-api-key`, anything\n * `Redaction.isSensitiveKey` recognizes, plus `x-honeycomb-team`) requires\n * an `https://` baseUrl unless the host is loopback; otherwise acquisition\n * fails with\n * {@link Endpoint.InvalidExporterEndpoint}.\n */\n readonly headers?: Headers.Input | undefined\n /** Export cadence for all three signals; each signal's Effect default applies when omitted. */\n readonly exportInterval?: Duration.Input | undefined\n /** Upper bound on the shutdown flush when the layer's scope closes. */\n readonly shutdownTimeout?: Duration.Input | undefined\n}\n\n/**\n * Creates the OTLP logs, metrics, and traces layer with flows resource\n * defaults, JSON-serialized. Exports share a four-request limit with no waiting\n * queue. Requests larger than 1 MiB or stalled for ten seconds are discarded;\n * `flows_observability_otlp_dropped` counts discarded batches, and at most\n * once a minute a `Warn` record with code `otlp_export_discarded` names the\n * reason, the request size, and the running total through the loggers that\n * were installed when the layer was acquired, never through this exporter.\n *\n * **Details**\n *\n * The layer still requires an `HttpClient`, which is how it stays\n * platform-neutral: a Node host may hand it `@effect/platform-node`'s Undici\n * client (re-exported by `@smthrs/platform-node`), a browser or test\n * hands it something else. Use {@link layerFetch} when the host's global\n * `fetch` is good enough. On Node 26 and every browser it is.\n * Fetch redirects are refused. Supply `FetchHttpClient.RequestInit` around\n * the whole exporting effect to retain other fetch options; options scoped\n * only to the supplied client's layer are replaced by the redirect policy.\n * Other HTTP transports must independently refuse automatic redirects.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = (\n options: Options\n): Layer.Layer<\n never,\n Resource.InvalidResourceConfiguration | Endpoint.InvalidExporterEndpoint,\n HttpClient.HttpClient\n> =>\n Layer.unwrap(\n Effect.map(\n Effect.all([\n Resource.decode({\n serviceName: options.serviceName ?? defaultServiceName,\n serviceVersion: options.serviceVersion ?? defaultServiceVersion,\n ...(options.attributes === undefined ? {} : { attributes: options.attributes })\n }),\n Endpoint.decode(options.baseUrl, \"baseUrl\").pipe(\n Effect.tap((baseUrl) => refusePlaintextCredentials(baseUrl, options.headers))\n )\n ]),\n ([decoded, baseUrl]) => {\n const resource = Resource.toOpenTelemetryConfiguration(decoded)\n return (\n Otlp.layerJson({\n baseUrl,\n resource: {\n serviceName: resource.serviceName,\n // `serviceVersion` is supplied above before Resource decoding.\n serviceVersion: resource.serviceVersion!,\n ...(resource.attributes === undefined ? {} : { attributes: resource.attributes })\n },\n headers: options.headers,\n maxBatchSize,\n loggerExportInterval: options.exportInterval,\n metricsExportInterval: options.exportInterval,\n tracerExportInterval: options.exportInterval,\n shutdownTimeout: options.shutdownTimeout\n }).pipe(\n Layer.provide(boundedClient),\n // Upstream merges OTEL_RESOURCE_ATTRIBUTES even with explicit\n // options. Keep unvalidated ambient metadata out of every request.\n Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))),\n (exporter) => Layer.provideMerge(redactedSpans, exporter)\n )\n )\n }\n )\n )\n\n/**\n * Provides {@link layer} over the host's global `fetch`, the default wiring\n * for a Node host, and browser-safe by construction because it never touches\n * a `node:` built-in.\n *\n * **Example**\n *\n * ```ts\n * import * as Otlp from \"@smthrs/observability/Otlp\"\n *\n * const Telemetry = Otlp.layerFetch({ baseUrl: \"http://localhost:4318\" })\n * ```\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerFetch = (\n options: Options\n): Layer.Layer<never, Resource.InvalidResourceConfiguration | Endpoint.InvalidExporterEndpoint> =>\n layer(options).pipe(Layer.provide(FetchHttpClient.layer))\n\n/**\n * Why an OTLP layer refused to start.\n *\n * @category errors\n * @since 1.0.0\n */\nexport type LayerError = Resource.InvalidResourceConfiguration | Endpoint.InvalidExporterEndpoint\n\n/**\n * Parses `OTEL_EXPORTER_OTLP_HEADERS`: comma-separated `key=value` pairs whose\n * values are percent-decoded, as the OpenTelemetry exporter specification\n * defines. A pair without `=` or with an empty key is skipped.\n *\n * @category environment\n * @since 1.0.0\n */\nexport const parseHeaders = (value: string | undefined): Record<string, string> => {\n const headers: Record<string, string> = {}\n for (const pair of (value ?? \"\").split(\",\")) {\n const separator = pair.indexOf(\"=\")\n const key = pair.slice(0, separator).trim()\n if (separator < 0 || key === \"\") continue\n const raw = pair.slice(separator + 1).trim()\n let decoded = raw\n try {\n decoded = decodeURIComponent(raw)\n } catch { /* A malformed escape is kept verbatim. */ }\n headers[key] = decoded\n }\n return headers\n}\n\n/**\n * {@link layerFetch} when the environment names a collector, otherwise\n * {@link layerNoop}.\n *\n * `OTEL_EXPORTER_OTLP_ENDPOINT` is the collector base URL and\n * `OTEL_EXPORTER_OTLP_HEADERS` the headers sent with every export. An unset or\n * empty endpoint installs no exporter at all.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerEnvironment = (\n environment: Readonly<Record<string, string | undefined>>,\n options: Omit<Options, \"baseUrl\" | \"headers\"> = {}\n): Layer.Layer<never, LayerError> => {\n const endpoint = environment[\"OTEL_EXPORTER_OTLP_ENDPOINT\"]?.trim()\n if (endpoint === undefined || endpoint === \"\") return layerNoop\n return layerFetch({ ...options, baseUrl: endpoint, headers: parseHeaders(environment[\"OTEL_EXPORTER_OTLP_HEADERS\"]) })\n}\n\n/**\n * Exports nothing. The explicit stand-in for hosts with no collector, such as\n * a development shell, a test, or a browser deployment that has not opted in, so\n * wiring code can switch layers rather than branch.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerNoop: Layer.Layer<never> = Layer.empty\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,gBAA2B;AAC3B,YAAuB;AACvB,mBAAsB;AACtB,qBAAgC;AAEhC,aAAwB;AACxB,WAAsB;AACtB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,iBAA4B;AAC5B,aAAwB;AACxB,gBAA2B;AAC3B,aAAwB;AACxB,sBAAiC;AACjC,cAAyB;AAEzB,iBAA4B;AAE5B,yBAAoC;A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,IAEJ;AAAA,EACF;AACF;AAkBK,MAAM,aAAa,CACxB,YAEA,MAAM,OAAO,EAAE,KAAK,MAAM,QAAQ,gBAAgB,KAAK,CAAC;AAkBnD,MAAM,eAAe,CAAC,UAAsD;AACjF,QAAM,UAAkC,CAAC;AACzC,aAAW,SAAS,SAAS,IAAI,MAAM,GAAG,GAAG;AAC3C,UAAM,YAAY,KAAK,QAAQ,GAAG;AAClC,UAAM,MAAM,KAAK,MAAM,GAAG,SAAS,EAAE,KAAK;AAC1C,QAAI,YAAY,KAAK,QAAQ,GAAI;AACjC,UAAM,MAAM,KAAK,MAAM,YAAY,CAAC,EAAE,KAAK;AAC3C,QAAI,UAAU;AACd,QAAI;AACF,gBAAU,mBAAmB,GAAG;AAAA,IAClC,QAAQ;AAAA,IAA6C;AACrD,YAAQ,GAAG,IAAI;AAAA,EACjB;AACA,SAAO;AACT;AAaO,MAAM,mBAAmB,CAC9B,aACA,UAAgD,CAAC,MACd;AACnC,QAAM,WAAW,YAAY,6BAA6B,GAAG,KAAK;AAClE,MAAI,aAAa,UAAa,aAAa,GAAI,QAAO;AACtD,SAAO,WAAW,EAAE,GAAG,SAAS,SAAS,UAAU,SAAS,aAAa,YAAY,4BAA4B,CAAC,EAAE,CAAC;AACvH;AAUO,MAAM,YAAgC,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicit, validated OpenTelemetry resource metadata for Smithers.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as OtelResource from "@effect/opentelemetry/Resource";
|
|
7
|
+
import type { Attributes as OtelAttributes } from "@opentelemetry/api";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
/**
|
|
12
|
+
* Largest service-name or service-version field accepted by a resource.
|
|
13
|
+
*
|
|
14
|
+
* @category constants
|
|
15
|
+
* @since 1.0.0-rc.0
|
|
16
|
+
*/
|
|
17
|
+
export declare const maximumIdentityLength = 1024;
|
|
18
|
+
/**
|
|
19
|
+
* Largest attribute key accepted by a resource.
|
|
20
|
+
*
|
|
21
|
+
* @category constants
|
|
22
|
+
* @since 1.0.0-rc.0
|
|
23
|
+
*/
|
|
24
|
+
export declare const maximumAttributeKeyLength = 1024;
|
|
25
|
+
/**
|
|
26
|
+
* Largest string value accepted by one resource attribute.
|
|
27
|
+
*
|
|
28
|
+
* @category constants
|
|
29
|
+
* @since 1.0.0-rc.0
|
|
30
|
+
*/
|
|
31
|
+
export declare const maximumAttributeStringLength = 65536;
|
|
32
|
+
/**
|
|
33
|
+
* Largest number of elements accepted in one array attribute value.
|
|
34
|
+
*
|
|
35
|
+
* @category constants
|
|
36
|
+
* @since 1.0.0-rc.0
|
|
37
|
+
*/
|
|
38
|
+
export declare const maximumAttributeArrayLength = 256;
|
|
39
|
+
/**
|
|
40
|
+
* Largest number of attributes accepted by one resource.
|
|
41
|
+
*
|
|
42
|
+
* @category constants
|
|
43
|
+
* @since 1.0.0-rc.0
|
|
44
|
+
*/
|
|
45
|
+
export declare const maximumAttributes = 256;
|
|
46
|
+
/**
|
|
47
|
+
* Largest OTLP/JSON encoding accepted for one whole resource, in UTF-8 bytes.
|
|
48
|
+
*
|
|
49
|
+
* The measure is the OTLP `Resource` message the exporters place in every
|
|
50
|
+
* request, `{"attributes":[{"key":…,"value":{…}}],"droppedAttributesCount":0}`
|
|
51
|
+
* with service identity and SDK-added `telemetry.sdk.name` and
|
|
52
|
+
* `telemetry.sdk.language` included, after JSON escaping and UTF-8 encoding.
|
|
53
|
+
* These SDK fields are conservatively reserved even for the default Effect
|
|
54
|
+
* exporter. Caller attributes overwritten by SDK identity or metadata are
|
|
55
|
+
* still counted. It is the bound the per-field limits cannot express: 256
|
|
56
|
+
* attributes at the string ceiling would encode to 16 MiB, and the resource
|
|
57
|
+
* rides in every export request, so the default transport, which discards a
|
|
58
|
+
* request over 1 MiB, would deliver nothing at all. 128 KiB admits one
|
|
59
|
+
* ASCII attribute at the string ceiling and leaves that transport 888 KiB of every
|
|
60
|
+
* request for the signal batch; see `Otlp.reservedBatchBytes`.
|
|
61
|
+
*
|
|
62
|
+
* @category constants
|
|
63
|
+
* @since 1.0.0-rc.0
|
|
64
|
+
*/
|
|
65
|
+
export declare const maximumResourceBytes = 131072;
|
|
66
|
+
/**
|
|
67
|
+
* Runtime schema for one OpenTelemetry resource attribute value.
|
|
68
|
+
*
|
|
69
|
+
* @category schemas
|
|
70
|
+
* @since 1.0.0-rc.0
|
|
71
|
+
*/
|
|
72
|
+
export declare const AttributeValue: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Number>, Schema.$Array<Schema.Boolean>]>;
|
|
73
|
+
/**
|
|
74
|
+
* Runtime schema for OpenTelemetry resource attributes.
|
|
75
|
+
*
|
|
76
|
+
* @category schemas
|
|
77
|
+
* @since 1.0.0-rc.0
|
|
78
|
+
*/
|
|
79
|
+
export declare const Attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Number>, Schema.$Array<Schema.Boolean>]>>;
|
|
80
|
+
/**
|
|
81
|
+
* Runtime schema for the service identity attached to exported telemetry.
|
|
82
|
+
*
|
|
83
|
+
* @category schemas
|
|
84
|
+
* @since 1.0.0-rc.0
|
|
85
|
+
*/
|
|
86
|
+
export declare const Configuration: Schema.Struct<{
|
|
87
|
+
readonly serviceName: Schema.NonEmptyString;
|
|
88
|
+
readonly serviceVersion: Schema.optional<Schema.NonEmptyString>;
|
|
89
|
+
readonly attributes: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Number>, Schema.$Array<Schema.Boolean>]>>>;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Configuration used to identify the service emitting telemetry.
|
|
93
|
+
*
|
|
94
|
+
* @category models
|
|
95
|
+
* @since 1.0.0-rc.0
|
|
96
|
+
*/
|
|
97
|
+
export type Configuration = typeof Configuration.Type;
|
|
98
|
+
declare const InvalidResourceConfiguration_base: Schema.Class<InvalidResourceConfiguration, Schema.TaggedStruct<"@smthrs/observability/InvalidResourceConfiguration", {
|
|
99
|
+
readonly code: Schema.Literal<"invalid_resource_configuration">;
|
|
100
|
+
readonly path: Schema.String;
|
|
101
|
+
readonly message: Schema.String;
|
|
102
|
+
}>, import("effect/Cause").YieldableError>;
|
|
103
|
+
/**
|
|
104
|
+
* Stable resource-configuration refusal shared by every OTEL layer.
|
|
105
|
+
*
|
|
106
|
+
* @category errors
|
|
107
|
+
* @since 1.0.0-rc.0
|
|
108
|
+
*/
|
|
109
|
+
export declare class InvalidResourceConfiguration extends InvalidResourceConfiguration_base {
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Decodes one resource configuration without retaining rejected values.
|
|
113
|
+
*
|
|
114
|
+
* @category decoding
|
|
115
|
+
* @since 1.0.0-rc.0
|
|
116
|
+
*/
|
|
117
|
+
export declare const decode: (configuration: unknown) => Effect.Effect<Configuration, InvalidResourceConfiguration>;
|
|
118
|
+
/**
|
|
119
|
+
* Decodes one resource configuration for the package's pure projection API.
|
|
120
|
+
*
|
|
121
|
+
* @category decoding
|
|
122
|
+
* @since 1.0.0-rc.0
|
|
123
|
+
*/
|
|
124
|
+
export declare const decodeSync: (configuration: unknown) => Configuration;
|
|
125
|
+
/**
|
|
126
|
+
* Projects a decoded resource into the exact optional-property shape expected
|
|
127
|
+
* by the OpenTelemetry SDK.
|
|
128
|
+
*
|
|
129
|
+
* @category conversions
|
|
130
|
+
* @since 1.0.0-rc.0
|
|
131
|
+
*/
|
|
132
|
+
export declare const toOpenTelemetryConfiguration: (configuration: Configuration) => {
|
|
133
|
+
readonly serviceName: string;
|
|
134
|
+
readonly serviceVersion?: string;
|
|
135
|
+
readonly attributes?: OtelAttributes;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Converts explicit service metadata into OpenTelemetry resource attributes.
|
|
139
|
+
*
|
|
140
|
+
* No environment variables are read. Invalid metadata throws the same typed
|
|
141
|
+
* {@link InvalidResourceConfiguration} every layer returns during acquisition.
|
|
142
|
+
*
|
|
143
|
+
* @category conversions
|
|
144
|
+
* @since 1.0.0-rc.0
|
|
145
|
+
*/
|
|
146
|
+
export declare const configToAttributes: (configuration: Configuration) => OtelAttributes;
|
|
147
|
+
/**
|
|
148
|
+
* Provides an explicitly validated OpenTelemetry resource.
|
|
149
|
+
*
|
|
150
|
+
* @category layers
|
|
151
|
+
* @since 1.0.0-rc.0
|
|
152
|
+
*/
|
|
153
|
+
export declare const layer: (configuration: Configuration) => Layer.Layer<OtelResource.Resource, InvalidResourceConfiguration>;
|
|
154
|
+
/**
|
|
155
|
+
* The OpenTelemetry resource service.
|
|
156
|
+
*
|
|
157
|
+
* @category services
|
|
158
|
+
* @since 1.0.0-rc.0
|
|
159
|
+
*/
|
|
160
|
+
export declare const Resource: typeof OtelResource.Resource;
|
|
161
|
+
export {};
|
|
162
|
+
//# sourceMappingURL=Resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resource.d.ts","sourceRoot":"","sources":["../../src/Resource.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,OAAQ,CAAA;AAE1C;;;;;GA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AEH;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,8BAAwB,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Resource_exports = {};
|
|
30
|
+
__export(Resource_exports, {
|
|
31
|
+
AttributeValue: () => AttributeValue,
|
|
32
|
+
Attributes: () => Attributes,
|
|
33
|
+
Configuration: () => Configuration,
|
|
34
|
+
InvalidResourceConfiguration: () => InvalidResourceConfiguration,
|
|
35
|
+
Resource: () => Resource,
|
|
36
|
+
configToAttributes: () => configToAttributes,
|
|
37
|
+
decode: () => decode,
|
|
38
|
+
decodeSync: () => decodeSync,
|
|
39
|
+
layer: () => layer,
|
|
40
|
+
maximumAttributeArrayLength: () => maximumAttributeArrayLength,
|
|
41
|
+
maximumAttributeKeyLength: () => maximumAttributeKeyLength,
|
|
42
|
+
maximumAttributeStringLength: () => maximumAttributeStringLength,
|
|
43
|
+
maximumAttributes: () => maximumAttributes,
|
|
44
|
+
maximumIdentityLength: () => maximumIdentityLength,
|
|
45
|
+
maximumResourceBytes: () => maximumResourceBytes,
|
|
46
|
+
toOpenTelemetryConfiguration: () => toOpenTelemetryConfiguration
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(Resource_exports);
|
|
49
|
+
var OtelResource = __toESM(require("@effect/opentelemetry/Resource"), 1);
|
|
50
|
+
var Effect = __toESM(require("effect/Effect"), 1);
|
|
51
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
52
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
53
|
+
var OtlpResource = __toESM(require("effect/unstable/observability/OtlpResource"), 1);
|
|
54
|
+
var import_schemaIssuePath = require("./internal/schemaIssuePath.js");
|
|
55
|
+
const maximumIdentityLength = 1024;
|
|
56
|
+
const maximumAttributeKeyLength = 1024;
|
|
57
|
+
const maximumAttributeStringLength = 65536;
|
|
58
|
+
const maximumAttributeArrayLength = 256;
|
|
59
|
+
const maximumAttributes = 256;
|
|
60
|
+
const maximumResourceBytes = 131072;
|
|
61
|
+
const loneSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
62
|
+
const embeddedNul = new RegExp(String.fromCharCode(0));
|
|
63
|
+
const isWellFormed = (value) => !loneSurrogate.test(value) && !embeddedNul.test(value);
|
|
64
|
+
const identity = Schema.NonEmptyString.check(
|
|
65
|
+
Schema.isMaxLength(maximumIdentityLength),
|
|
66
|
+
Schema.makeFilter((value) => isWellFormed(value), { title: "wellFormedResourceIdentity" })
|
|
67
|
+
);
|
|
68
|
+
const attributeString = Schema.String.check(
|
|
69
|
+
Schema.isMaxLength(maximumAttributeStringLength),
|
|
70
|
+
Schema.makeFilter((value) => isWellFormed(value), { title: "wellFormedAttributeString" })
|
|
71
|
+
);
|
|
72
|
+
const attributeNumber = Schema.Number.check(
|
|
73
|
+
Schema.makeFilter((value) => Number.isFinite(value), { title: "finiteAttributeNumber" })
|
|
74
|
+
);
|
|
75
|
+
const AttributeValue = Schema.Union([
|
|
76
|
+
attributeString,
|
|
77
|
+
attributeNumber,
|
|
78
|
+
Schema.Boolean,
|
|
79
|
+
Schema.Array(attributeString),
|
|
80
|
+
Schema.Array(attributeNumber),
|
|
81
|
+
Schema.Array(Schema.Boolean)
|
|
82
|
+
]).check(
|
|
83
|
+
Schema.makeFilter(
|
|
84
|
+
(value) => !Array.isArray(value) || value.length <= maximumAttributeArrayLength || {
|
|
85
|
+
path: [],
|
|
86
|
+
issue: `holds ${value.length} elements, over the ${maximumAttributeArrayLength} element limit`
|
|
87
|
+
},
|
|
88
|
+
{ title: "boundedResourceAttributeArrays" }
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
const Attributes = Schema.Record(Schema.String, AttributeValue).check(
|
|
92
|
+
Schema.makeFilter(
|
|
93
|
+
(attributes) => Object.keys(attributes).length <= maximumAttributes,
|
|
94
|
+
{ title: "boundedResourceAttributes" }
|
|
95
|
+
),
|
|
96
|
+
Schema.makeFilter(
|
|
97
|
+
(attributes) => Object.keys(attributes).every(
|
|
98
|
+
(key) => key.length > 0 && key.length <= maximumAttributeKeyLength && isWellFormed(key)
|
|
99
|
+
),
|
|
100
|
+
{ title: "wellFormedResourceAttributeKeys" }
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const encodedResourceBytes = (configuration) => {
|
|
105
|
+
const bytes = (value) => encoder.encode(JSON.stringify(value)).byteLength;
|
|
106
|
+
const identityAttributes = OtelResource.configToAttributes({
|
|
107
|
+
serviceName: configuration.serviceName,
|
|
108
|
+
...configuration.serviceVersion === void 0 ? {} : { serviceVersion: configuration.serviceVersion }
|
|
109
|
+
});
|
|
110
|
+
let total = bytes({
|
|
111
|
+
attributes: OtlpResource.entriesToAttributes(Object.entries(identityAttributes)),
|
|
112
|
+
droppedAttributesCount: 0
|
|
113
|
+
});
|
|
114
|
+
for (const [key, value] of Object.entries(configuration.attributes ?? {})) {
|
|
115
|
+
total += 1 + bytes({ key, value: Array.isArray(value) ? { arrayValue: { values: [] } } : null });
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
for (const [index, element] of value.entries()) {
|
|
118
|
+
total += (index === 0 ? 0 : 1) + bytes(OtlpResource.unknownToAttributeValue(element));
|
|
119
|
+
if (total > maximumResourceBytes) return total;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
total += bytes(OtlpResource.unknownToAttributeValue(value)) - 4;
|
|
123
|
+
}
|
|
124
|
+
if (total > maximumResourceBytes) return total;
|
|
125
|
+
}
|
|
126
|
+
return total;
|
|
127
|
+
};
|
|
128
|
+
const Configuration = Schema.Struct({
|
|
129
|
+
serviceName: identity,
|
|
130
|
+
serviceVersion: Schema.optional(identity),
|
|
131
|
+
attributes: Schema.optional(Attributes)
|
|
132
|
+
}).check(
|
|
133
|
+
Schema.makeFilter(
|
|
134
|
+
(configuration) => {
|
|
135
|
+
const bytes = encodedResourceBytes(configuration);
|
|
136
|
+
return bytes <= maximumResourceBytes || {
|
|
137
|
+
path: ["attributes"],
|
|
138
|
+
issue: `bring the resource to at least ${bytes} bytes of OTLP JSON, over the ${maximumResourceBytes} byte limit`
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
{ title: "boundedResourceBytes" }
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
class InvalidResourceConfiguration extends Schema.TaggedError()(
|
|
145
|
+
"@smthrs/observability/InvalidResourceConfiguration",
|
|
146
|
+
{
|
|
147
|
+
code: Schema.Literal("invalid_resource_configuration"),
|
|
148
|
+
path: Schema.String,
|
|
149
|
+
message: Schema.String
|
|
150
|
+
}
|
|
151
|
+
) {
|
|
152
|
+
}
|
|
153
|
+
const invalid = (cause) => {
|
|
154
|
+
const path = (0, import_schemaIssuePath.schemaIssuePath)(cause, "resource");
|
|
155
|
+
return new InvalidResourceConfiguration({
|
|
156
|
+
code: "invalid_resource_configuration",
|
|
157
|
+
path,
|
|
158
|
+
message: `OpenTelemetry resource ${path} ${(0, import_schemaIssuePath.schemaIssueMessage)(cause) ?? "is invalid"}`
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const decode = (configuration) => Schema.decodeUnknownEffect(Configuration)(configuration).pipe(Effect.mapError(invalid));
|
|
162
|
+
const decodeSync = (configuration) => {
|
|
163
|
+
try {
|
|
164
|
+
return Schema.decodeUnknownSync(Configuration)(configuration);
|
|
165
|
+
} catch (cause) {
|
|
166
|
+
throw invalid(cause);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const toOpenTelemetryConfiguration = (configuration) => ({
|
|
170
|
+
serviceName: configuration.serviceName,
|
|
171
|
+
...configuration.serviceVersion === void 0 ? {} : { serviceVersion: configuration.serviceVersion },
|
|
172
|
+
...configuration.attributes === void 0 ? {} : {
|
|
173
|
+
attributes: Object.fromEntries(
|
|
174
|
+
Object.entries(configuration.attributes).map(([key, value]) => [
|
|
175
|
+
key,
|
|
176
|
+
Array.isArray(value) ? [...value] : value
|
|
177
|
+
])
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const configToAttributes = (configuration) => OtelResource.configToAttributes(toOpenTelemetryConfiguration(decodeSync(configuration)));
|
|
182
|
+
const layer = (configuration) => Layer.unwrap(
|
|
183
|
+
Effect.map(decode(configuration), (decoded) => OtelResource.layer(toOpenTelemetryConfiguration(decoded)))
|
|
184
|
+
);
|
|
185
|
+
const Resource = OtelResource.Resource;
|
|
186
|
+
//# sourceMappingURL=Resource.js.map
|