@genkit-ai/core
Version:
Genkit AI framework core libraries.
1 lines • 2.54 kB
Source Map (JSON)
{"version":3,"sources":["../../src/tracing/realtime-span-processor.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context } from '@opentelemetry/api';\nimport {\n ReadableSpan,\n Span,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\n\n/**\n * RealtimeSpanProcessor exports spans both when they start and when they end.\n * This enables real-time trace visualization in development.\n */\nexport class RealtimeSpanProcessor implements SpanProcessor {\n constructor(private readonly exporter: SpanExporter) {}\n\n /**\n * Called when a span is started. Exports immediately for real-time updates.\n */\n onStart(span: Span, _parentContext: Context): void {\n // Export the span immediately (it won't have endTime yet)\n this.exporter.export([span], () => {\n // Ignore result - we don't want to block span creation\n });\n }\n\n /**\n * Called when a span ends. Exports again with complete data.\n */\n onEnd(span: ReadableSpan): void {\n // Export the completed span\n this.exporter.export([span], () => {\n // Ignore result\n });\n }\n\n /**\n * Forces the exporter to flush any buffered spans.\n */\n async forceFlush(): Promise<void> {\n if (this.exporter.forceFlush) {\n return this.exporter.forceFlush();\n }\n }\n\n /**\n * Shuts down the processor and exporter.\n */\n async shutdown(): Promise<void> {\n return this.exporter.shutdown();\n }\n}\n"],"mappings":"AA4BO,MAAM,sBAA+C;AAAA,EAC1D,YAA6B,UAAwB;AAAxB;AAAA,EAAyB;AAAA;AAAA;AAAA;AAAA,EAKtD,QAAQ,MAAY,gBAA+B;AAEjD,SAAK,SAAS,OAAO,CAAC,IAAI,GAAG,MAAM;AAAA,IAEnC,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAA0B;AAE9B,SAAK,SAAS,OAAO,CAAC,IAAI,GAAG,MAAM;AAAA,IAEnC,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA4B;AAChC,QAAI,KAAK,SAAS,YAAY;AAC5B,aAAO,KAAK,SAAS,WAAW;AAAA,IAClC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAA0B;AAC9B,WAAO,KAAK,SAAS,SAAS;AAAA,EAChC;AACF;","names":[]}