@cloudbase/agent-observability 1.0.1-alpha.19 → 1.0.1-alpha.23

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.
@@ -9,9 +9,9 @@ import { SpanContext } from '@opentelemetry/api';
9
9
  import { Logger } from '@cloudbase/agent-shared';
10
10
 
11
11
  /**
12
- * LangChain Callback Handler for AG-Kit Observability
12
+ * LangChain Callback Handler for Observability
13
13
  *
14
- * Converts LangChain callback events into AG-Kit observations with OpenInference semantics.
14
+ * Converts LangChain callback events into observations with OpenInference semantics.
15
15
  */
16
16
 
17
17
  /**
@@ -49,10 +49,10 @@ type AnonymousLlmMessage = {
49
49
  additional_kwargs?: BaseMessageFields["additional_kwargs"];
50
50
  };
51
51
  /**
52
- * LangChain Callback Handler for AG-Kit Observability.
52
+ * LangChain Callback Handler for Observability.
53
53
  *
54
54
  * This handler intercepts LangChain callbacks and converts them into
55
- * AG-Kit observations following OpenInference semantic conventions.
55
+ * Observations following OpenInference semantic conventions.
56
56
  *
57
57
  * @public
58
58
  */
@@ -9,9 +9,9 @@ import { SpanContext } from '@opentelemetry/api';
9
9
  import { Logger } from '@cloudbase/agent-shared';
10
10
 
11
11
  /**
12
- * LangChain Callback Handler for AG-Kit Observability
12
+ * LangChain Callback Handler for Observability
13
13
  *
14
- * Converts LangChain callback events into AG-Kit observations with OpenInference semantics.
14
+ * Converts LangChain callback events into observations with OpenInference semantics.
15
15
  */
16
16
 
17
17
  /**
@@ -49,10 +49,10 @@ type AnonymousLlmMessage = {
49
49
  additional_kwargs?: BaseMessageFields["additional_kwargs"];
50
50
  };
51
51
  /**
52
- * LangChain Callback Handler for AG-Kit Observability.
52
+ * LangChain Callback Handler for Observability.
53
53
  *
54
54
  * This handler intercepts LangChain callbacks and converts them into
55
- * AG-Kit observations following OpenInference semantic conventions.
55
+ * Observations following OpenInference semantic conventions.
56
56
  *
57
57
  * @public
58
58
  */
package/dist/langchain.js CHANGED
@@ -21,39 +21,42 @@ var __copyProps = (to, from, except, desc) => {
21
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
22
 
23
23
  // src/core/constants.ts
24
- var import_openinference_semantic_conventions, OtelSpanAttributes;
24
+ var import_openinference_semantic_conventions, OBSERVABILITY_TRACER_NAME, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION, OtelSpanAttributes;
25
25
  var init_constants = __esm({
26
26
  "src/core/constants.ts"() {
27
27
  "use strict";
28
28
  import_openinference_semantic_conventions = require("@arizeai/openinference-semantic-conventions");
29
+ OBSERVABILITY_TRACER_NAME = "agui-tracer";
30
+ OBSERVABILITY_SDK_NAME = "observability";
31
+ OBSERVABILITY_SDK_VERSION = "0.1.0";
29
32
  OtelSpanAttributes = {
30
33
  // OpenInference - re-export all standard conventions
31
34
  ...import_openinference_semantic_conventions.SemanticConventions,
32
- // AG-Kit Trace attributes (non-standard)
35
+ // Trace attributes (non-standard)
33
36
  TRACE_NAME: "trace.name",
34
37
  TRACE_TAGS: "trace.tags",
35
38
  TRACE_PUBLIC: "trace.public",
36
39
  TRACE_METADATA: "trace.metadata",
37
40
  TRACE_INPUT: "trace.input",
38
41
  TRACE_OUTPUT: "trace.output",
39
- // AG-Kit Observation attributes (non-standard)
42
+ // Observation attributes (non-standard)
40
43
  OBSERVATION_TYPE: "observation.type",
41
44
  OBSERVATION_LEVEL: "observation.level",
42
45
  OBSERVATION_STATUS_MESSAGE: "observation.status_message",
43
46
  OBSERVATION_INPUT: "observation.input",
44
47
  OBSERVATION_OUTPUT: "observation.output",
45
48
  OBSERVATION_METADATA: "observation.metadata",
46
- // AG-Kit LLM-specific (non-standard)
49
+ // LLM-specific (non-standard)
47
50
  LLM_COMPLETION_START_TIME: "llm.completion_start_time",
48
51
  LLM_MODEL_PARAMETERS: "llm.model_parameters",
49
52
  LLM_USAGE_DETAILS: "llm.usage_details",
50
53
  LLM_COST_DETAILS: "llm.cost_details",
51
- // AG-Kit Retriever-specific (non-standard)
54
+ // Retriever-specific (non-standard)
52
55
  RETRIEVER_NAME: "retriever.name",
53
56
  RETRIEVER_QUERY: "retriever.query",
54
57
  RETRIEVER_INDEX_ID: "retriever.index_id",
55
58
  RETRIEVER_TOP_K: "retriever.top_k",
56
- // AG-Kit General (non-standard)
59
+ // General (non-standard)
57
60
  ENVIRONMENT: "environment",
58
61
  RELEASE: "release",
59
62
  VERSION: "version"
@@ -106,19 +109,20 @@ function createObservationAttributes(type, attributes) {
106
109
  modelParameters,
107
110
  usageDetails
108
111
  } = attributes;
112
+ const spanKind = import_openinference_semantic_conventions.OpenInferenceSpanKind[type.toUpperCase()] || "UNKNOWN";
109
113
  const otelAttributes = {
110
- [import_openinference_semantic_conventions2.SemanticConventions.OPENINFERENCE_SPAN_KIND]: type.toUpperCase(),
114
+ [import_openinference_semantic_conventions2.SemanticConventions.OPENINFERENCE_SPAN_KIND]: spanKind,
111
115
  [OtelSpanAttributes.OBSERVATION_TYPE]: type,
112
116
  [OtelSpanAttributes.OBSERVATION_LEVEL]: level,
113
117
  [OtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: statusMessage,
114
118
  [OtelSpanAttributes.VERSION]: version,
115
119
  // Use OpenInference input.value convention
116
120
  [import_openinference_semantic_conventions2.SemanticConventions.INPUT_VALUE]: _serialize(input),
117
- // Also set legacy agkit.observation.input for compatibility
121
+ // Also set observation.input for compatibility
118
122
  [OtelSpanAttributes.OBSERVATION_INPUT]: _serialize(input),
119
123
  // Use OpenInference output.value convention
120
124
  [import_openinference_semantic_conventions2.SemanticConventions.OUTPUT_VALUE]: _serialize(output),
121
- // Also set legacy agkit.observation.output for compatibility
125
+ // Also set observation.output for compatibility
122
126
  [OtelSpanAttributes.OBSERVATION_OUTPUT]: _serialize(output)
123
127
  };
124
128
  if (type === "llm") {
@@ -411,22 +415,22 @@ function getTracer() {
411
415
  OBSERVABILITY_SDK_VERSION
412
416
  );
413
417
  }
414
- var import_api, OBSERVABILITY_GLOBAL_SYMBOL, OBSERVABILITY_SDK_NAME, OBSERVABILITY_SDK_VERSION;
418
+ var import_api, OBSERVABILITY_GLOBAL_SYMBOL;
415
419
  var init_tracerProvider = __esm({
416
420
  "src/core/tracerProvider.ts"() {
417
421
  "use strict";
418
422
  import_api = require("@opentelemetry/api");
423
+ init_constants();
419
424
  OBSERVABILITY_GLOBAL_SYMBOL = /* @__PURE__ */ Symbol.for("observability");
420
- OBSERVABILITY_SDK_NAME = "ag-kit-observability";
421
- OBSERVABILITY_SDK_VERSION = "0.1.0";
422
425
  }
423
426
  });
424
427
 
425
428
  // src/core/spanWrapper.ts
426
- var BaseObservation, ObservationSpan, ObservationLLM, ObservationEmbedding, ObservationAgent, ObservationTool, ObservationChain, ObservationRetriever, ObservationReranker, ObservationEvaluator, ObservationGuardrail;
429
+ var import_api2, BaseObservation, ObservationSpan, ObservationLLM, ObservationEmbedding, ObservationAgent, ObservationTool, ObservationChain, ObservationRetriever, ObservationReranker, ObservationEvaluator, ObservationGuardrail;
427
430
  var init_spanWrapper = __esm({
428
431
  "src/core/spanWrapper.ts"() {
429
432
  "use strict";
433
+ import_api2 = require("@opentelemetry/api");
430
434
  init_attributes();
431
435
  init_tracerProvider();
432
436
  BaseObservation = class {
@@ -449,7 +453,7 @@ var init_spanWrapper = __esm({
449
453
  );
450
454
  }
451
455
  }
452
- /** Gets the AG-Kit OpenTelemetry tracer instance */
456
+ /** Gets the OpenTelemetry tracer instance */
453
457
  get tracer() {
454
458
  return getTracer();
455
459
  }
@@ -461,6 +465,27 @@ var init_spanWrapper = __esm({
461
465
  end(endTime) {
462
466
  this.otelSpan.end(endTime);
463
467
  }
468
+ /**
469
+ * Sets the span status.
470
+ *
471
+ * @param status - The status to set on the span
472
+ */
473
+ setStatus(status) {
474
+ this.otelSpan.setStatus(status);
475
+ }
476
+ /**
477
+ * Sets the span status to ERROR.
478
+ *
479
+ * Convenience method for marking the span as failed.
480
+ *
481
+ * @param message - Error description message
482
+ */
483
+ setErrorStatus(message) {
484
+ this.otelSpan.setStatus({
485
+ code: import_api2.SpanStatusCode.ERROR,
486
+ message
487
+ });
488
+ }
464
489
  /**
465
490
  * Updates the OTEL span attributes.
466
491
  *
@@ -587,6 +612,9 @@ var init_spanWrapper = __esm({
587
612
  // src/index.ts
588
613
  var src_exports = {};
589
614
  __export(src_exports, {
615
+ OBSERVABILITY_SDK_NAME: () => OBSERVABILITY_SDK_NAME,
616
+ OBSERVABILITY_SDK_VERSION: () => OBSERVABILITY_SDK_VERSION,
617
+ OBSERVABILITY_TRACER_NAME: () => OBSERVABILITY_TRACER_NAME,
590
618
  ObservationAgent: () => ObservationAgent,
591
619
  ObservationChain: () => ObservationChain,
592
620
  ObservationEmbedding: () => ObservationEmbedding,
@@ -619,7 +647,7 @@ function createOtelSpan(params) {
619
647
  }
620
648
  function createParentContext(parentSpanContext) {
621
649
  if (!parentSpanContext) return;
622
- return import_api2.trace.setSpanContext(import_api2.context.active(), parentSpanContext);
650
+ return import_api3.trace.setSpanContext(import_api3.context.active(), parentSpanContext);
623
651
  }
624
652
  function startObservation(name, attributes, options) {
625
653
  const { asType = "span", ...observationOptions } = options || {};
@@ -682,7 +710,7 @@ function startObservation(name, attributes, options) {
682
710
  }
683
711
  }
684
712
  function updateActiveTrace(attributes) {
685
- const span = import_api2.trace.getActiveSpan();
713
+ const span = import_api3.trace.getActiveSpan();
686
714
  if (!span) {
687
715
  console.warn(
688
716
  "[Observability] No active OTEL span in context. Skipping trace update."
@@ -692,10 +720,10 @@ function updateActiveTrace(attributes) {
692
720
  span.setAttributes(createTraceAttributes(attributes));
693
721
  }
694
722
  function getActiveTraceId() {
695
- return import_api2.trace.getActiveSpan()?.spanContext().traceId;
723
+ return import_api3.trace.getActiveSpan()?.spanContext().traceId;
696
724
  }
697
725
  function getActiveSpanId() {
698
- return import_api2.trace.getActiveSpan()?.spanContext().spanId;
726
+ return import_api3.trace.getActiveSpan()?.spanContext().spanId;
699
727
  }
700
728
  function wrapPromise(promise, span, endOnExit) {
701
729
  return promise.then(
@@ -707,7 +735,7 @@ function wrapPromise(promise, span, endOnExit) {
707
735
  },
708
736
  (err) => {
709
737
  span.setStatus({
710
- code: import_api2.SpanStatusCode.ERROR,
738
+ code: import_api3.SpanStatusCode.ERROR,
711
739
  message: err instanceof Error ? err.message : "Unknown error"
712
740
  });
713
741
  if (endOnExit !== false) {
@@ -722,7 +750,7 @@ function startActiveObservation(name, fn, options) {
722
750
  return getTracer().startActiveSpan(
723
751
  name,
724
752
  { startTime: observationOptions?.startTime },
725
- createParentContext(observationOptions?.parentSpanContext) ?? import_api2.context.active(),
753
+ createParentContext(observationOptions?.parentSpanContext) ?? import_api3.context.active(),
726
754
  (span) => {
727
755
  try {
728
756
  let observation;
@@ -773,7 +801,7 @@ function startActiveObservation(name, fn, options) {
773
801
  }
774
802
  } catch (err) {
775
803
  span.setStatus({
776
- code: import_api2.SpanStatusCode.ERROR,
804
+ code: import_api3.SpanStatusCode.ERROR,
777
805
  message: err instanceof Error ? err.message : "Unknown error"
778
806
  });
779
807
  if (endOnExit !== false) {
@@ -785,7 +813,7 @@ function startActiveObservation(name, fn, options) {
785
813
  );
786
814
  }
787
815
  function updateActiveObservation(attributes) {
788
- const span = import_api2.trace.getActiveSpan();
816
+ const span = import_api3.trace.getActiveSpan();
789
817
  if (!span) {
790
818
  console.warn(
791
819
  "[Observability] No active OTEL span in context. Skipping observation update."
@@ -817,8 +845,8 @@ function observe(fn, options = {}) {
817
845
  asType
818
846
  }
819
847
  );
820
- const activeContext = import_api2.trace.setSpan(import_api2.context.active(), observation.otelSpan);
821
- const result = import_api2.context.with(activeContext, () => fn.apply(this, args));
848
+ const activeContext = import_api3.trace.setSpan(import_api3.context.active(), observation.otelSpan);
849
+ const result = import_api3.context.with(activeContext, () => fn.apply(this, args));
822
850
  if (result instanceof Promise) {
823
851
  return result.then(
824
852
  (value) => {
@@ -848,16 +876,17 @@ function observe(fn, options = {}) {
848
876
  Object.defineProperty(wrappedFunction, "length", { value: fn.length });
849
877
  return wrappedFunction;
850
878
  }
851
- var import_api2;
879
+ var import_api3;
852
880
  var init_src = __esm({
853
881
  "src/index.ts"() {
854
882
  "use strict";
855
- import_api2 = require("@opentelemetry/api");
883
+ import_api3 = require("@opentelemetry/api");
856
884
  init_attributes();
857
885
  init_spanWrapper();
858
886
  init_tracerProvider();
859
887
  init_attributes();
860
888
  init_tracerProvider();
889
+ init_constants();
861
890
  }
862
891
  });
863
892
 
@@ -1317,11 +1346,7 @@ var CallbackHandler = class extends import_base.BaseCallbackHandler {
1317
1346
  const statusMessage = attributes.statusMessage;
1318
1347
  if (level === "ERROR") {
1319
1348
  try {
1320
- const { SpanStatusCode: SpanStatusCode2 } = require("@opentelemetry/api");
1321
- observation.otelSpan.setStatus({
1322
- code: SpanStatusCode2.ERROR,
1323
- message: statusMessage || "Unknown error"
1324
- });
1349
+ observation.setErrorStatus(statusMessage || "Unknown error");
1325
1350
  } catch (e) {
1326
1351
  this.logger.debug?.("Failed to set span error status:", e);
1327
1352
  }