@cloudbase/agent-observability 0.0.20 → 0.0.22

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.
@@ -1,6 +1,23 @@
1
- import {
2
- __esm
3
- } from "./chunk-NFEGQTCC.mjs";
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
4
21
 
5
22
  // src/core/constants.ts
6
23
  import {
@@ -50,6 +67,9 @@ var init_constants = __esm({
50
67
  });
51
68
 
52
69
  export {
70
+ __esm,
71
+ __export,
72
+ __toCommonJS,
53
73
  OpenInferenceSpanKind,
54
74
  OBSERVABILITY_TRACER_NAME,
55
75
  OBSERVABILITY_SDK_NAME,
@@ -57,4 +77,4 @@ export {
57
77
  OtelSpanAttributes,
58
78
  init_constants
59
79
  };
60
- //# sourceMappingURL=chunk-5EXUNUGP.mjs.map
80
+ //# sourceMappingURL=chunk-PJ5HSKYS.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/constants.ts"],"sourcesContent":["/**\n * OTEL attribute constants for observability.\n *\n * Uses OpenInference semantic conventions where applicable:\n * https://github.com/Arize-ai/openinference/tree/main/spec\n *\n * Falls back to non-standard attributes where OpenInference\n * doesn't define a standard.\n *\n * @module\n */\n\nimport {\n SemanticConventions,\n OpenInferenceSpanKind,\n} from \"@arizeai/openinference-semantic-conventions\";\n\n// Re-export OpenInference types for convenience\nexport { OpenInferenceSpanKind };\n\n/**\n * SDK information\n */\n// Brandless defaults: avoid emitting project-specific identifiers into traces.\n// Users can still override service.name via OTEL_SERVICE_NAME.\nexport const OBSERVABILITY_TRACER_NAME = \"agui-tracer\";\nexport const OBSERVABILITY_SDK_NAME = \"observability\";\nexport const OBSERVABILITY_SDK_VERSION = \"0.1.0\";\n\n/**\n * Combined attribute namespace for internal use\n * Provides a single namespace for all OTEL attributes used internally.\n *\n * Combines OpenInference SemanticConventions with non-standard attributes\n */\nexport const OtelSpanAttributes = {\n // OpenInference - re-export all standard conventions\n ...SemanticConventions,\n\n // Trace attributes (non-standard)\n TRACE_NAME: \"trace.name\",\n TRACE_TAGS: \"trace.tags\",\n TRACE_PUBLIC: \"trace.public\",\n TRACE_METADATA: \"trace.metadata\",\n TRACE_INPUT: \"trace.input\",\n TRACE_OUTPUT: \"trace.output\",\n\n // Observation attributes (non-standard)\n OBSERVATION_TYPE: \"observation.type\",\n OBSERVATION_LEVEL: \"observation.level\",\n OBSERVATION_STATUS_MESSAGE: \"observation.status_message\",\n OBSERVATION_INPUT: \"observation.input\",\n OBSERVATION_OUTPUT: \"observation.output\",\n OBSERVATION_METADATA: \"observation.metadata\",\n\n // LLM-specific (non-standard)\n LLM_COMPLETION_START_TIME: \"llm.completion_start_time\",\n LLM_MODEL_PARAMETERS: \"llm.model_parameters\",\n LLM_USAGE_DETAILS: \"llm.usage_details\",\n LLM_COST_DETAILS: \"llm.cost_details\",\n\n // Retriever-specific (non-standard)\n RETRIEVER_NAME: \"retriever.name\",\n RETRIEVER_QUERY: \"retriever.query\",\n RETRIEVER_INDEX_ID: \"retriever.index_id\",\n RETRIEVER_TOP_K: \"retriever.top_k\",\n\n // General (non-standard)\n ENVIRONMENT: \"environment\",\n RELEASE: \"release\",\n VERSION: \"version\",\n} as const;\n\n"],"mappings":";;;;;AAYA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAfP,IAyBa,2BACA,wBACA,2BAQA;AAnCb;AAAA;AAAA;AAyBO,IAAM,4BAA4B;AAClC,IAAM,yBAAyB;AAC/B,IAAM,4BAA4B;AAQlC,IAAM,qBAAqB;AAAA;AAAA,MAEhC,GAAG;AAAA;AAAA,MAGH,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,cAAc;AAAA;AAAA,MAGd,kBAAkB;AAAA,MAClB,mBAAmB;AAAA,MACnB,4BAA4B;AAAA,MAC5B,mBAAmB;AAAA,MACnB,oBAAoB;AAAA,MACpB,sBAAsB;AAAA;AAAA,MAGtB,2BAA2B;AAAA,MAC3B,sBAAsB;AAAA,MACtB,mBAAmB;AAAA,MACnB,kBAAkB;AAAA;AAAA,MAGlB,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,oBAAoB;AAAA,MACpB,iBAAiB;AAAA;AAAA,MAGjB,aAAa;AAAA,MACb,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/core/constants.ts"],"sourcesContent":["/**\n * OTEL attribute constants for observability.\n *\n * Uses OpenInference semantic conventions where applicable:\n * https://github.com/Arize-ai/openinference/tree/main/spec\n *\n * Falls back to non-standard attributes where OpenInference\n * doesn't define a standard.\n *\n * @module\n */\n\nimport {\n SemanticConventions,\n OpenInferenceSpanKind,\n} from \"@arizeai/openinference-semantic-conventions\";\n\n// Re-export OpenInference types for convenience\nexport { OpenInferenceSpanKind };\n\n/**\n * SDK information\n */\n// Brandless defaults: avoid emitting project-specific identifiers into traces.\n// Users can still override service.name via OTEL_SERVICE_NAME.\nexport const OBSERVABILITY_TRACER_NAME = \"agui-tracer\";\nexport const OBSERVABILITY_SDK_NAME = \"observability\";\nexport const OBSERVABILITY_SDK_VERSION = \"0.1.0\";\n\n/**\n * Combined attribute namespace for internal use\n * Provides a single namespace for all OTEL attributes used internally.\n *\n * Combines OpenInference SemanticConventions with non-standard attributes\n */\nexport const OtelSpanAttributes = {\n // OpenInference - re-export all standard conventions\n ...SemanticConventions,\n\n // Trace attributes (non-standard)\n TRACE_NAME: \"trace.name\",\n TRACE_TAGS: \"trace.tags\",\n TRACE_PUBLIC: \"trace.public\",\n TRACE_METADATA: \"trace.metadata\",\n TRACE_INPUT: \"trace.input\",\n TRACE_OUTPUT: \"trace.output\",\n\n // Observation attributes (non-standard)\n OBSERVATION_TYPE: \"observation.type\",\n OBSERVATION_LEVEL: \"observation.level\",\n OBSERVATION_STATUS_MESSAGE: \"observation.status_message\",\n OBSERVATION_INPUT: \"observation.input\",\n OBSERVATION_OUTPUT: \"observation.output\",\n OBSERVATION_METADATA: \"observation.metadata\",\n\n // LLM-specific (non-standard)\n LLM_COMPLETION_START_TIME: \"llm.completion_start_time\",\n LLM_MODEL_PARAMETERS: \"llm.model_parameters\",\n LLM_USAGE_DETAILS: \"llm.usage_details\",\n LLM_COST_DETAILS: \"llm.cost_details\",\n\n // Retriever-specific (non-standard)\n RETRIEVER_NAME: \"retriever.name\",\n RETRIEVER_QUERY: \"retriever.query\",\n RETRIEVER_INDEX_ID: \"retriever.index_id\",\n RETRIEVER_TOP_K: \"retriever.top_k\",\n\n // General (non-standard)\n ENVIRONMENT: \"environment\",\n RELEASE: \"release\",\n VERSION: \"version\",\n} as const;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAfP,IAyBa,2BACA,wBACA,2BAQA;AAnCb;AAAA;AAAA;AAyBO,IAAM,4BAA4B;AAClC,IAAM,yBAAyB;AAC/B,IAAM,4BAA4B;AAQlC,IAAM,qBAAqB;AAAA;AAAA,MAEhC,GAAG;AAAA;AAAA,MAGH,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,cAAc;AAAA;AAAA,MAGd,kBAAkB;AAAA,MAClB,mBAAmB;AAAA,MACnB,4BAA4B;AAAA,MAC5B,mBAAmB;AAAA,MACnB,oBAAoB;AAAA,MACpB,sBAAsB;AAAA;AAAA,MAGtB,2BAA2B;AAAA,MAC3B,sBAAsB;AAAA,MACtB,mBAAmB;AAAA,MACnB,kBAAkB;AAAA;AAAA,MAGlB,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,oBAAoB;AAAA,MACpB,iBAAiB;AAAA;AAAA,MAGjB,aAAa;AAAA,MACb,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA;AAAA;","names":[]}
@@ -3,13 +3,11 @@ import {
3
3
  OBSERVABILITY_SDK_VERSION,
4
4
  OpenInferenceSpanKind,
5
5
  OtelSpanAttributes,
6
- init_constants
7
- } from "./chunk-5EXUNUGP.mjs";
8
- import {
9
6
  __esm,
10
7
  __export,
11
- __toCommonJS
12
- } from "./chunk-NFEGQTCC.mjs";
8
+ __toCommonJS,
9
+ init_constants
10
+ } from "./chunk-PJ5HSKYS.mjs";
13
11
 
14
12
  // src/core/attributes.ts
15
13
  import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
@@ -741,7 +739,7 @@ __export(src_exports, {
741
739
  validateTraceContext: () => validateTraceContext,
742
740
  validateTraceId: () => validateTraceId
743
741
  });
744
- import { trace as trace2, context as context2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
742
+ import { trace as trace2, context as context2, SpanStatusCode as SpanStatusCode2, INVALID_SPAN_CONTEXT } from "@opentelemetry/api";
745
743
  function createOtelSpan(params) {
746
744
  return getTracer().startSpan(
747
745
  params.name,
@@ -756,63 +754,98 @@ function createParentContext(parentSpanContext) {
756
754
  if (!parentSpanContext) return;
757
755
  return trace2.setSpanContext(context2.active(), parentSpanContext);
758
756
  }
759
- function startObservation(name, attributes, options) {
760
- const { asType = "chain", ...observationOptions } = options || {};
761
- const otelSpan = createOtelSpan({
762
- name,
763
- ...observationOptions
764
- });
757
+ function createNoopSpan() {
758
+ return trace2.wrapSpanContext(INVALID_SPAN_CONTEXT);
759
+ }
760
+ function createNoopObservation(asType = "chain") {
761
+ const otelSpan = createNoopSpan();
765
762
  switch (asType) {
766
763
  case "llm":
767
- return new ObservationLLM({
768
- otelSpan,
769
- attributes
770
- });
764
+ return new ObservationLLM({ otelSpan });
771
765
  case "embedding":
772
- return new ObservationEmbedding({
773
- otelSpan,
774
- attributes
775
- });
766
+ return new ObservationEmbedding({ otelSpan });
776
767
  case "agent":
777
- return new ObservationAgent({
778
- otelSpan,
779
- attributes
780
- });
768
+ return new ObservationAgent({ otelSpan });
781
769
  case "tool":
782
- return new ObservationTool({
783
- otelSpan,
784
- attributes
785
- });
786
- case "chain":
787
- return new ObservationChain({
788
- otelSpan,
789
- attributes
790
- });
770
+ return new ObservationTool({ otelSpan });
791
771
  case "retriever":
792
- return new ObservationRetriever({
793
- otelSpan,
794
- attributes
795
- });
772
+ return new ObservationRetriever({ otelSpan });
796
773
  case "reranker":
797
- return new ObservationReranker({
798
- otelSpan,
799
- attributes
800
- });
774
+ return new ObservationReranker({ otelSpan });
801
775
  case "evaluator":
802
- return new ObservationEvaluator({
803
- otelSpan,
804
- attributes
805
- });
776
+ return new ObservationEvaluator({ otelSpan });
806
777
  case "guardrail":
807
- return new ObservationGuardrail({
808
- otelSpan,
809
- attributes
810
- });
778
+ return new ObservationGuardrail({ otelSpan });
779
+ case "chain":
811
780
  default:
812
- return new ObservationChain({
813
- otelSpan,
814
- attributes
815
- });
781
+ return new ObservationChain({ otelSpan });
782
+ }
783
+ }
784
+ function startObservation(name, attributes, options) {
785
+ const { asType = "chain", ...observationOptions } = options || {};
786
+ try {
787
+ const otelSpan = createOtelSpan({
788
+ name,
789
+ ...observationOptions
790
+ });
791
+ switch (asType) {
792
+ case "llm":
793
+ return new ObservationLLM({
794
+ otelSpan,
795
+ attributes
796
+ });
797
+ case "embedding":
798
+ return new ObservationEmbedding({
799
+ otelSpan,
800
+ attributes
801
+ });
802
+ case "agent":
803
+ return new ObservationAgent({
804
+ otelSpan,
805
+ attributes
806
+ });
807
+ case "tool":
808
+ return new ObservationTool({
809
+ otelSpan,
810
+ attributes
811
+ });
812
+ case "chain":
813
+ return new ObservationChain({
814
+ otelSpan,
815
+ attributes
816
+ });
817
+ case "retriever":
818
+ return new ObservationRetriever({
819
+ otelSpan,
820
+ attributes
821
+ });
822
+ case "reranker":
823
+ return new ObservationReranker({
824
+ otelSpan,
825
+ attributes
826
+ });
827
+ case "evaluator":
828
+ return new ObservationEvaluator({
829
+ otelSpan,
830
+ attributes
831
+ });
832
+ case "guardrail":
833
+ return new ObservationGuardrail({
834
+ otelSpan,
835
+ attributes
836
+ });
837
+ default:
838
+ return new ObservationChain({
839
+ otelSpan,
840
+ attributes
841
+ });
842
+ }
843
+ } catch (err) {
844
+ console.warn(
845
+ `[Observability] Failed to create observation "${name}":`,
846
+ err instanceof Error ? err.message : err
847
+ );
848
+ return createNoopObservation(asType);
816
849
  }
817
850
  }
818
851
  function updateActiveTrace(attributes) {
@@ -853,67 +886,81 @@ function wrapPromise(promise, span, endOnExit) {
853
886
  }
854
887
  function startActiveObservation(name, fn, options) {
855
888
  const { asType = "chain", endOnExit, ...observationOptions } = options || {};
856
- return getTracer().startActiveSpan(
857
- name,
858
- { startTime: observationOptions?.startTime },
859
- createParentContext(observationOptions?.parentSpanContext) ?? context2.active(),
860
- (span) => {
861
- try {
862
- let observation;
863
- switch (asType) {
864
- case "llm":
865
- observation = new ObservationLLM({ otelSpan: span });
866
- break;
867
- case "embedding":
868
- observation = new ObservationEmbedding({ otelSpan: span });
869
- break;
870
- case "agent":
871
- observation = new ObservationAgent({ otelSpan: span });
872
- break;
873
- case "tool":
874
- observation = new ObservationTool({ otelSpan: span });
875
- break;
876
- case "retriever":
877
- observation = new ObservationRetriever({ otelSpan: span });
878
- break;
879
- case "reranker":
880
- observation = new ObservationReranker({ otelSpan: span });
881
- break;
882
- case "evaluator":
883
- observation = new ObservationEvaluator({ otelSpan: span });
884
- break;
885
- case "guardrail":
886
- observation = new ObservationGuardrail({ otelSpan: span });
887
- break;
888
- case "chain":
889
- default:
890
- observation = new ObservationChain({ otelSpan: span });
891
- }
892
- const result = fn(observation);
893
- if (result instanceof Promise) {
894
- return wrapPromise(
895
- result,
896
- span,
897
- endOnExit
898
- );
899
- } else {
889
+ let fnCalled = false;
890
+ try {
891
+ return getTracer().startActiveSpan(
892
+ name,
893
+ { startTime: observationOptions?.startTime },
894
+ createParentContext(observationOptions?.parentSpanContext) ?? context2.active(),
895
+ (span) => {
896
+ try {
897
+ let observation;
898
+ switch (asType) {
899
+ case "llm":
900
+ observation = new ObservationLLM({ otelSpan: span });
901
+ break;
902
+ case "embedding":
903
+ observation = new ObservationEmbedding({ otelSpan: span });
904
+ break;
905
+ case "agent":
906
+ observation = new ObservationAgent({ otelSpan: span });
907
+ break;
908
+ case "tool":
909
+ observation = new ObservationTool({ otelSpan: span });
910
+ break;
911
+ case "retriever":
912
+ observation = new ObservationRetriever({ otelSpan: span });
913
+ break;
914
+ case "reranker":
915
+ observation = new ObservationReranker({ otelSpan: span });
916
+ break;
917
+ case "evaluator":
918
+ observation = new ObservationEvaluator({ otelSpan: span });
919
+ break;
920
+ case "guardrail":
921
+ observation = new ObservationGuardrail({ otelSpan: span });
922
+ break;
923
+ case "chain":
924
+ default:
925
+ observation = new ObservationChain({ otelSpan: span });
926
+ }
927
+ fnCalled = true;
928
+ const result = fn(observation);
929
+ if (result instanceof Promise) {
930
+ return wrapPromise(
931
+ result,
932
+ span,
933
+ endOnExit
934
+ );
935
+ } else {
936
+ if (endOnExit !== false) {
937
+ span.end();
938
+ }
939
+ return result;
940
+ }
941
+ } catch (err) {
942
+ span.setStatus({
943
+ code: SpanStatusCode2.ERROR,
944
+ message: err instanceof Error ? err.message : "Unknown error"
945
+ });
900
946
  if (endOnExit !== false) {
901
947
  span.end();
902
948
  }
903
- return result;
904
- }
905
- } catch (err) {
906
- span.setStatus({
907
- code: SpanStatusCode2.ERROR,
908
- message: err instanceof Error ? err.message : "Unknown error"
909
- });
910
- if (endOnExit !== false) {
911
- span.end();
949
+ throw err;
912
950
  }
913
- throw err;
914
951
  }
952
+ );
953
+ } catch (err) {
954
+ if (fnCalled) {
955
+ throw err;
915
956
  }
916
- );
957
+ console.warn(
958
+ `[Observability] startActiveObservation "${name}" failed, falling back to no-op:`,
959
+ err instanceof Error ? err.message : err
960
+ );
961
+ const noopObservation = createNoopObservation(asType);
962
+ return fn(noopObservation);
963
+ }
917
964
  }
918
965
  function updateActiveObservation(attributes) {
919
966
  const span = trace2.getActiveSpan();
@@ -939,41 +986,59 @@ function observe(fn, options = {}) {
939
986
  } = options;
940
987
  const wrappedFunction = function(...args) {
941
988
  const name = fn.name || "anonymous-function";
942
- const inputData = captureInput ? _captureArguments(args) : void 0;
943
- const observation = startObservation(
944
- name,
945
- inputData ? { input: inputData } : {},
946
- {
947
- ...observationOptions,
948
- asType
949
- }
950
- );
951
- const activeContext = trace2.setSpan(context2.active(), observation.otelSpan);
952
- const result = context2.with(activeContext, () => fn.apply(this, args));
953
- if (result instanceof Promise) {
954
- return result.then(
955
- (value) => {
956
- if (captureOutput) {
957
- observation.update({ output: value });
958
- }
959
- observation.end();
960
- return value;
961
- },
962
- (err) => {
963
- observation.update({
964
- level: "ERROR",
965
- statusMessage: err instanceof Error ? err.message : "Unknown error"
966
- });
967
- observation.end();
968
- throw err;
989
+ let observation;
990
+ let fnCalled = false;
991
+ try {
992
+ const inputData = captureInput ? _captureArguments(args) : void 0;
993
+ observation = startObservation(
994
+ name,
995
+ inputData ? { input: inputData } : {},
996
+ {
997
+ ...observationOptions,
998
+ asType
969
999
  }
970
1000
  );
1001
+ const activeContext = trace2.setSpan(context2.active(), observation.otelSpan);
1002
+ fnCalled = true;
1003
+ const result = context2.with(activeContext, () => fn.apply(this, args));
1004
+ if (result instanceof Promise) {
1005
+ return result.then(
1006
+ (value) => {
1007
+ if (captureOutput) {
1008
+ observation.update({ output: value });
1009
+ }
1010
+ observation.end();
1011
+ return value;
1012
+ },
1013
+ (err) => {
1014
+ observation.update({
1015
+ level: "ERROR",
1016
+ statusMessage: err instanceof Error ? err.message : "Unknown error"
1017
+ });
1018
+ observation.end();
1019
+ throw err;
1020
+ }
1021
+ );
1022
+ }
1023
+ if (captureOutput) {
1024
+ observation.update({ output: result });
1025
+ }
1026
+ observation.end();
1027
+ return result;
1028
+ } catch (err) {
1029
+ if (fnCalled) {
1030
+ throw err;
1031
+ }
1032
+ console.warn(
1033
+ `[Observability] observe "${name}" failed, falling back to direct call:`,
1034
+ err instanceof Error ? err.message : err
1035
+ );
1036
+ try {
1037
+ observation?.end();
1038
+ } catch {
1039
+ }
1040
+ return fn.apply(this, args);
971
1041
  }
972
- if (captureOutput) {
973
- observation.update({ output: result });
974
- }
975
- observation.end();
976
- return result;
977
1042
  };
978
1043
  Object.defineProperty(wrappedFunction, "name", { value: fn.name });
979
1044
  Object.defineProperty(wrappedFunction, "length", { value: fn.length });
@@ -1020,4 +1085,4 @@ export {
1020
1085
  observe,
1021
1086
  init_src
1022
1087
  };
1023
- //# sourceMappingURL=chunk-AHSI4KTT.mjs.map
1088
+ //# sourceMappingURL=chunk-Q5P7VQEQ.mjs.map