@@ -57,10 +57,12 @@ const (
57
57
TestModeOn = "on"
58
58
innerEventTypePrefix = "io.openfunction.function"
59
59
tracingProviderSkywalking = "skywalking"
60
+ RawData = Option ("RawData" ) // This option controls the Send() function to send raw data
60
61
)
61
62
62
63
type Runtime string
63
64
type ResourceType string
65
+ type Option string
64
66
65
67
type NativeContext interface {
66
68
// GetNativeContext returns the Go native context object.
@@ -188,6 +190,9 @@ type Context interface {
188
190
189
191
// GetInnerEvent returns the InnerEvent.
190
192
GetInnerEvent () InnerEvent
193
+
194
+ // ContextOptions returns the context's options.
195
+ ContextOptions () ContextOption
191
196
}
192
197
193
198
type Out interface {
@@ -229,6 +234,11 @@ type TracingConfig interface {
229
234
GetBaggage () map [string ]string
230
235
}
231
236
237
+ type ContextOption interface {
238
+ SetRawData (condition bool ) ContextOption
239
+ IsRawDataEnabled () bool
240
+ }
241
+
232
242
type FunctionContext struct {
233
243
mu sync.Mutex
234
244
Name string `json:"name"`
@@ -252,6 +262,7 @@ type FunctionContext struct {
252
262
podNamespace string
253
263
daprClient dapr.Client
254
264
mode string
265
+ options map [Option ]string
255
266
}
256
267
257
268
type EventRequest struct {
@@ -363,7 +374,7 @@ func (ctx *FunctionContext) Send(outputName string, data []byte) ([]byte, error)
363
374
364
375
payload = data
365
376
366
- if traceable (output .ComponentType ) {
377
+ if IsTracingProviderSkyWalking ( ctx ) && traceable (output .ComponentType ) && ! ctx . IsRawDataEnabled ( ) {
367
378
ie := NewInnerEvent (ctx )
368
379
ie .MergeMetadata (ctx .GetInnerEvent ())
369
380
ie .SetUserData (data )
@@ -607,6 +618,37 @@ func (ctx *FunctionContext) GetOut() Out {
607
618
return ctx .Out
608
619
}
609
620
621
+ func (ctx * FunctionContext ) setContextOption (key Option , value string ) {
622
+ ctx .mu .Lock ()
623
+ defer ctx .mu .Unlock ()
624
+ ctx .options [key ] = value
625
+ }
626
+
627
+ func (ctx * FunctionContext ) getContextOption (key Option ) string {
628
+ if value , ok := ctx .options [key ]; ok {
629
+ return value
630
+ } else {
631
+ return ""
632
+ }
633
+ }
634
+
635
+ func (ctx * FunctionContext ) ContextOptions () ContextOption {
636
+ return ctx
637
+ }
638
+
639
+ func (ctx * FunctionContext ) SetRawData (enable bool ) ContextOption {
640
+ ctx .setContextOption (RawData , strconv .FormatBool (enable ))
641
+ return ctx
642
+ }
643
+
644
+ func (ctx * FunctionContext ) IsRawDataEnabled () bool {
645
+ if enable , err := strconv .ParseBool (ctx .getContextOption (RawData )); err != nil {
646
+ return false
647
+ } else {
648
+ return enable
649
+ }
650
+ }
651
+
610
652
func (o * FunctionOut ) GetOut () * FunctionOut {
611
653
return o
612
654
}
@@ -810,13 +852,22 @@ func parseContext() (*FunctionContext, error) {
810
852
clientGRPCPort = port
811
853
}
812
854
855
+ // Initialize the context options
856
+ newContextOptions (ctx )
857
+
813
858
return ctx , nil
814
859
}
815
860
816
861
func NewFunctionOut () * FunctionOut {
817
862
return & FunctionOut {}
818
863
}
819
864
865
+ func newContextOptions (ctx * FunctionContext ) {
866
+ ctx .options = map [Option ]string {
867
+ RawData : "false" ,
868
+ }
869
+ }
870
+
820
871
// Convert queue binding event into cloud event format to add tracing metadata in the cloud event context.
821
872
func traceable (t string ) bool {
822
873
@@ -886,3 +937,12 @@ func ConvertUserDataToBytes(data interface{}) []byte {
886
937
return d
887
938
}
888
939
}
940
+
941
+ func IsTracingProviderSkyWalking (ctx RuntimeContext ) bool {
942
+ if ctx .HasPluginsTracingCfg () && ctx .GetPluginsTracingCfg ().IsEnabled () &&
943
+ ctx .GetPluginsTracingCfg ().ProviderName () == TracingProviderSkywalking {
944
+ return true
945
+ }
946
+
947
+ return false
948
+ }
0 commit comments