You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide helper functions to enable easier and cleaner way to start transactions and segments.
Summary
By my experience most of the time the applications that require transactions they are quite straight forward.
Starting a transaction
Starting Segments
Ending segments
Ending transactions
Desired Behaviour
Optimally will be nice to have a way to wrap application specific functions that when invoked will start transactions and segments without coupling the application code to the agent's behavior, and without changing their underlying type.
To achieve the wrapping behavior we can use reflections, and to avoid changing the underlying type of the "wrapees" we can use generics.
Possible Solution
I can think of two solutions, the easiest one could be the addition of helper functions WrapTransactionFunc and WrapSegmentFunc, and they can be implemented like this:
funcWrapTransactionFunc[Vany](app*Application, wrapeeV, transactionNamestring, traceOptions...TraceOption) V {
typ:=reflect.TypeOf(wrapee)
iftyp.Kind() !=reflect.Func {
panic("wrapee must be a func")
}
wrappedFunc:=func(args []reflect.Value) []reflect.Value {
tx:=app.StartTransaction(transactionName, traceOptions...)
defertx.End()
returnreflect.ValueOf(wrapee).Call(args)
}
fn:=reflect.MakeFunc(typ, wrappedFunc)
returnfn.Interface().(V)
}
funcWrapSegmentFunc[Vany](tx*Transaction, wrapeeV, segmentNamestring) V {
typ:=reflect.TypeOf(wrapee)
iftyp.Kind() !=reflect.Func {
panic("wrapee must be a func")
}
wrappedFunc:=func(args []reflect.Value) []reflect.Value {
sg:=tx.StartSegment(segmentName)
defersg.End()
returnreflect.ValueOf(wrapee).Call(args)
}
fn:=reflect.MakeFunc(typ, wrappedFunc)
returnfn.Interface().(V)
}
The text was updated successfully, but these errors were encountered:
Provide helper functions to enable easier and cleaner way to start transactions and segments.
Summary
By my experience most of the time the applications that require transactions they are quite straight forward.
Desired Behaviour
Optimally will be nice to have a way to wrap application specific functions that when invoked will start transactions and segments without coupling the application code to the agent's behavior, and without changing their underlying type.
To achieve the wrapping behavior we can use reflections, and to avoid changing the underlying type of the "wrapees" we can use generics.
Possible Solution
I can think of two solutions, the easiest one could be the addition of helper functions WrapTransactionFunc and WrapSegmentFunc, and they can be implemented like this:
The text was updated successfully, but these errors were encountered: