@cognidesk/otel 0.0.3-dev.2 → 0.0.3-dev.5
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/dist/index.js +0 -1
- package/package.json +4 -3
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cognidesk/otel",
|
|
3
|
-
"version": "0.0.3-dev.
|
|
3
|
+
"version": "0.0.3-dev.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsup src/index.ts --format esm --dts --
|
|
15
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
16
16
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
17
17
|
"test": "vitest run --passWithNoTests",
|
|
18
18
|
"lint": "tsc -p tsconfig.json --noEmit"
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"registry": "https://registry.npmjs.org/"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
|
-
"dist"
|
|
38
|
+
"dist",
|
|
39
|
+
"!dist/**/*.map"
|
|
39
40
|
],
|
|
40
41
|
"repository": {
|
|
41
42
|
"type": "git",
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import process from \"node:process\";\nimport { metrics, SpanStatusCode, trace } from \"@opentelemetry/api\";\nimport { OTLPMetricExporter } from \"@opentelemetry/exporter-metrics-otlp-proto\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-proto\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport { PeriodicExportingMetricReader } from \"@opentelemetry/sdk-metrics\";\nimport { NodeSDK } from \"@opentelemetry/sdk-node\";\n\nexport interface CognideskOtelOptions {\n serviceName: string;\n serviceVersion?: string;\n environment?: string;\n otlpEndpoint?: string;\n tracesEndpoint?: string;\n metricsEndpoint?: string;\n metricExportIntervalMillis?: number;\n resourceAttributes?: Record<string, string | number | boolean>;\n installShutdownHooks?: boolean;\n}\n\nexport interface CognideskOtelHandle {\n sdk: NodeSDK;\n shutdown(): Promise<void>;\n}\n\nexport interface CognideskDemoTelemetrySeedOptions {\n serviceName?: string;\n serviceVersion?: string;\n intervalMillis?: number;\n}\n\nexport interface CognideskDemoTelemetrySeedHandle {\n shutdown(): void;\n}\n\nexport function startCognideskOtel(options: CognideskOtelOptions): CognideskOtelHandle {\n const baseEndpoint = trimTrailingSlash(options.otlpEndpoint ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? \"http://localhost:4318\");\n const sdk = new NodeSDK({\n resource: resourceFromAttributes({\n \"service.name\": options.serviceName,\n ...(options.serviceVersion ? { \"service.version\": options.serviceVersion } : {}),\n ...(options.environment ? { \"deployment.environment.name\": options.environment } : {}),\n ...options.resourceAttributes,\n }),\n traceExporter: new OTLPTraceExporter({\n url: options.tracesEndpoint ?? process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ?? `${baseEndpoint}/v1/traces`,\n }),\n metricReader: new PeriodicExportingMetricReader({\n exporter: new OTLPMetricExporter({\n url: options.metricsEndpoint ?? process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ?? `${baseEndpoint}/v1/metrics`,\n }),\n exportIntervalMillis: options.metricExportIntervalMillis ?? 5000,\n }),\n });\n\n sdk.start();\n\n const shutdown = async () => {\n await sdk.shutdown();\n };\n\n if (options.installShutdownHooks ?? true) {\n const shutdownAndExit = (signal: NodeJS.Signals) => {\n void shutdown()\n .catch((error) => {\n console.error(\"Failed to shut down Cognidesk OpenTelemetry\", error);\n })\n .finally(() => {\n process.kill(process.pid, signal);\n });\n };\n process.once(\"SIGTERM\", shutdownAndExit);\n process.once(\"SIGINT\", shutdownAndExit);\n }\n\n return { sdk, shutdown };\n}\n\nexport function startCognideskDemoTelemetrySeed(\n options: CognideskDemoTelemetrySeedOptions = {},\n): CognideskDemoTelemetrySeedHandle {\n const serviceName = options.serviceName ?? \"cognidesk-flight-demo\";\n const serviceVersion = options.serviceVersion ?? \"0.0.0\";\n const intervalMillis = Math.max(1000, options.intervalMillis ?? 3000);\n const meter = metrics.getMeter(\"cognidesk-demo-telemetry\", serviceVersion);\n const tracer = trace.getTracer(\"cognidesk-demo-telemetry\", serviceVersion);\n const supportRequests = meter.createCounter(\"cognidesk_demo_support_requests_total\", {\n description: \"Synthetic support workload for local Studio telemetry dashboards.\",\n unit: \"{request}\",\n });\n const handoffs = meter.createCounter(\"cognidesk_demo_handoffs_total\", {\n description: \"Synthetic handoff count for local Studio telemetry dashboards.\",\n unit: \"{handoff}\",\n });\n const queueDepthByRoute = new Map<string, DemoTelemetryPoint>();\n const slaMinutesByTier = new Map<string, DemoTelemetryPoint>();\n const timeoutHandles = new Set<ReturnType<typeof setTimeout>>();\n let tick = 0;\n\n meter.createObservableGauge(\"cognidesk_demo_queue_depth\", {\n description: \"Synthetic live queue depth by route.\",\n unit: \"{conversation}\",\n }).addCallback((observable) => {\n for (const point of queueDepthByRoute.values()) {\n observable.observe(point.value, point.attributes);\n }\n });\n\n meter.createObservableGauge(\"cognidesk_demo_sla_minutes\", {\n description: \"Synthetic current SLA wait estimate by support tier.\",\n unit: \"min\",\n }).addCallback((observable) => {\n for (const point of slaMinutesByTier.values()) {\n observable.observe(point.value, point.attributes);\n }\n });\n\n function emit() {\n const route = demoTelemetryRoutes[tick % demoTelemetryRoutes.length]!;\n const requests = 2 + ((tick + route.offset) % 5);\n const escalations = (tick + route.offset) % 4 === 0 ? 1 : 0;\n const queueDepth = 3 + ((tick * 2 + route.offset) % 13);\n const slaMinutes = 4 + ((tick + route.offset * 3) % 18);\n const durationMs = 80 + ((tick * 37 + route.offset * 19) % 620);\n const attributes = {\n \"service.name\": serviceName,\n \"cognidesk.demo\": \"flight\",\n \"flight_demo.route\": route.route,\n \"flight_demo.channel\": route.channel,\n \"flight_demo.support_tier\": route.tier,\n \"flight_demo.priority\": route.priority,\n };\n\n supportRequests.add(requests, attributes);\n if (escalations) handoffs.add(escalations, attributes);\n queueDepthByRoute.set(route.route, { value: queueDepth, attributes });\n slaMinutesByTier.set(route.tier, { value: slaMinutes, attributes });\n\n const span = tracer.startSpan(\"flight_demo.synthetic.support_case\", {\n attributes: {\n ...attributes,\n \"flight_demo.synthetic_request_count\": requests,\n \"flight_demo.synthetic_queue_depth\": queueDepth,\n \"flight_demo.synthetic_sla_minutes\": slaMinutes,\n },\n });\n span.setStatus({ code: escalations ? SpanStatusCode.ERROR : SpanStatusCode.OK });\n if (escalations) {\n span.recordException(new Error(\"Synthetic handoff threshold exceeded\"));\n }\n const timeout = setTimeout(() => {\n timeoutHandles.delete(timeout);\n span.end();\n }, durationMs);\n timeoutHandles.add(timeout);\n tick += 1;\n }\n\n emit();\n const interval = setInterval(emit, intervalMillis);\n return {\n shutdown() {\n clearInterval(interval);\n for (const timeout of timeoutHandles) clearTimeout(timeout);\n timeoutHandles.clear();\n },\n };\n}\n\nfunction trimTrailingSlash(value: string) {\n return value.replace(/\\/$/, \"\");\n}\n\ntype DemoTelemetryPoint = {\n value: number;\n attributes: Record<string, string | number | boolean>;\n};\n\nconst demoTelemetryRoutes = [\n { route: \"VIE-LHR\", channel: \"chat\", tier: \"rebooking\", priority: \"high\", offset: 1 },\n { route: \"VIE-FRA\", channel: \"web\", tier: \"status\", priority: \"normal\", offset: 2 },\n { route: \"VIE-CDG\", channel: \"chat\", tier: \"baggage\", priority: \"normal\", offset: 3 },\n { route: \"VIE-AMS\", channel: \"mobile\", tier: \"booking\", priority: \"low\", offset: 4 },\n] as const;\n"],"mappings":";AAAA,OAAO,aAAa;AACpB,SAAS,SAAS,gBAAgB,aAAa;AAC/C,SAAS,0BAA0B;AACnC,SAAS,yB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