@@ -34,6 +34,20 @@ export interface EnrichSessionParams {
3434 userProperties ?: Record < string , any > ;
3535}
3636
37+ /**
38+ * Options for tracing a function
39+ */
40+ export interface TraceFunctionOptions {
41+ /** Type of event: 'model', 'tool', or 'chain' */
42+ eventType ?: string | undefined ;
43+ /** Configuration parameters to include in the trace */
44+ config ?: Record < string , any > | undefined ;
45+ /** Metadata to include in the trace */
46+ metadata ?: Record < string , any > | undefined ;
47+ /** Custom name for the event */
48+ eventName ?: string | undefined ;
49+ }
50+
3751/**
3852 * Core properties of the HoneyHiveTracer
3953 */
@@ -706,30 +720,33 @@ export class HoneyHiveTracer {
706720 return { } ;
707721 }
708722 }
709-
710- public traceFunction ( ...args : any [ ] ) {
711- return traceFunction ( ...args , this . getTraceloopAssociationProperties ( ) ) ;
723+
724+ public traceFunction (
725+ options : TraceFunctionOptions = { }
726+ ) {
727+ const associationProps = this . getTraceloopAssociationProperties ( ) ;
728+ return traceFunction ( options , associationProps ) ;
712729 }
713730
714731 public traceModel < F extends ( ...args : any [ ] ) => any > (
715732 func : F ,
716- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
733+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
717734 ) : F {
718- return this . traceFunction ( { eventType : "model" , config , metadata , eventName } ) ( func ) ;
735+ return this . traceFunction ( { ... options , eventType : "model" } ) ( func ) ;
719736 }
720737
721738 public traceTool < F extends ( ...args : any [ ] ) => any > (
722739 func : F ,
723- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
740+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
724741 ) : F {
725- return this . traceFunction ( { eventType : "tool" , config , metadata , eventName } ) ( func ) ;
742+ return this . traceFunction ( { ... options , eventType : "tool" } ) ( func ) ;
726743 }
727744
728745 public traceChain < F extends ( ...args : any [ ] ) => any > (
729746 func : F ,
730- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
747+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
731748 ) : F {
732- return this . traceFunction ( { eventType : "chain" , config , metadata , eventName } ) ( func ) ;
749+ return this . traceFunction ( { ... options , eventType : "chain" } ) ( func ) ;
733750 }
734751
735752 public logModel ( params : EnrichSpanParams = { } ) {
@@ -989,30 +1006,31 @@ export function enrichSpan({
9891006
9901007export function traceModel < F extends ( ...args : any [ ] ) => any > (
9911008 func : F ,
992- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
1009+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
9931010) : F {
994- return traceFunction ( { eventType : "model" , config , metadata , eventName } ) ( func ) ;
1011+ return traceFunction ( { ... options , eventType : "model" } ) ( func ) ;
9951012}
9961013
9971014export function traceTool < F extends ( ...args : any [ ] ) => any > (
9981015 func : F ,
999- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
1016+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
10001017) : F {
1001- return traceFunction ( { eventType : "tool" , config , metadata , eventName } ) ( func ) ;
1018+ return traceFunction ( { ... options , eventType : "tool" } ) ( func ) ;
10021019}
10031020
10041021export function traceChain < F extends ( ...args : any [ ] ) => any > (
10051022 func : F ,
1006- { config , metadata , eventName } : { config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { }
1023+ options : Omit < TraceFunctionOptions , 'eventType' > = { }
10071024) : F {
1008- return traceFunction ( { eventType : "chain" , config , metadata , eventName } ) ( func ) ;
1025+ return traceFunction ( { ... options , eventType : "chain" } ) ( func ) ;
10091026}
10101027
10111028export function traceFunction (
1012- { eventType, config, metadata, eventName } :
1013- { eventType ?: string | undefined ; config ?: any | undefined ; metadata ?: any | undefined ; eventName ?: string | undefined } = { } ,
1029+ options : TraceFunctionOptions = { } ,
10141030 associationProperties : Record < string , string > | undefined = undefined
10151031) {
1032+ const { eventType, config, metadata, eventName } = options ;
1033+
10161034 // Helper function to extract argument names from the function
10171035 function getArgs ( func : ( ...args : any [ ] ) => any ) : string [ ] | null {
10181036 try {
0 commit comments