@oatscenter/trellis 0.100.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/auth/authorization/client_context.d.ts +61 -0
- package/auth/authorization/client_context.js +266 -0
- package/auth/authorization/nats_registry.d.ts +41 -0
- package/auth/authorization/nats_registry.js +283 -0
- package/auth/authorization/provider_cache.d.ts +90 -0
- package/auth/authorization/provider_cache.js +783 -0
- package/auth/authorization/refresh.d.ts +46 -0
- package/auth/authorization/refresh.js +246 -0
- package/auth/authorization/types.d.ts +207 -0
- package/auth/authorization/types.js +60 -0
- package/auth/authorization_context.d.ts +11 -0
- package/auth/authorization_context.js +10 -0
- package/auth/browser/flow_types.d.ts +84 -0
- package/auth/browser/flow_types.js +70 -0
- package/auth/browser/portal.d.ts +21 -0
- package/auth/browser/portal.js +307 -0
- package/auth/browser/storage.d.ts +26 -0
- package/auth/browser/storage.js +224 -0
- package/auth/browser.d.ts +11 -0
- package/auth/browser.js +10 -0
- package/auth/browser_recovery.d.ts +13 -0
- package/auth/browser_recovery.js +38 -0
- package/auth/device_activation.d.ts +134 -0
- package/auth/device_activation.js +376 -0
- package/auth/http_error.d.ts +12 -0
- package/auth/http_error.js +32 -0
- package/auth/keys.d.ts +5 -0
- package/auth/keys.js +63 -0
- package/auth/mod.d.ts +16 -0
- package/auth/mod.js +16 -0
- package/auth/proof.d.ts +31 -0
- package/auth/proof.js +95 -0
- package/auth/protocol_wasm/trellis_protocol_wasm.d.ts +138 -0
- package/auth/protocol_wasm/trellis_protocol_wasm.js +605 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bytes.d.ts +1 -0
- package/auth/protocol_wasm/trellis_protocol_wasm_bytes.js +2 -0
- package/auth/protocol_wasm.d.ts +179 -0
- package/auth/protocol_wasm.js +133 -0
- package/auth/session_auth.d.ts +30 -0
- package/auth/session_auth.js +77 -0
- package/auth/session_proof.d.ts +53 -0
- package/auth/session_proof.js +43 -0
- package/auth/time.d.ts +6 -0
- package/auth/time.js +7 -0
- package/auth/trellis_id.d.ts +1 -0
- package/auth/trellis_id.js +5 -0
- package/auth/utils.d.ts +10 -0
- package/auth/utils.js +69 -0
- package/auth.d.ts +1 -0
- package/auth.js +1 -0
- package/caller.d.ts +111 -0
- package/caller.js +85 -0
- package/client.d.ts +14 -0
- package/client.js +1 -0
- package/client_connect.d.ts +143 -0
- package/client_connect.js +1097 -0
- package/codec.d.ts +13 -0
- package/codec.js +192 -0
- package/connection.d.ts +107 -0
- package/connection.js +396 -0
- package/device/activation.d.ts +42 -0
- package/device/activation.js +319 -0
- package/device.d.ts +80 -0
- package/device.js +687 -0
- package/env.d.ts +2 -0
- package/env.js +10 -0
- package/errors/AuthError.d.ts +30 -0
- package/errors/AuthError.js +34 -0
- package/errors/KVError.d.ts +30 -0
- package/errors/KVError.js +36 -0
- package/errors/OperationLifecycleError.d.ts +110 -0
- package/errors/OperationLifecycleError.js +142 -0
- package/errors/RemoteError.d.ts +61 -0
- package/errors/RemoteError.js +72 -0
- package/errors/SchemaValidationError.d.ts +48 -0
- package/errors/SchemaValidationError.js +49 -0
- package/errors/StoreError.d.ts +21 -0
- package/errors/StoreError.js +31 -0
- package/errors/TransferError.d.ts +21 -0
- package/errors/TransferError.js +31 -0
- package/errors/TransportError.d.ts +29 -0
- package/errors/TransportError.js +33 -0
- package/errors/TrellisError.d.ts +15 -0
- package/errors/TrellisError.js +15 -0
- package/errors/ValidationError.d.ts +50 -0
- package/errors/ValidationError.js +59 -0
- package/errors/index.d.ts +254 -0
- package/errors/index.js +238 -0
- package/generated.d.ts +4 -0
- package/generated.js +3 -0
- package/generated_support.d.ts +120 -0
- package/generated_support.js +359 -0
- package/globals.d.ts +9 -0
- package/globals.js +16 -0
- package/health_transport.d.ts +18 -0
- package/health_transport.js +32 -0
- package/helpers.d.ts +11 -0
- package/helpers.js +53 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/internal_sdk/generated/apis/auth/mod.d.ts +805 -0
- package/internal_sdk/generated/apis/auth/mod.js +958 -0
- package/internal_sdk/generated/apis/core/mod.d.ts +79 -0
- package/internal_sdk/generated/apis/core/mod.js +93 -0
- package/internal_sdk/generated/apis/events/mod.d.ts +224 -0
- package/internal_sdk/generated/apis/events/mod.js +313 -0
- package/internal_sdk/generated/apis/health/mod.d.ts +106 -0
- package/internal_sdk/generated/apis/health/mod.js +132 -0
- package/internal_sdk/generated/apis/index.d.ts +7 -0
- package/internal_sdk/generated/apis/index.js +8 -0
- package/internal_sdk/generated/apis/jobs/mod.d.ts +176 -0
- package/internal_sdk/generated/apis/jobs/mod.js +209 -0
- package/internal_sdk/generated/apis/state/mod.d.ts +104 -0
- package/internal_sdk/generated/apis/state/mod.js +139 -0
- package/internal_sdk/generated/index.d.ts +4 -0
- package/internal_sdk/generated/index.js +5 -0
- package/internal_sdk/generated/package.json +18 -0
- package/internal_sdk/generated/participants/cli/mod.d.ts +402 -0
- package/internal_sdk/generated/participants/cli/mod.js +460 -0
- package/internal_sdk/generated/participants/cli/types.d.ts +2 -0
- package/internal_sdk/generated/participants/cli/types.js +3 -0
- package/internal_sdk/generated/participants/console/mod.d.ts +489 -0
- package/internal_sdk/generated/participants/console/mod.js +579 -0
- package/internal_sdk/generated/participants/console/types.d.ts +2 -0
- package/internal_sdk/generated/participants/console/types.js +3 -0
- package/internal_sdk/generated/participants/eventsRuntime/mod.d.ts +64 -0
- package/internal_sdk/generated/participants/eventsRuntime/mod.js +42 -0
- package/internal_sdk/generated/participants/eventsRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/eventsRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/healthRuntime/mod.d.ts +58 -0
- package/internal_sdk/generated/participants/healthRuntime/mod.js +36 -0
- package/internal_sdk/generated/participants/healthRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/healthRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/index.d.ts +8 -0
- package/internal_sdk/generated/participants/index.js +9 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.d.ts +64 -0
- package/internal_sdk/generated/participants/jobsRuntime/mod.js +42 -0
- package/internal_sdk/generated/participants/jobsRuntime/types.d.ts +2 -0
- package/internal_sdk/generated/participants/jobsRuntime/types.js +3 -0
- package/internal_sdk/generated/participants/platform/mod.d.ts +164 -0
- package/internal_sdk/generated/participants/platform/mod.js +149 -0
- package/internal_sdk/generated/participants/platform/types.d.ts +7 -0
- package/internal_sdk/generated/participants/platform/types.js +5 -0
- package/internal_sdk/generated/participants/portal/mod.d.ts +131 -0
- package/internal_sdk/generated/participants/portal/mod.js +109 -0
- package/internal_sdk/generated/participants/portal/types.d.ts +2 -0
- package/internal_sdk/generated/participants/portal/types.js +3 -0
- package/internal_sdk/generated/types/_internal/p0.d.ts +13511 -0
- package/internal_sdk/generated/types/_internal/p0.js +6105 -0
- package/internal_sdk/generated/types/index.d.ts +2951 -0
- package/internal_sdk/generated/types/index.js +1477 -0
- package/jobs.d.ts +309 -0
- package/jobs.js +389 -0
- package/kv.d.ts +85 -0
- package/kv.js +330 -0
- package/operations.d.ts +189 -0
- package/operations.js +847 -0
- package/package.json +73 -0
- package/pagination.d.ts +25 -0
- package/pagination.js +117 -0
- package/participant.d.ts +6 -0
- package/participant.js +6 -0
- package/participant_runtime/api.d.ts +131 -0
- package/participant_runtime/api.js +42 -0
- package/participant_runtime/json.d.ts +16 -0
- package/participant_runtime/json.js +193 -0
- package/participant_runtime/metadata.d.ts +34 -0
- package/participant_runtime/metadata.js +4 -0
- package/participant_runtime/participant.d.ts +200 -0
- package/participant_runtime/participant.js +330 -0
- package/participant_runtime/schemas.d.ts +347 -0
- package/participant_runtime/schemas.js +211 -0
- package/participant_runtime/surface_names.d.ts +16 -0
- package/participant_runtime/surface_names.js +34 -0
- package/portable.d.ts +30 -0
- package/portable.js +14 -0
- package/provider.d.ts +69 -0
- package/provider.js +68 -0
- package/runtime_transport.d.ts +25 -0
- package/runtime_transport.js +48 -0
- package/service/mod.d.ts +14 -0
- package/service/mod.js +13 -0
- package/service/outbox_inbox.d.ts +259 -0
- package/service/outbox_inbox.js +908 -0
- package/service/runtime/bootstrap.d.ts +56 -0
- package/service/runtime/bootstrap.js +226 -0
- package/service/runtime/core.d.ts +46 -0
- package/service/runtime/core.js +1747 -0
- package/service/runtime/health.d.ts +97 -0
- package/service/runtime/health.js +153 -0
- package/service/runtime/health_schemas.d.ts +23 -0
- package/service/runtime/health_schemas.js +20 -0
- package/service/runtime/internal_jobs/active-job.d.ts +40 -0
- package/service/runtime/internal_jobs/active-job.js +91 -0
- package/service/runtime/internal_jobs/bindings.d.ts +40 -0
- package/service/runtime/internal_jobs/bindings.js +1 -0
- package/service/runtime/internal_jobs/cancellation-registry.d.ts +13 -0
- package/service/runtime/internal_jobs/cancellation-registry.js +55 -0
- package/service/runtime/internal_jobs/heartbeat.d.ts +33 -0
- package/service/runtime/internal_jobs/heartbeat.js +65 -0
- package/service/runtime/internal_jobs/job-manager.d.ts +126 -0
- package/service/runtime/internal_jobs/job-manager.js +821 -0
- package/service/runtime/internal_jobs/key-coordinator.d.ts +280 -0
- package/service/runtime/internal_jobs/key-coordinator.js +747 -0
- package/service/runtime/internal_jobs/projection.d.ts +3 -0
- package/service/runtime/internal_jobs/projection.js +42 -0
- package/service/runtime/internal_jobs/runtime-worker.d.ts +126 -0
- package/service/runtime/internal_jobs/runtime-worker.js +454 -0
- package/service/runtime/internal_jobs/types.d.ts +246 -0
- package/service/runtime/internal_jobs/types.js +163 -0
- package/service/runtime/logger.d.ts +2 -0
- package/service/runtime/logger.js +7 -0
- package/service/runtime/runtime.d.ts +16 -0
- package/service/runtime/runtime.js +1 -0
- package/service/runtime/service.d.ts +372 -0
- package/service/runtime/service.js +1896 -0
- package/service/runtime/transfer/download.d.ts +27 -0
- package/service/runtime/transfer/download.js +1 -0
- package/service/runtime/transfer/protocol.d.ts +15 -0
- package/service/runtime/transfer/protocol.js +46 -0
- package/service/runtime/transfer/queue.d.ts +18 -0
- package/service/runtime/transfer/queue.js +136 -0
- package/service/runtime/transfer/upload.d.ts +40 -0
- package/service/runtime/transfer/upload.js +27 -0
- package/service/runtime/transfer.d.ts +62 -0
- package/service/runtime/transfer.js +763 -0
- package/session.d.ts +862 -0
- package/session.js +3407 -0
- package/store.d.ts +71 -0
- package/store.js +412 -0
- package/store_entry.d.ts +20 -0
- package/store_entry.js +75 -0
- package/tasks.d.ts +10 -0
- package/tasks.js +28 -0
- package/telemetry/carrier.d.ts +8 -0
- package/telemetry/carrier.js +20 -0
- package/telemetry/core.d.ts +7 -0
- package/telemetry/core.js +14 -0
- package/telemetry/env.d.ts +2 -0
- package/telemetry/env.js +10 -0
- package/telemetry/init.d.ts +2 -0
- package/telemetry/init.js +7 -0
- package/telemetry/metrics.d.ts +81 -0
- package/telemetry/metrics.js +267 -0
- package/telemetry/mod.d.ts +13 -0
- package/telemetry/mod.js +8 -0
- package/telemetry/nats.d.ts +6 -0
- package/telemetry/nats.js +6 -0
- package/telemetry/result.d.ts +1 -0
- package/telemetry/result.js +18 -0
- package/telemetry/runtime.d.ts +1 -0
- package/telemetry/runtime.js +141 -0
- package/telemetry/trace.d.ts +4 -0
- package/telemetry/trace.js +26 -0
- package/telemetry/trellis.d.ts +1 -0
- package/telemetry/trellis.js +1 -0
- package/telemetry.d.ts +1 -0
- package/telemetry.js +1 -0
- package/transfer.d.ts +112 -0
- package/transfer.js +525 -0
- package/transfer_protocol.d.ts +1 -0
- package/transfer_protocol.js +13 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { configureErrorTraceId } from "./result.js";
|
|
2
|
+
import { initTelemetryRuntime } from "./runtime.js";
|
|
3
|
+
/** Initializes Trellis telemetry for a service runtime. */
|
|
4
|
+
export function initTelemetry(serviceName) {
|
|
5
|
+
configureErrorTraceId();
|
|
6
|
+
initTelemetryRuntime(serviceName);
|
|
7
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Meter } from "@opentelemetry/api";
|
|
2
|
+
/** Low-cardinality attributes accepted by {@link recordTrellisError}. */
|
|
3
|
+
export type TrellisErrorMetricAttributes = {
|
|
4
|
+
/** Stable Trellis surface name, such as `rpc`, `jobs`, or `operations`. */
|
|
5
|
+
surface?: string;
|
|
6
|
+
/** Stable flow direction such as `client`, `server`, `publish`, or `consume`. */
|
|
7
|
+
direction?: string;
|
|
8
|
+
/** Stable operation kind or method name. Do not pass IDs, subjects, or URLs. */
|
|
9
|
+
operation?: string;
|
|
10
|
+
/** Stable lifecycle phase such as `encode`, `send`, `auth`, or `handler`. */
|
|
11
|
+
phase?: string;
|
|
12
|
+
/** Stable local Trellis error type override when the thrown value does not expose one. */
|
|
13
|
+
errorType?: string;
|
|
14
|
+
/** Stable wrapped remote Trellis error type override. */
|
|
15
|
+
remoteErrorType?: string;
|
|
16
|
+
/** Stable auth failure reason, such as `missing_session_key`. */
|
|
17
|
+
authReason?: string;
|
|
18
|
+
/** Static messaging system name, when already known. */
|
|
19
|
+
messagingSystem?: string;
|
|
20
|
+
/** Static messaging operation name, when already known. */
|
|
21
|
+
messagingOperation?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Duration metric names accepted by {@link recordTrellisDuration}. */
|
|
24
|
+
export type TrellisDurationMetricName = "trellis.connect.duration" | "trellis.auth.flow.duration" | "trellis.auth.approval_resolution.duration" | "trellis.auth.callout.duration" | "trellis.admin.workflow.duration" | "trellis.contract.analysis.duration";
|
|
25
|
+
/** Low-cardinality attributes accepted by {@link recordTrellisDuration}. */
|
|
26
|
+
export type TrellisDurationMetricAttributes = {
|
|
27
|
+
/** Stable Trellis surface name, such as `rpc`, `jobs`, or `operations`. */
|
|
28
|
+
surface?: string;
|
|
29
|
+
/** Stable operation kind or method name. Do not pass IDs, subjects, or URLs. */
|
|
30
|
+
operation?: string;
|
|
31
|
+
/** Stable lifecycle phase such as `bootstrap`, `encode`, or `total`. */
|
|
32
|
+
phase?: string;
|
|
33
|
+
/** Stable outcome label such as `ok` or `error`. */
|
|
34
|
+
outcome?: string;
|
|
35
|
+
/** Participant kind such as `admin`, `client`, `service`, or `device`. */
|
|
36
|
+
participantKind?: string;
|
|
37
|
+
/** Session kind such as `user`, `service`, or `device`. */
|
|
38
|
+
sessionKind?: string;
|
|
39
|
+
/** Auth flow such as `local`, `oauth`, `device`, or `bootstrap`. */
|
|
40
|
+
authFlow?: string;
|
|
41
|
+
/** Auth approval outcome such as `approved`, `denied`, `required`, or `none`. */
|
|
42
|
+
authApproval?: string;
|
|
43
|
+
/** Whether a deployment authority is present. */
|
|
44
|
+
authorityPresent?: boolean;
|
|
45
|
+
/** Plan classification such as `install`, `update`, `migration`, `noop`, or `unknown`. */
|
|
46
|
+
planClassification?: string;
|
|
47
|
+
/** Contract kind such as `app`, `service`, `device`, `builtin`, or `unknown`. */
|
|
48
|
+
contractKind?: string;
|
|
49
|
+
/** Static messaging system name, when already known. */
|
|
50
|
+
messagingSystem?: string;
|
|
51
|
+
/** Static messaging operation name, when already known. */
|
|
52
|
+
messagingOperation?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Returns the shared Trellis OpenTelemetry meter. */
|
|
55
|
+
export declare function getTrellisMeter(): Meter;
|
|
56
|
+
/** Records one Trellis error with only stable, low-cardinality attributes. */
|
|
57
|
+
export declare function recordTrellisError(error: unknown, attributes?: TrellisErrorMetricAttributes): void;
|
|
58
|
+
/**
|
|
59
|
+
* Records one duration measurement on the given Trellis histogram.
|
|
60
|
+
*
|
|
61
|
+
* Converts `durationMs` to seconds. Negative, NaN, and infinite values are
|
|
62
|
+
* silently ignored.
|
|
63
|
+
*
|
|
64
|
+
* Histogram instruments are cached by metric name so `createHistogram` is
|
|
65
|
+
* called at most once per metric name.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The duration metric name.
|
|
68
|
+
* @param durationMs - The measured duration in milliseconds.
|
|
69
|
+
* @param attributes - Optional low-cardinality attributes. Only values that
|
|
70
|
+
* pass sanitization are included.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* recordTrellisDuration("trellis.connect.duration", 42.5, {
|
|
75
|
+
* phase: "nats_connect",
|
|
76
|
+
* outcome: "ok",
|
|
77
|
+
* participantKind: "client",
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function recordTrellisDuration(name: TrellisDurationMetricName, durationMs: number, attributes?: TrellisDurationMetricAttributes): void;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { metrics } from "@opentelemetry/api";
|
|
2
|
+
const TRELLIS_METER_NAME = "@oatscenter/trellis";
|
|
3
|
+
const MAX_ATTRIBUTE_LENGTH = 96;
|
|
4
|
+
const LOW_CARDINALITY_PATTERN = /^[A-Za-z0-9_.:-]+$/;
|
|
5
|
+
const UUID_PATTERN = /(^|[_.:-])[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}($|[_.:-])/i;
|
|
6
|
+
const ULID_PATTERN = /(^|[_.:-])[0-7][0-9A-HJKMNP-TV-Z]{25}($|[_.:-])/i;
|
|
7
|
+
const LONG_HEX_SEGMENT_PATTERN = /(^|[_.:-])[0-9a-f]{12,}($|[_.:-])/i;
|
|
8
|
+
const TRELLIS_SUBJECT_PREFIX_PATTERN = /^(rpc|events|feeds|operations|jobs|state|kv|store|resources|transfer)\.v\d+\./;
|
|
9
|
+
const AUTH_REASONS = new Set([
|
|
10
|
+
"invalid_request",
|
|
11
|
+
"missing_session_key",
|
|
12
|
+
"missing_proof",
|
|
13
|
+
"session_not_found",
|
|
14
|
+
"session_expired",
|
|
15
|
+
"invalid_signature",
|
|
16
|
+
"user_not_found",
|
|
17
|
+
"user_already_exists",
|
|
18
|
+
"username_taken",
|
|
19
|
+
"identity_already_exists",
|
|
20
|
+
"identity_not_found",
|
|
21
|
+
"user_inactive",
|
|
22
|
+
"unknown_device",
|
|
23
|
+
"device_deployment_not_found",
|
|
24
|
+
"device_deployment_disabled",
|
|
25
|
+
"device_activation_revoked",
|
|
26
|
+
"unknown_service",
|
|
27
|
+
"service_disabled",
|
|
28
|
+
"iat_out_of_range",
|
|
29
|
+
"invalid_binding_token",
|
|
30
|
+
"session_corrupted",
|
|
31
|
+
"session_already_bound",
|
|
32
|
+
"authtoken_already_used",
|
|
33
|
+
"oauth_session_key_mismatch",
|
|
34
|
+
"reply_subject_mismatch",
|
|
35
|
+
"insufficient_permissions",
|
|
36
|
+
"forbidden",
|
|
37
|
+
"last_admin_required",
|
|
38
|
+
"missing_flow_id",
|
|
39
|
+
"device_activation_flow_not_found",
|
|
40
|
+
"device_activation_flow_expired",
|
|
41
|
+
"device_activation_rejected",
|
|
42
|
+
"device_identity_key_mismatch",
|
|
43
|
+
"invalid_device_qr_mac",
|
|
44
|
+
]);
|
|
45
|
+
const DURATION_HISTOGRAM_CACHE = new Map();
|
|
46
|
+
/** Returns the shared Trellis OpenTelemetry meter. */
|
|
47
|
+
export function getTrellisMeter() {
|
|
48
|
+
return metrics.getMeter(TRELLIS_METER_NAME);
|
|
49
|
+
}
|
|
50
|
+
/** Records one Trellis error with only stable, low-cardinality attributes. */
|
|
51
|
+
export function recordTrellisError(error, attributes = {}) {
|
|
52
|
+
getTrellisMeter().createCounter("trellis.errors", {
|
|
53
|
+
description: "Trellis errors observed by runtime instrumentation.",
|
|
54
|
+
unit: "{error}",
|
|
55
|
+
}).add(1, buildTrellisErrorMetricAttributes(error, attributes));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Builds sanitized, low-cardinality attributes for `trellis.errors`.
|
|
59
|
+
*
|
|
60
|
+
* @internal Exported for focused tests; runtime callers should use
|
|
61
|
+
* {@link recordTrellisError}.
|
|
62
|
+
*/
|
|
63
|
+
export function buildTrellisErrorMetricAttributes(error, attributes = {}) {
|
|
64
|
+
const serializable = serializableErrorData(error);
|
|
65
|
+
const metricAttributes = {
|
|
66
|
+
"exception.type": exceptionType(error),
|
|
67
|
+
"trellis.error.type": trellisErrorType(error, serializable, attributes.errorType),
|
|
68
|
+
};
|
|
69
|
+
const remoteErrorType = lowCardinalityValue(attributes.remoteErrorType) ??
|
|
70
|
+
remoteSerializableErrorType(serializable);
|
|
71
|
+
if (remoteErrorType) {
|
|
72
|
+
metricAttributes["trellis.remote_error.type"] = remoteErrorType;
|
|
73
|
+
}
|
|
74
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.surface", attributes.surface);
|
|
75
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.direction", attributes.direction);
|
|
76
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.operation", attributes.operation);
|
|
77
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.phase", attributes.phase);
|
|
78
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.auth.reason", boundedAuthReason(attributes.authReason) ?? authReason(serializable));
|
|
79
|
+
setLowCardinalityAttribute(metricAttributes, "messaging.system", attributes.messagingSystem);
|
|
80
|
+
setLowCardinalityAttribute(metricAttributes, "messaging.operation", attributes.messagingOperation);
|
|
81
|
+
return metricAttributes;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Builds sanitized, low-cardinality attributes for duration histograms.
|
|
85
|
+
*
|
|
86
|
+
* @internal Exported for focused tests; runtime callers should use
|
|
87
|
+
* {@link recordTrellisDuration}.
|
|
88
|
+
*/
|
|
89
|
+
export function buildTrellisDurationMetricAttributes(attributes = {}) {
|
|
90
|
+
const metricAttributes = {};
|
|
91
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.surface", attributes.surface);
|
|
92
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.operation", attributes.operation);
|
|
93
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.phase", attributes.phase);
|
|
94
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.outcome", attributes.outcome);
|
|
95
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.participant.kind", attributes.participantKind);
|
|
96
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.session.kind", attributes.sessionKind);
|
|
97
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.auth.flow", attributes.authFlow);
|
|
98
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.auth.approval", attributes.authApproval);
|
|
99
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.plan.classification", attributes.planClassification);
|
|
100
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.contract.kind", attributes.contractKind);
|
|
101
|
+
setLowCardinalityAttribute(metricAttributes, "messaging.system", attributes.messagingSystem);
|
|
102
|
+
setLowCardinalityAttribute(metricAttributes, "messaging.operation", attributes.messagingOperation);
|
|
103
|
+
if (attributes.authorityPresent !== undefined) {
|
|
104
|
+
setLowCardinalityAttribute(metricAttributes, "trellis.authority.present", String(attributes.authorityPresent));
|
|
105
|
+
}
|
|
106
|
+
return metricAttributes;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Records one duration measurement on the given Trellis histogram.
|
|
110
|
+
*
|
|
111
|
+
* Converts `durationMs` to seconds. Negative, NaN, and infinite values are
|
|
112
|
+
* silently ignored.
|
|
113
|
+
*
|
|
114
|
+
* Histogram instruments are cached by metric name so `createHistogram` is
|
|
115
|
+
* called at most once per metric name.
|
|
116
|
+
*
|
|
117
|
+
* @param name - The duration metric name.
|
|
118
|
+
* @param durationMs - The measured duration in milliseconds.
|
|
119
|
+
* @param attributes - Optional low-cardinality attributes. Only values that
|
|
120
|
+
* pass sanitization are included.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* recordTrellisDuration("trellis.connect.duration", 42.5, {
|
|
125
|
+
* phase: "nats_connect",
|
|
126
|
+
* outcome: "ok",
|
|
127
|
+
* participantKind: "client",
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export function recordTrellisDuration(name, durationMs, attributes) {
|
|
132
|
+
if (typeof durationMs !== "number" ||
|
|
133
|
+
durationMs < 0 ||
|
|
134
|
+
!Number.isFinite(durationMs)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const histogram = getDurationHistogram(name);
|
|
138
|
+
const metricAttributes = buildTrellisDurationMetricAttributes(attributes);
|
|
139
|
+
histogram.record(durationMs / 1000, metricAttributes);
|
|
140
|
+
}
|
|
141
|
+
function getDurationHistogram(name) {
|
|
142
|
+
let histogram = DURATION_HISTOGRAM_CACHE.get(name);
|
|
143
|
+
if (!histogram) {
|
|
144
|
+
histogram = getTrellisMeter().createHistogram(name, {
|
|
145
|
+
description: histogramDescription(name),
|
|
146
|
+
unit: "s",
|
|
147
|
+
});
|
|
148
|
+
DURATION_HISTOGRAM_CACHE.set(name, histogram);
|
|
149
|
+
}
|
|
150
|
+
return histogram;
|
|
151
|
+
}
|
|
152
|
+
function histogramDescription(name) {
|
|
153
|
+
switch (name) {
|
|
154
|
+
case "trellis.connect.duration":
|
|
155
|
+
return "Duration of connection lifecycle phases.";
|
|
156
|
+
case "trellis.auth.flow.duration":
|
|
157
|
+
return "Duration of auth flow phases.";
|
|
158
|
+
case "trellis.auth.approval_resolution.duration":
|
|
159
|
+
return "Duration of approval resolution phases.";
|
|
160
|
+
case "trellis.auth.callout.duration":
|
|
161
|
+
return "Duration of NATS auth callout phases.";
|
|
162
|
+
case "trellis.admin.workflow.duration":
|
|
163
|
+
return "Duration of admin workflow phases.";
|
|
164
|
+
case "trellis.contract.analysis.duration":
|
|
165
|
+
return "Duration of contract analysis phases.";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function trellisErrorType(error, serializable, override) {
|
|
169
|
+
const overrideType = lowCardinalityValue(override);
|
|
170
|
+
if (overrideType)
|
|
171
|
+
return overrideType;
|
|
172
|
+
const serializableType = lowCardinalityValue(serializable?.type);
|
|
173
|
+
if (serializableType)
|
|
174
|
+
return serializableType;
|
|
175
|
+
const objectType = objectStringProperty(error, "type");
|
|
176
|
+
if (objectType)
|
|
177
|
+
return objectType;
|
|
178
|
+
return exceptionType(error);
|
|
179
|
+
}
|
|
180
|
+
function exceptionType(error) {
|
|
181
|
+
if (error instanceof Error) {
|
|
182
|
+
const name = lowCardinalityValue(error.name);
|
|
183
|
+
if (name)
|
|
184
|
+
return name;
|
|
185
|
+
}
|
|
186
|
+
const objectType = objectStringProperty(error, "type");
|
|
187
|
+
if (objectType)
|
|
188
|
+
return objectType;
|
|
189
|
+
return "unknown";
|
|
190
|
+
}
|
|
191
|
+
function serializableErrorData(error) {
|
|
192
|
+
const toSerializable = safeProperty(error, "toSerializable");
|
|
193
|
+
if (!isSerializableMethod(toSerializable))
|
|
194
|
+
return undefined;
|
|
195
|
+
try {
|
|
196
|
+
const data = toSerializable.call(error);
|
|
197
|
+
return isRecord(data) ? data : undefined;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function remoteSerializableErrorType(serializable) {
|
|
204
|
+
const remoteError = safeProperty(serializable, "remoteError");
|
|
205
|
+
if (!isRecord(remoteError))
|
|
206
|
+
return undefined;
|
|
207
|
+
return objectStringProperty(remoteError, "type");
|
|
208
|
+
}
|
|
209
|
+
function authReason(serializable) {
|
|
210
|
+
const type = safeProperty(serializable, "type");
|
|
211
|
+
if (type === "AuthError") {
|
|
212
|
+
return boundedAuthReason(safeProperty(serializable, "reason"));
|
|
213
|
+
}
|
|
214
|
+
if (type === "RemoteError") {
|
|
215
|
+
const remoteError = safeProperty(serializable, "remoteError");
|
|
216
|
+
if (isRecord(remoteError) && objectStringProperty(remoteError, "type") ===
|
|
217
|
+
"AuthError") {
|
|
218
|
+
return boundedAuthReason(safeProperty(remoteError, "reason"));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
function boundedAuthReason(value) {
|
|
224
|
+
const sanitized = lowCardinalityValue(value);
|
|
225
|
+
if (!sanitized || !AUTH_REASONS.has(sanitized))
|
|
226
|
+
return undefined;
|
|
227
|
+
return sanitized;
|
|
228
|
+
}
|
|
229
|
+
function isRecord(value) {
|
|
230
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
231
|
+
}
|
|
232
|
+
function isSerializableMethod(value) {
|
|
233
|
+
return typeof value === "function";
|
|
234
|
+
}
|
|
235
|
+
function safeProperty(value, key) {
|
|
236
|
+
if (!isRecord(value))
|
|
237
|
+
return undefined;
|
|
238
|
+
try {
|
|
239
|
+
return value[key];
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function objectStringProperty(value, key) {
|
|
246
|
+
return lowCardinalityValue(safeProperty(value, key));
|
|
247
|
+
}
|
|
248
|
+
function setLowCardinalityAttribute(attributes, key, value) {
|
|
249
|
+
const sanitized = lowCardinalityValue(value);
|
|
250
|
+
if (sanitized)
|
|
251
|
+
attributes[key] = sanitized;
|
|
252
|
+
}
|
|
253
|
+
function lowCardinalityValue(value) {
|
|
254
|
+
if (typeof value !== "string")
|
|
255
|
+
return undefined;
|
|
256
|
+
const trimmed = value.trim();
|
|
257
|
+
if (trimmed.length === 0 ||
|
|
258
|
+
trimmed.length > MAX_ATTRIBUTE_LENGTH ||
|
|
259
|
+
!LOW_CARDINALITY_PATTERN.test(trimmed) ||
|
|
260
|
+
UUID_PATTERN.test(trimmed) ||
|
|
261
|
+
ULID_PATTERN.test(trimmed) ||
|
|
262
|
+
LONG_HEX_SEGMENT_PATTERN.test(trimmed) ||
|
|
263
|
+
TRELLIS_SUBJECT_PREFIX_PATTERN.test(trimmed)) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
return trimmed;
|
|
267
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { HeaderCarrier } from "./carrier.ts";
|
|
2
|
+
export { createMapCarrier, extractTraceContext, injectTraceContext, } from "./carrier.ts";
|
|
3
|
+
export type { Context, Span } from "./core.ts";
|
|
4
|
+
export { context, getActiveSpan, getTracer, SpanKind, SpanStatusCode, trace, withSpan, withSpanAsync, } from "./core.ts";
|
|
5
|
+
export { getEnv } from "./env.ts";
|
|
6
|
+
export { initTelemetry } from "./init.ts";
|
|
7
|
+
export { buildTrellisDurationMetricAttributes, buildTrellisErrorMetricAttributes, getTrellisMeter, recordTrellisDuration, recordTrellisError, } from "./metrics.ts";
|
|
8
|
+
export type { TrellisDurationMetricAttributes, TrellisDurationMetricName, } from "./metrics.ts";
|
|
9
|
+
export type { TrellisErrorMetricAttributes } from "./metrics.ts";
|
|
10
|
+
export type { NatsHeadersLike } from "./nats.ts";
|
|
11
|
+
export { createNatsHeaderCarrier } from "./nats.ts";
|
|
12
|
+
export { configureErrorTraceId } from "./result.ts";
|
|
13
|
+
export { getTrellisTracer, startClientSpan, startServerSpan, } from "./trellis.ts";
|
package/telemetry/mod.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createMapCarrier, extractTraceContext, injectTraceContext, } from "./carrier.js";
|
|
2
|
+
export { context, getActiveSpan, getTracer, SpanKind, SpanStatusCode, trace, withSpan, withSpanAsync, } from "./core.js";
|
|
3
|
+
export { getEnv } from "./env.js";
|
|
4
|
+
export { initTelemetry } from "./init.js";
|
|
5
|
+
export { buildTrellisDurationMetricAttributes, buildTrellisErrorMetricAttributes, getTrellisMeter, recordTrellisDuration, recordTrellisError, } from "./metrics.js";
|
|
6
|
+
export { createNatsHeaderCarrier } from "./nats.js";
|
|
7
|
+
export { configureErrorTraceId } from "./result.js";
|
|
8
|
+
export { getTrellisTracer, startClientSpan, startServerSpan, } from "./trellis.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function configureErrorTraceId(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { trace } from "@opentelemetry/api";
|
|
2
|
+
import { BaseError } from "@oatscenter/result";
|
|
3
|
+
let traceIdGetterConfigured = false;
|
|
4
|
+
export function configureErrorTraceId() {
|
|
5
|
+
if (traceIdGetterConfigured)
|
|
6
|
+
return;
|
|
7
|
+
traceIdGetterConfigured = true;
|
|
8
|
+
BaseError.traceIdGetter = () => {
|
|
9
|
+
const span = trace.getActiveSpan();
|
|
10
|
+
if (!span)
|
|
11
|
+
return undefined;
|
|
12
|
+
const spanContext = span.spanContext();
|
|
13
|
+
if (spanContext.traceId === "00000000000000000000000000000000") {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return spanContext.traceId;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initTelemetryRuntime(serviceName: string): void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { metrics } from "@opentelemetry/api";
|
|
10
|
+
import { getEnv } from "./env.js";
|
|
11
|
+
let initialized = false;
|
|
12
|
+
let provider;
|
|
13
|
+
let metricProvider;
|
|
14
|
+
function runtimeImport(specifier) {
|
|
15
|
+
return import(__rewriteRelativeImportExtension(specifier));
|
|
16
|
+
}
|
|
17
|
+
async function loadTracingRuntime() {
|
|
18
|
+
const [traceNode, otlp, traceBase, resources, semantic] = await Promise.all([
|
|
19
|
+
runtimeImport(["@opentelemetry", "sdk-trace-node"].join("/")),
|
|
20
|
+
runtimeImport(["@opentelemetry", "exporter-trace-otlp-proto"].join("/")),
|
|
21
|
+
runtimeImport(["@opentelemetry", "sdk-trace-base"].join("/")),
|
|
22
|
+
runtimeImport(["@opentelemetry", "resources"].join("/")),
|
|
23
|
+
runtimeImport(["@opentelemetry", "semantic-conventions"].join("/")),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
NodeTracerProvider: traceNode.NodeTracerProvider,
|
|
27
|
+
OTLPTraceExporter: otlp.OTLPTraceExporter,
|
|
28
|
+
BatchSpanProcessor: traceBase.BatchSpanProcessor,
|
|
29
|
+
ConsoleSpanExporter: traceBase.ConsoleSpanExporter,
|
|
30
|
+
resourceFromAttributes: resources.resourceFromAttributes,
|
|
31
|
+
ATTR_SERVICE_NAME: semantic.ATTR_SERVICE_NAME,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function loadMetricsRuntime() {
|
|
35
|
+
const [sdkMetrics, otlp, resources, semantic] = await Promise.all([
|
|
36
|
+
runtimeImport(["@opentelemetry", "sdk-metrics"].join("/")),
|
|
37
|
+
runtimeImport(["@opentelemetry", "exporter-metrics-otlp-proto"].join("/")),
|
|
38
|
+
runtimeImport(["@opentelemetry", "resources"].join("/")),
|
|
39
|
+
runtimeImport(["@opentelemetry", "semantic-conventions"].join("/")),
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
MeterProvider: sdkMetrics.MeterProvider,
|
|
43
|
+
PeriodicExportingMetricReader: sdkMetrics.PeriodicExportingMetricReader,
|
|
44
|
+
ConsoleMetricExporter: sdkMetrics.ConsoleMetricExporter,
|
|
45
|
+
OTLPMetricExporter: otlp.OTLPMetricExporter,
|
|
46
|
+
resourceFromAttributes: resources.resourceFromAttributes,
|
|
47
|
+
ATTR_SERVICE_NAME: semantic.ATTR_SERVICE_NAME,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function initTracingRuntime(serviceName) {
|
|
51
|
+
const endpoint = getEnv("OTEL_EXPORTER_OTLP_ENDPOINT");
|
|
52
|
+
const consoleTracing = getEnv("OTEL_TRACES_CONSOLE") === "true";
|
|
53
|
+
if (!endpoint && !consoleTracing) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const runtime = await loadTracingRuntime();
|
|
58
|
+
const spanProcessors = [];
|
|
59
|
+
if (endpoint) {
|
|
60
|
+
spanProcessors.push(new runtime.BatchSpanProcessor(new runtime.OTLPTraceExporter({ url: `${endpoint}/v1/traces` })));
|
|
61
|
+
}
|
|
62
|
+
if (consoleTracing) {
|
|
63
|
+
spanProcessors.push(new runtime.BatchSpanProcessor(new runtime.ConsoleSpanExporter()));
|
|
64
|
+
}
|
|
65
|
+
const nextProvider = new runtime.NodeTracerProvider({
|
|
66
|
+
resource: runtime.resourceFromAttributes({
|
|
67
|
+
[runtime.ATTR_SERVICE_NAME]: serviceName,
|
|
68
|
+
}),
|
|
69
|
+
...(spanProcessors.length > 0 ? { spanProcessors } : {}),
|
|
70
|
+
});
|
|
71
|
+
provider = nextProvider;
|
|
72
|
+
nextProvider.register();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.warn("Failed to initialize tracing runtime", error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function metricEndpoint() {
|
|
79
|
+
const metricsEndpoint = getEnv("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT");
|
|
80
|
+
if (metricsEndpoint)
|
|
81
|
+
return metricsEndpoint;
|
|
82
|
+
const endpoint = getEnv("OTEL_EXPORTER_OTLP_ENDPOINT");
|
|
83
|
+
if (!endpoint)
|
|
84
|
+
return undefined;
|
|
85
|
+
return `${endpoint.replace(/\/$/, "")}/v1/metrics`;
|
|
86
|
+
}
|
|
87
|
+
function metricExportIntervalMillis() {
|
|
88
|
+
const configured = getEnv("OTEL_METRIC_EXPORT_INTERVAL");
|
|
89
|
+
if (!configured)
|
|
90
|
+
return undefined;
|
|
91
|
+
const parsed = Number(configured);
|
|
92
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
93
|
+
return undefined;
|
|
94
|
+
return Math.trunc(parsed);
|
|
95
|
+
}
|
|
96
|
+
async function initMetricsRuntime(serviceName) {
|
|
97
|
+
const endpoint = metricEndpoint();
|
|
98
|
+
const consoleMetrics = getEnv("TRELLIS_METRICS_CONSOLE") === "true";
|
|
99
|
+
if (!endpoint && !consoleMetrics) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const runtime = await loadMetricsRuntime();
|
|
104
|
+
const readers = [];
|
|
105
|
+
const exportIntervalMillis = metricExportIntervalMillis();
|
|
106
|
+
if (endpoint) {
|
|
107
|
+
readers.push(new runtime.PeriodicExportingMetricReader({
|
|
108
|
+
exporter: new runtime.OTLPMetricExporter({ url: endpoint }),
|
|
109
|
+
...(exportIntervalMillis !== undefined
|
|
110
|
+
? { exportIntervalMillis }
|
|
111
|
+
: {}),
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
if (consoleMetrics) {
|
|
115
|
+
readers.push(new runtime.PeriodicExportingMetricReader({
|
|
116
|
+
exporter: new runtime.ConsoleMetricExporter(),
|
|
117
|
+
...(exportIntervalMillis !== undefined
|
|
118
|
+
? { exportIntervalMillis }
|
|
119
|
+
: {}),
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
const nextMetricProvider = new runtime.MeterProvider({
|
|
123
|
+
resource: runtime.resourceFromAttributes({
|
|
124
|
+
[runtime.ATTR_SERVICE_NAME]: serviceName,
|
|
125
|
+
}),
|
|
126
|
+
...(readers.length > 0 ? { readers } : {}),
|
|
127
|
+
});
|
|
128
|
+
metricProvider = nextMetricProvider;
|
|
129
|
+
metrics.setGlobalMeterProvider(nextMetricProvider);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.warn("Failed to initialize metrics runtime", error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function initTelemetryRuntime(serviceName) {
|
|
136
|
+
if (initialized)
|
|
137
|
+
return;
|
|
138
|
+
initialized = true;
|
|
139
|
+
void initTracingRuntime(serviceName);
|
|
140
|
+
void initMetricsRuntime(serviceName);
|
|
141
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context, Span } from "@opentelemetry/api";
|
|
2
|
+
export declare function getTrellisTracer(): import("@opentelemetry/api").Tracer;
|
|
3
|
+
export declare function startClientSpan(method: string, subject: string): Span;
|
|
4
|
+
export declare function startServerSpan(method: string, subject: string, parentContext?: Context): Span;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SpanKind } from "@opentelemetry/api";
|
|
2
|
+
import { getTracer } from "./core.js";
|
|
3
|
+
const TRELLIS_INSTRUMENTATION_SCOPE = "@oatscenter/trellis";
|
|
4
|
+
export function getTrellisTracer() {
|
|
5
|
+
return getTracer(TRELLIS_INSTRUMENTATION_SCOPE);
|
|
6
|
+
}
|
|
7
|
+
export function startClientSpan(method, subject) {
|
|
8
|
+
return getTrellisTracer().startSpan(`rpc.client.${method}`, {
|
|
9
|
+
kind: SpanKind.CLIENT,
|
|
10
|
+
attributes: {
|
|
11
|
+
"rpc.system": "nats",
|
|
12
|
+
"rpc.method": method,
|
|
13
|
+
"messaging.destination": subject,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function startServerSpan(method, subject, parentContext) {
|
|
18
|
+
return getTrellisTracer().startSpan(`rpc.server.${method}`, {
|
|
19
|
+
kind: SpanKind.SERVER,
|
|
20
|
+
attributes: {
|
|
21
|
+
"rpc.system": "nats",
|
|
22
|
+
"rpc.method": method,
|
|
23
|
+
"messaging.destination": subject,
|
|
24
|
+
},
|
|
25
|
+
}, parentContext);
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getTrellisTracer, startClientSpan, startServerSpan } from "./trace.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getTrellisTracer, startClientSpan, startServerSpan } from "./trace.js";
|
package/telemetry.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./telemetry/mod.ts";
|
package/telemetry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./telemetry/mod.js";
|