@smthrs/observability 0.35.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 -843
- 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 -1392
- package/src/index.js +0 -137
- package/src/kindPhase.js +0 -17
- package/src/logging.js +0 -264
- 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 -1222
- 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
|
@@ -0,0 +1,237 @@
|
|
|
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 * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as OtlpResource from "effect/unstable/observability/OtlpResource";
|
|
11
|
+
import { schemaIssueMessage, schemaIssuePath } from "./internal/schemaIssuePath.js";
|
|
12
|
+
/**
|
|
13
|
+
* Largest service-name or service-version field accepted by a resource.
|
|
14
|
+
*
|
|
15
|
+
* @category constants
|
|
16
|
+
* @since 1.0.0-rc.0
|
|
17
|
+
*/
|
|
18
|
+
export const maximumIdentityLength = 1_024;
|
|
19
|
+
/**
|
|
20
|
+
* Largest attribute key accepted by a resource.
|
|
21
|
+
*
|
|
22
|
+
* @category constants
|
|
23
|
+
* @since 1.0.0-rc.0
|
|
24
|
+
*/
|
|
25
|
+
export const maximumAttributeKeyLength = 1_024;
|
|
26
|
+
/**
|
|
27
|
+
* Largest string value accepted by one resource attribute.
|
|
28
|
+
*
|
|
29
|
+
* @category constants
|
|
30
|
+
* @since 1.0.0-rc.0
|
|
31
|
+
*/
|
|
32
|
+
export const maximumAttributeStringLength = 65_536;
|
|
33
|
+
/**
|
|
34
|
+
* Largest number of elements accepted in one array attribute value.
|
|
35
|
+
*
|
|
36
|
+
* @category constants
|
|
37
|
+
* @since 1.0.0-rc.0
|
|
38
|
+
*/
|
|
39
|
+
export const maximumAttributeArrayLength = 256;
|
|
40
|
+
/**
|
|
41
|
+
* Largest number of attributes accepted by one resource.
|
|
42
|
+
*
|
|
43
|
+
* @category constants
|
|
44
|
+
* @since 1.0.0-rc.0
|
|
45
|
+
*/
|
|
46
|
+
export const maximumAttributes = 256;
|
|
47
|
+
/**
|
|
48
|
+
* Largest OTLP/JSON encoding accepted for one whole resource, in UTF-8 bytes.
|
|
49
|
+
*
|
|
50
|
+
* The measure is the OTLP `Resource` message the exporters place in every
|
|
51
|
+
* request, `{"attributes":[{"key":…,"value":{…}}],"droppedAttributesCount":0}`
|
|
52
|
+
* with service identity and SDK-added `telemetry.sdk.name` and
|
|
53
|
+
* `telemetry.sdk.language` included, after JSON escaping and UTF-8 encoding.
|
|
54
|
+
* These SDK fields are conservatively reserved even for the default Effect
|
|
55
|
+
* exporter. Caller attributes overwritten by SDK identity or metadata are
|
|
56
|
+
* still counted. It is the bound the per-field limits cannot express: 256
|
|
57
|
+
* attributes at the string ceiling would encode to 16 MiB, and the resource
|
|
58
|
+
* rides in every export request, so the default transport, which discards a
|
|
59
|
+
* request over 1 MiB, would deliver nothing at all. 128 KiB admits one
|
|
60
|
+
* ASCII attribute at the string ceiling and leaves that transport 888 KiB of every
|
|
61
|
+
* request for the signal batch; see `Otlp.reservedBatchBytes`.
|
|
62
|
+
*
|
|
63
|
+
* @category constants
|
|
64
|
+
* @since 1.0.0-rc.0
|
|
65
|
+
*/
|
|
66
|
+
export const maximumResourceBytes = 131_072;
|
|
67
|
+
const loneSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
68
|
+
const embeddedNul = new RegExp(String.fromCharCode(0));
|
|
69
|
+
const isWellFormed = (value) => !loneSurrogate.test(value) && !embeddedNul.test(value);
|
|
70
|
+
const identity = Schema.NonEmptyString.check(Schema.isMaxLength(maximumIdentityLength), Schema.makeFilter((value) => isWellFormed(value), { title: "wellFormedResourceIdentity" }));
|
|
71
|
+
const attributeString = Schema.String.check(Schema.isMaxLength(maximumAttributeStringLength), Schema.makeFilter((value) => isWellFormed(value), { title: "wellFormedAttributeString" }));
|
|
72
|
+
const attributeNumber = Schema.Number.check(Schema.makeFilter((value) => Number.isFinite(value), { title: "finiteAttributeNumber" }));
|
|
73
|
+
/**
|
|
74
|
+
* Runtime schema for one OpenTelemetry resource attribute value.
|
|
75
|
+
*
|
|
76
|
+
* @category schemas
|
|
77
|
+
* @since 1.0.0-rc.0
|
|
78
|
+
*/
|
|
79
|
+
export const AttributeValue = Schema.Union([
|
|
80
|
+
attributeString,
|
|
81
|
+
attributeNumber,
|
|
82
|
+
Schema.Boolean,
|
|
83
|
+
Schema.Array(attributeString),
|
|
84
|
+
Schema.Array(attributeNumber),
|
|
85
|
+
Schema.Array(Schema.Boolean)
|
|
86
|
+
]).check(Schema.makeFilter((value) => !Array.isArray(value) || value.length <= maximumAttributeArrayLength || {
|
|
87
|
+
path: [],
|
|
88
|
+
issue: `holds ${value.length} elements, over the ${maximumAttributeArrayLength} element limit`
|
|
89
|
+
}, { title: "boundedResourceAttributeArrays" }));
|
|
90
|
+
/**
|
|
91
|
+
* Runtime schema for OpenTelemetry resource attributes.
|
|
92
|
+
*
|
|
93
|
+
* @category schemas
|
|
94
|
+
* @since 1.0.0-rc.0
|
|
95
|
+
*/
|
|
96
|
+
export const Attributes = Schema.Record(Schema.String, AttributeValue).check(Schema.makeFilter((attributes) => Object.keys(attributes).length <= maximumAttributes, { title: "boundedResourceAttributes" }), Schema.makeFilter((attributes) => Object.keys(attributes).every((key) => key.length > 0 && key.length <= maximumAttributeKeyLength && isWellFormed(key)), { title: "wellFormedResourceAttributeKeys" }));
|
|
97
|
+
const encoder = new TextEncoder();
|
|
98
|
+
/**
|
|
99
|
+
* Counts OTLP JSON fragments, including keys, wrappers, escaping and UTF-8.
|
|
100
|
+
* Stops at the first fragment over budget: the refusal reports a lower bound.
|
|
101
|
+
* A configuration may reuse one large string in thousands of array slots, so
|
|
102
|
+
* serializing the whole resource before checking could allocate gigabytes.
|
|
103
|
+
*/
|
|
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 === undefined ? {} : { serviceVersion: configuration.serviceVersion })
|
|
109
|
+
});
|
|
110
|
+
// Use the pinned SDK projection so its added metadata cannot escape the
|
|
111
|
+
// complete-resource ceiling. Both exporters use these OTLP AnyValue shapes.
|
|
112
|
+
let total = bytes({
|
|
113
|
+
attributes: OtlpResource.entriesToAttributes(Object.entries(identityAttributes)),
|
|
114
|
+
droppedAttributesCount: 0
|
|
115
|
+
});
|
|
116
|
+
for (const [key, value] of Object.entries(configuration.attributes ?? {})) {
|
|
117
|
+
// An identity attribute is always present, so every addition needs a comma.
|
|
118
|
+
total += 1 + bytes({ key, value: Array.isArray(value) ? { arrayValue: { values: [] } } : null });
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
for (const [index, element] of value.entries()) {
|
|
121
|
+
total += (index === 0 ? 0 : 1) + bytes(OtlpResource.unknownToAttributeValue(element));
|
|
122
|
+
if (total > maximumResourceBytes)
|
|
123
|
+
return total;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
total += bytes(OtlpResource.unknownToAttributeValue(value)) - 4; // replace JSON null
|
|
128
|
+
}
|
|
129
|
+
if (total > maximumResourceBytes)
|
|
130
|
+
return total;
|
|
131
|
+
}
|
|
132
|
+
return total;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Runtime schema for the service identity attached to exported telemetry.
|
|
136
|
+
*
|
|
137
|
+
* @category schemas
|
|
138
|
+
* @since 1.0.0-rc.0
|
|
139
|
+
*/
|
|
140
|
+
export const Configuration = Schema.Struct({
|
|
141
|
+
serviceName: identity,
|
|
142
|
+
serviceVersion: Schema.optional(identity),
|
|
143
|
+
attributes: Schema.optional(Attributes)
|
|
144
|
+
}).check(Schema.makeFilter((configuration) => {
|
|
145
|
+
const bytes = encodedResourceBytes(configuration);
|
|
146
|
+
// Only attributes can carry a resource past the budget: the two identity
|
|
147
|
+
// fields encode to at most 6 KiB each, so the refusal points there.
|
|
148
|
+
return bytes <= maximumResourceBytes || {
|
|
149
|
+
path: ["attributes"],
|
|
150
|
+
issue: `bring the resource to at least ${bytes} bytes of OTLP JSON, over the ${maximumResourceBytes} byte limit`
|
|
151
|
+
};
|
|
152
|
+
}, { title: "boundedResourceBytes" }));
|
|
153
|
+
/**
|
|
154
|
+
* Stable resource-configuration refusal shared by every OTEL layer.
|
|
155
|
+
*
|
|
156
|
+
* @category errors
|
|
157
|
+
* @since 1.0.0-rc.0
|
|
158
|
+
*/
|
|
159
|
+
export class InvalidResourceConfiguration extends Schema.TaggedError()("@smthrs/observability/InvalidResourceConfiguration", {
|
|
160
|
+
code: Schema.Literal("invalid_resource_configuration"),
|
|
161
|
+
path: Schema.String,
|
|
162
|
+
message: Schema.String
|
|
163
|
+
}) {
|
|
164
|
+
}
|
|
165
|
+
const invalid = (cause) => {
|
|
166
|
+
const path = schemaIssuePath(cause, "resource");
|
|
167
|
+
return new InvalidResourceConfiguration({
|
|
168
|
+
code: "invalid_resource_configuration",
|
|
169
|
+
path,
|
|
170
|
+
message: `OpenTelemetry resource ${path} ${schemaIssueMessage(cause) ?? "is invalid"}`
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Decodes one resource configuration without retaining rejected values.
|
|
175
|
+
*
|
|
176
|
+
* @category decoding
|
|
177
|
+
* @since 1.0.0-rc.0
|
|
178
|
+
*/
|
|
179
|
+
export const decode = (configuration) => Schema.decodeUnknownEffect(Configuration)(configuration).pipe(Effect.mapError(invalid));
|
|
180
|
+
/**
|
|
181
|
+
* Decodes one resource configuration for the package's pure projection API.
|
|
182
|
+
*
|
|
183
|
+
* @category decoding
|
|
184
|
+
* @since 1.0.0-rc.0
|
|
185
|
+
*/
|
|
186
|
+
export const decodeSync = (configuration) => {
|
|
187
|
+
try {
|
|
188
|
+
return Schema.decodeUnknownSync(Configuration)(configuration);
|
|
189
|
+
}
|
|
190
|
+
catch (cause) {
|
|
191
|
+
throw invalid(cause);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Projects a decoded resource into the exact optional-property shape expected
|
|
196
|
+
* by the OpenTelemetry SDK.
|
|
197
|
+
*
|
|
198
|
+
* @category conversions
|
|
199
|
+
* @since 1.0.0-rc.0
|
|
200
|
+
*/
|
|
201
|
+
export const toOpenTelemetryConfiguration = (configuration) => ({
|
|
202
|
+
serviceName: configuration.serviceName,
|
|
203
|
+
...(configuration.serviceVersion === undefined ? {} : { serviceVersion: configuration.serviceVersion }),
|
|
204
|
+
...(configuration.attributes === undefined
|
|
205
|
+
? {}
|
|
206
|
+
: {
|
|
207
|
+
attributes: Object.fromEntries(Object.entries(configuration.attributes).map(([key, value]) => [
|
|
208
|
+
key,
|
|
209
|
+
Array.isArray(value) ? [...value] : value
|
|
210
|
+
]))
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
/**
|
|
214
|
+
* Converts explicit service metadata into OpenTelemetry resource attributes.
|
|
215
|
+
*
|
|
216
|
+
* No environment variables are read. Invalid metadata throws the same typed
|
|
217
|
+
* {@link InvalidResourceConfiguration} every layer returns during acquisition.
|
|
218
|
+
*
|
|
219
|
+
* @category conversions
|
|
220
|
+
* @since 1.0.0-rc.0
|
|
221
|
+
*/
|
|
222
|
+
export const configToAttributes = (configuration) => OtelResource.configToAttributes(toOpenTelemetryConfiguration(decodeSync(configuration)));
|
|
223
|
+
/**
|
|
224
|
+
* Provides an explicitly validated OpenTelemetry resource.
|
|
225
|
+
*
|
|
226
|
+
* @category layers
|
|
227
|
+
* @since 1.0.0-rc.0
|
|
228
|
+
*/
|
|
229
|
+
export const layer = (configuration) => Layer.unwrap(Effect.map(decode(configuration), (decoded) => OtelResource.layer(toOpenTelemetryConfiguration(decoded))));
|
|
230
|
+
/**
|
|
231
|
+
* The OpenTelemetry resource service.
|
|
232
|
+
*
|
|
233
|
+
* @category services
|
|
234
|
+
* @since 1.0.0-rc.0
|
|
235
|
+
*/
|
|
236
|
+
export const Resource = OtelResource.Resource;
|
|
237
|
+
//# sourceMappingURL=Resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../src/Resource.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAA;AAE9D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,4CAA4C,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEnF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAA;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAA;AAE3C,MAAM,aAAa,GAAG,wEAAwE,CAAA;AAC9F,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtD,MAAM,YAAY,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAEvG,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAC1C,MAAM,CAAC,WA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AAY,CAAC,KAAK,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC,CAAC,CAC1G,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability for flows: the default OTLP export wiring plus the
|
|
3
|
+
* Effect-native logger, metric, and OpenTelemetry resource layers.
|
|
4
|
+
*
|
|
5
|
+
* The store packages define and update their own metric handles
|
|
6
|
+
* (`JournalMetrics`, `RunStoreMetrics`, `CacheStoreMetrics`,
|
|
7
|
+
* `ArtifactStoreMetrics`, `DatabaseMetrics`) and open spans through Effect's
|
|
8
|
+
* tracer; this package is the exporter they deliberately leave out. `Otlp`
|
|
9
|
+
* only composes what `effect` already ships, so it is browser-bundleable. The
|
|
10
|
+
* remaining modules are the fuller stack folded in from the agent workspace:
|
|
11
|
+
* a structured `Logger`, a `JournalLogger` that mirrors log events into the
|
|
12
|
+
* run journal, `Metric` helpers, the `Resource` descriptor, and the `Otel`
|
|
13
|
+
* layer the OpenTelemetry SDK wiring installs behind.
|
|
14
|
+
*
|
|
15
|
+
* `NodeOtel` and `BrowserOtel` are deliberately NOT re-exported here. Each
|
|
16
|
+
* resolves a host-specific OpenTelemetry SDK. `NodeOtel` reaches Node-only
|
|
17
|
+
* host modules through `@effect/opentelemetry/NodeSdk` and
|
|
18
|
+
* `@opentelemetry/sdk-trace-node`, including the bare `async_hooks` specifier
|
|
19
|
+
* `@opentelemetry/context-async-hooks` imports, so re-exporting it would put a
|
|
20
|
+
* module a browser bundler cannot resolve in the root entry and break the
|
|
21
|
+
* browser bundle this package guarantees. Import them by subpath instead:
|
|
22
|
+
* `@smthrs/observability/NodeOtel`.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @category layers
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export * as Otlp from "./Otlp.ts";
|
|
31
|
+
/**
|
|
32
|
+
* @category observability
|
|
33
|
+
* @since 1.0.0-rc.0
|
|
34
|
+
*/
|
|
35
|
+
export * as Endpoint from "./Endpoint.ts";
|
|
36
|
+
/**
|
|
37
|
+
* @category observability
|
|
38
|
+
* @since 0.1.0
|
|
39
|
+
*/
|
|
40
|
+
export * as JournalLogger from "./JournalLogger.ts";
|
|
41
|
+
/**
|
|
42
|
+
* @category observability
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
export * as Logger from "./Logger.ts";
|
|
46
|
+
/**
|
|
47
|
+
* @category observability
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
*/
|
|
50
|
+
export * as Metric from "./Metric.ts";
|
|
51
|
+
/**
|
|
52
|
+
* @category observability
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
*/
|
|
55
|
+
export * as Otel from "./Otel.ts";
|
|
56
|
+
/**
|
|
57
|
+
* @category observability
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
*/
|
|
60
|
+
export * as Resource from "./Resource.ts";
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability for flows: the default OTLP export wiring plus the
|
|
3
|
+
* Effect-native logger, metric, and OpenTelemetry resource layers.
|
|
4
|
+
*
|
|
5
|
+
* The store packages define and update their own metric handles
|
|
6
|
+
* (`JournalMetrics`, `RunStoreMetrics`, `CacheStoreMetrics`,
|
|
7
|
+
* `ArtifactStoreMetrics`, `DatabaseMetrics`) and open spans through Effect's
|
|
8
|
+
* tracer; this package is the exporter they deliberately leave out. `Otlp`
|
|
9
|
+
* only composes what `effect` already ships, so it is browser-bundleable. The
|
|
10
|
+
* remaining modules are the fuller stack folded in from the agent workspace:
|
|
11
|
+
* a structured `Logger`, a `JournalLogger` that mirrors log events into the
|
|
12
|
+
* run journal, `Metric` helpers, the `Resource` descriptor, and the `Otel`
|
|
13
|
+
* layer the OpenTelemetry SDK wiring installs behind.
|
|
14
|
+
*
|
|
15
|
+
* `NodeOtel` and `BrowserOtel` are deliberately NOT re-exported here. Each
|
|
16
|
+
* resolves a host-specific OpenTelemetry SDK. `NodeOtel` reaches Node-only
|
|
17
|
+
* host modules through `@effect/opentelemetry/NodeSdk` and
|
|
18
|
+
* `@opentelemetry/sdk-trace-node`, including the bare `async_hooks` specifier
|
|
19
|
+
* `@opentelemetry/context-async-hooks` imports, so re-exporting it would put a
|
|
20
|
+
* module a browser bundler cannot resolve in the root entry and break the
|
|
21
|
+
* browser bundle this package guarantees. Import them by subpath instead:
|
|
22
|
+
* `@smthrs/observability/NodeOtel`.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @category layers
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export * as Otlp from "./Otlp.js";
|
|
31
|
+
/**
|
|
32
|
+
* @category observability
|
|
33
|
+
* @since 1.0.0-rc.0
|
|
34
|
+
*/
|
|
35
|
+
export * as Endpoint from "./Endpoint.js";
|
|
36
|
+
/**
|
|
37
|
+
* @category observability
|
|
38
|
+
* @since 0.1.0
|
|
39
|
+
*/
|
|
40
|
+
export * as JournalLogger from "./JournalLogger.js";
|
|
41
|
+
/**
|
|
42
|
+
* @category observability
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
export * as Logger from "./Logger.js";
|
|
46
|
+
/**
|
|
47
|
+
* @category observability
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
*/
|
|
50
|
+
export * as Metric from "./Metric.js";
|
|
51
|
+
/**
|
|
52
|
+
* @category observability
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
*/
|
|
55
|
+
export * as Otel from "./Otel.js";
|
|
56
|
+
/**
|
|
57
|
+
* @category observability
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
*/
|
|
60
|
+
export * as Resource from "./Resource.js";
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decoder-issue walk shared by this package's refusals.
|
|
3
|
+
*
|
|
4
|
+
* `JournalLogger` and `Resource` both publish the path of the option a decode
|
|
5
|
+
* rejected, and `Resource` also publishes the measured size a budget filter
|
|
6
|
+
* attached to its refusal. Effect's issues nest the same way for both, so the
|
|
7
|
+
* traversal lives once and a decoder change is followed once.
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
* @since 1.0.0-rc.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Walks a decode failure to the dotted path of the value it refused.
|
|
14
|
+
*
|
|
15
|
+
* Returns the caller's domain name when the failure carries no path at all.
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
* @since 1.0.0-rc.0
|
|
19
|
+
*/
|
|
20
|
+
export declare const schemaIssuePath: (error: unknown, fallback: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Reads the message a filter attached to the value a decode refused, when the
|
|
23
|
+
* filter attached one. None of the Effect checks this package composes attach
|
|
24
|
+
* one, so a refusal only ever carries text this package wrote, never the
|
|
25
|
+
* rejected value.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
* @since 1.0.0-rc.0
|
|
29
|
+
*/
|
|
30
|
+
export declare const schemaIssueMessage: (error: unknown) => string | undefined;
|
|
31
|
+
//# sourceMappingURL=schemaIssuePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaIssuePath.d.ts","sourceRoot":"","sources":["../../../src/internal/schemaIssuePath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA+BH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,EAAE,UAAU,MAAM,KAAG,MAAoD,CAAA;AAEvH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAI5D,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decoder-issue walk shared by this package's refusals.
|
|
3
|
+
*
|
|
4
|
+
* `JournalLogger` and `Resource` both publish the path of the option a decode
|
|
5
|
+
* rejected, and `Resource` also publishes the measured size a budget filter
|
|
6
|
+
* attached to its refusal. Effect's issues nest the same way for both, so the
|
|
7
|
+
* traversal lives once and a decoder change is followed once.
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
* @since 1.0.0-rc.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Walks a decode failure to its first offending leaf, collecting the path
|
|
14
|
+
* segments passed on the way. The walk is bounded so a self-referential issue
|
|
15
|
+
* tree cannot spin.
|
|
16
|
+
*/
|
|
17
|
+
const walk = (error) => {
|
|
18
|
+
let issue = error?.issue;
|
|
19
|
+
const segments = [];
|
|
20
|
+
for (let depth = 0; depth < 64 && typeof issue === "object" && issue !== null; depth++) {
|
|
21
|
+
const node = issue;
|
|
22
|
+
if (Array.isArray(node.path))
|
|
23
|
+
segments.push(...node.path.map(String));
|
|
24
|
+
if (node.issue !== undefined) {
|
|
25
|
+
issue = node.issue;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(node.issues) && node.issues[0] !== undefined) {
|
|
29
|
+
issue = node.issues[0];
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return { segments, leaf: issue };
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Walks a decode failure to the dotted path of the value it refused.
|
|
38
|
+
*
|
|
39
|
+
* Returns the caller's domain name when the failure carries no path at all.
|
|
40
|
+
*
|
|
41
|
+
* @private
|
|
42
|
+
* @since 1.0.0-rc.0
|
|
43
|
+
*/
|
|
44
|
+
export const schemaIssuePath = (error, fallback) => walk(error).segments.join(".") || fallback;
|
|
45
|
+
/**
|
|
46
|
+
* Reads the message a filter attached to the value a decode refused, when the
|
|
47
|
+
* filter attached one. None of the Effect checks this package composes attach
|
|
48
|
+
* one, so a refusal only ever carries text this package wrote, never the
|
|
49
|
+
* rejected value.
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
* @since 1.0.0-rc.0
|
|
53
|
+
*/
|
|
54
|
+
export const schemaIssueMessage = (error) => {
|
|
55
|
+
const leaf = walk(error).leaf;
|
|
56
|
+
const message = leaf?.annotations?.message;
|
|
57
|
+
return typeof message === "string" ? message : undefined;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=schemaIssuePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaIssuePath.js","sourceRoot":"","sources":["../../../src/internal/schemaIssuePath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;;;GAIG;AACH,MAAM,IAAI,GAAG,CAAC,KAAc,EAAa,EAAE;IACzC,IAAI,KAAK,GAAI,KAA6C,EAAE,KAAK,CAAA;IACjE,MAAM,QAAQ,GAAkB,EAAE,CAAA;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACvF,MAAM,IAAI,GAAG,KAAyF,CAAA;QACtG,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;QACrE,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;YAClB,SAAQ;QACV,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YAC/D,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YACtB,SAAQ;QACV,CAAC;QACD,MAAK;IACP,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AAClC,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAE,QAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAA;AAEvH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAoF,CAAA;IAC7G,MAAM,OAAO,GAAG,IAAI,EAAE,WAAW,EAAE,OAAO,CAAA;IAC1C,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1D,CAAC,CAAA"}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "@smthrs/observability"
|
|
3
|
+
description: "Send an Effect program's logs, metrics, and traces to an OpenTelemetry collector with one layer, no OpenTelemetry SDK, and a collector endpoint that is validated before anything exports."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
`@smthrs/observability` sends an Effect program's logs, metrics, and traces to
|
|
7
|
+
an OpenTelemetry collector. You add one layer to turn delivery on, and delete
|
|
8
|
+
that one line to turn it off; nothing else in the program changes.
|
|
9
|
+
|
|
10
|
+
## What it solves
|
|
11
|
+
|
|
12
|
+
An Effect program already produces telemetry without an exporter.
|
|
13
|
+
`Effect.withSpan` opens a span on Effect's tracer, `Metric.update` advances a
|
|
14
|
+
counter in Effect's metric registry, and `Effect.logInfo` writes a log record.
|
|
15
|
+
With nothing installed to deliver them, all three are collected and discarded.
|
|
16
|
+
|
|
17
|
+
The usual way to deliver them is an OpenTelemetry SDK: several packages, a
|
|
18
|
+
provider for each signal, and a bundle a browser build cannot carry. This
|
|
19
|
+
package is the smaller answer for the common case. `Otlp` composes only what
|
|
20
|
+
`effect` itself ships, so it pulls in no OpenTelemetry SDK, runs unchanged in
|
|
21
|
+
Node, Bun, and a browser, and posts all three signals to a collector over the
|
|
22
|
+
host's global `fetch`.
|
|
23
|
+
|
|
24
|
+
Two behaviors matter beyond the delivery itself:
|
|
25
|
+
|
|
26
|
+
- **A bad endpoint is refused at startup.** Export failure is absorbed by
|
|
27
|
+
design, so an exporter pointed at `collector:4318` or at a URL with a
|
|
28
|
+
trailing newline behaves exactly like a healthy one and delivers nothing
|
|
29
|
+
forever. Endpoints and service identities are decoded when the layer is
|
|
30
|
+
built, and a bad one fails there with a typed error.
|
|
31
|
+
- **Log records can also go somewhere durable.** `JournalLogger` mirrors a
|
|
32
|
+
run's log records into a run journal, so an operator reads them back in
|
|
33
|
+
process without standing up a collector at all.
|
|
34
|
+
|
|
35
|
+
When one layer is not enough, `NodeOtel`, `BrowserOtel`, and `Otel` wire a real
|
|
36
|
+
OpenTelemetry SDK, and every builder attaches the same validated service
|
|
37
|
+
identity, so `service.name` means the same thing whichever one you pick.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Not on npm yet; see [Installation](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/flow/docs/installation.md#use-the-libraries).
|
|
42
|
+
|
|
43
|
+
Node.js 26.4.0 or later. For the import forms and the browser rule, see
|
|
44
|
+
[Installation](./installation.md).
|
|
45
|
+
|
|
46
|
+
## Export all three signals
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import * as Otlp from "@smthrs/observability/Otlp"
|
|
50
|
+
import * as Effect from "effect/Effect"
|
|
51
|
+
import * as Metric from "effect/Metric"
|
|
52
|
+
|
|
53
|
+
const deployments = Metric.counter("deployments")
|
|
54
|
+
|
|
55
|
+
const program = Effect.gen(function*() {
|
|
56
|
+
yield* Effect.logInfo("deploying the API")
|
|
57
|
+
yield* Metric.update(deployments, 1)
|
|
58
|
+
}).pipe(Effect.withSpan("deploy"))
|
|
59
|
+
|
|
60
|
+
const telemetry = Otlp.layerFetch({
|
|
61
|
+
baseUrl: "http://localhost:4318",
|
|
62
|
+
serviceName: "deploy-status"
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
await Effect.runPromise(
|
|
66
|
+
program.pipe(Effect.provide(telemetry), Effect.orDie, Effect.scoped)
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The span posts to the collector's `/v1/traces` path, the log record to
|
|
71
|
+
`/v1/logs`, and the counter to `/v1/metrics`, all tagged `service.name:
|
|
72
|
+
deploy-status`. The exporters batch, so closing the layer's scope is what
|
|
73
|
+
flushes them: that is why the program ends in `Effect.scoped`. The
|
|
74
|
+
[Quickstart](./quickstart.md) runs this against a twelve-line collector
|
|
75
|
+
stand-in so you can watch each signal land.
|
|
76
|
+
|
|
77
|
+
## How this fits with @smthrs/flows
|
|
78
|
+
|
|
79
|
+
Smithers is a durable flow engine: a flow records each step as it completes, so
|
|
80
|
+
a process that dies replays what already finished and resumes at the first step
|
|
81
|
+
that did not. [`@smthrs/flows`](/api/flows) is the single npm package that
|
|
82
|
+
carries that whole engine, and it re-exports this one as its `Observability`
|
|
83
|
+
namespace. A program that already depends on `@smthrs/flows` has these layers
|
|
84
|
+
available without adding a dependency:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { Observability } from "@smthrs/flows"
|
|
88
|
+
|
|
89
|
+
const telemetry = Observability.Otlp.layerFetch({
|
|
90
|
+
baseUrl: "http://localhost:4318",
|
|
91
|
+
serviceName: "deploy-status"
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
That relationship is also why this package ships more than an exporter. The
|
|
96
|
+
engine packages under `@smthrs/flows` instrument themselves: they open spans on
|
|
97
|
+
Effect's tracer and update their own metric handles on their hot paths, and
|
|
98
|
+
none of them allocates an exporter. Providing one layer from this package turns
|
|
99
|
+
delivery on for all of that instrumentation at once. The `JournalLogger` and
|
|
100
|
+
`Metric` modules exist for the same reason: a run journal and a shared set of
|
|
101
|
+
runtime metric handles are what a durable engine needs and a standalone
|
|
102
|
+
exporter does not.
|
|
103
|
+
|
|
104
|
+
You do not need the engine to use this package. `Otlp`, `Logger`, `Resource`,
|
|
105
|
+
`Otel`, `NodeOtel`, and `BrowserOtel` work in any Effect program. Only
|
|
106
|
+
`JournalLogger` requires a journal, from [`@smthrs/journal`](/api/journal).
|
|
107
|
+
|
|
108
|
+
Above `@smthrs/flows` sits [`smithers`](/api/cli), the command-line interface
|
|
109
|
+
that runs, resumes, and inspects flows. Start there if you want to run flows
|
|
110
|
+
rather than embed the engine in your own program.
|
|
111
|
+
|
|
112
|
+
## Who uses this package
|
|
113
|
+
|
|
114
|
+
Host and CLI authors install the exporter, a logger, and, for a control-plane
|
|
115
|
+
run, the journal forwarder. Operators read the result: spans and metric series
|
|
116
|
+
in a collector, `telemetry.log` rows on a run's journal. Authors of the engine
|
|
117
|
+
packages use `Metric` to update a shared runtime handle, and touch nothing else
|
|
118
|
+
here.
|
|
119
|
+
|
|
120
|
+
## The package at a glance
|
|
121
|
+
|
|
122
|
+
The root entry point exports these namespaces, and each is also importable from
|
|
123
|
+
`@smthrs/observability/<Module>`:
|
|
124
|
+
|
|
125
|
+
| Namespace | What it is |
|
|
126
|
+
| --------------- | ----------------------------------------------------------------------------------------------------- |
|
|
127
|
+
| `Otlp` | The default exporter: one layer that posts logs, metrics, and traces to a collector, no SDK involved. |
|
|
128
|
+
| `Endpoint` | The validated collector endpoint every OTLP builder decodes before it exports anything. |
|
|
129
|
+
| `Resource` | The validated service identity attached to every exported signal. |
|
|
130
|
+
| `Logger` | Effect logger layers: pretty for development, one JSON object per line for production, and silence. |
|
|
131
|
+
| `JournalLogger` | A bounded, drop-on-overflow forwarder that mirrors log records into a run's durable journal. |
|
|
132
|
+
| `Metric` | The four runtime metric handles the engine packages update, and their exported identifiers. |
|
|
133
|
+
| `Otel` | The provider-neutral bridge for an OpenTelemetry SDK the application already built. |
|
|
134
|
+
|
|
135
|
+
Two more modules are subpath-only, because each resolves a host-specific
|
|
136
|
+
OpenTelemetry SDK:
|
|
137
|
+
|
|
138
|
+
| Import | What it is |
|
|
139
|
+
| ----------------------------------- | ----------------------------------------------------------------------- |
|
|
140
|
+
| `@smthrs/observability/NodeOtel` | Node OTLP/HTTP wiring over the OpenTelemetry SDK. Node only. |
|
|
141
|
+
| `@smthrs/observability/BrowserOtel` | Browser OpenTelemetry wiring over processors and readers you construct. |
|
|
142
|
+
|
|
143
|
+
Every export, with signatures and failure types, is on the
|
|
144
|
+
[API reference](./api.md).
|
|
145
|
+
|
|
146
|
+
## Where to go next
|
|
147
|
+
|
|
148
|
+
- [Installation](./installation.md): requirements, import forms, and which
|
|
149
|
+
packages a real composition adds.
|
|
150
|
+
- [Quickstart](./quickstart.md): export a trace, a log record, and a metric
|
|
151
|
+
series to a collector you can watch, in about thirty lines.
|
|
152
|
+
- Guides: [export to a collector](./guides/export-to-a-collector.md),
|
|
153
|
+
[wire an OpenTelemetry SDK](./guides/wire-an-opentelemetry-sdk.md),
|
|
154
|
+
[forward logs to the journal](./guides/forward-logs-to-the-journal.md),
|
|
155
|
+
[install a logger](./guides/install-a-logger.md),
|
|
156
|
+
[read the runtime metrics](./guides/read-runtime-metrics.md), and
|
|
157
|
+
[test telemetry without a collector](./guides/testing.md).
|
|
158
|
+
- Concepts: [instrumentation and export](./concepts/instrumentation-and-export.md),
|
|
159
|
+
[the layer map](./concepts/layer-map.md), and
|
|
160
|
+
[validation at layer acquisition](./concepts/validated-acquisition.md).
|
|
161
|
+
- [Troubleshooting](./troubleshooting.md): the typed refusals this package
|
|
162
|
+
reports, and the silent cases that are not refusals at all.
|