File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
js/packages/openinference-core/src Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -66,19 +66,21 @@ export function chain<
6666> ( options : TraceDecoratorOptions = { } ) {
6767 const {
6868 tracer : _tracer ,
69- name = "chain" ,
69+ name : optionsName ,
7070 processInput : _processInput ,
7171 processOutput : _processOutput ,
7272 } = options ;
7373 const tracer : OITracer = _tracer ? wrapTracer ( _tracer ) : getTracer ( ) ;
7474 const processInput = _processInput ?? defaultProcessInput ;
7575 const processOutput = _processOutput ?? defaultProcessOutput ;
7676 // TODO: infer the name from the target
77- return function ( originalMethod : Fn , _ctx : ClassMethodDecoratorContext ) {
77+ return function ( originalMethod : Fn , ctx : ClassMethodDecoratorContext ) {
78+ const methodName = String ( ctx . name ) ;
79+ const spanName = optionsName || methodName || "chain" ;
7880 const wrappedFn = function ( this : unknown , ...args : unknown [ ] ) {
7981 const input = processInput ( args ) ;
8082 return tracer . startActiveSpan (
81- name ,
83+ spanName ,
8284 {
8385 attributes : {
8486 [ OPENINFERENCE_SPAN_KIND ] : OpenInferenceSpanKind . CHAIN ,
Original file line number Diff line number Diff line change @@ -35,6 +35,20 @@ export function isObjectWithStringKeys(
3535 ) ;
3636}
3737
38+ /**
39+ * Type guard for if a function is a Promise
40+ * @param value
41+ * @returns true if it is a Promise
42+ */
43+ export function isPromise < T = unknown > ( value : unknown ) : value is Promise < T > {
44+ return (
45+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46+ ! ! value &&
47+ ( value as any ) ?. then === "function" &&
48+ ( value as any ) ?. catch === "function"
49+ ) ;
50+ }
51+
3852/**
3953 * Type guard to determine whether or not a value is an object with string keys and attribute values.
4054 * @param value
@@ -51,7 +65,7 @@ export function isAttributes(value: unknown): value is Attributes {
5165
5266/**
5367 * A type check function to ensure that a switch or set of conditionals is exhaustive.
54- * Typscript will throw an error if the switch or conditionals are not exhaustive.
68+ * Typescript will throw an error if the switch or conditionals are not exhaustive.
5569 * @example
5670 * ```typescript
5771 * type MyType = "a" | "b";
You can’t perform that action at this time.
0 commit comments