Skip to content

Commit

Permalink
Merge branch 'main' into ai-data-mask-deny-word
Browse files Browse the repository at this point in the history
  • Loading branch information
007gzs authored Nov 5, 2024
2 parents 0c3c221 + 7e8b044 commit 40f54b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugins/wasm-go/pkg/wrapper/log_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ type Log struct {
}

func (l Log) log(level LogLevel, msg string) {
msg = fmt.Sprintf("[%s] %s", l.pluginName, msg)
requestIDRaw, _ := proxywasm.GetProperty([]string{"x_request_id"})
requestID := string(requestIDRaw)
if requestID == "" {
requestID = "nil"
}
msg = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, msg)
switch level {
case LogLevelTrace:
proxywasm.LogTrace(msg)
Expand All @@ -54,7 +59,12 @@ func (l Log) log(level LogLevel, msg string) {
}

func (l Log) logFormat(level LogLevel, format string, args ...interface{}) {
format = fmt.Sprintf("[%s] %s", l.pluginName, format)
requestIDRaw, _ := proxywasm.GetProperty([]string{"x_request_id"})
requestID := string(requestIDRaw)
if requestID == "" {
requestID = "nil"
}
format = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, format)
switch level {
case LogLevelTrace:
proxywasm.LogTracef(format, args...)
Expand Down
2 changes: 2 additions & 0 deletions plugins/wasm-go/pkg/wrapper/plugin_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ func (ctx *CommonHttpCtx[PluginConfig]) SetResponseBodyBufferLimit(size uint32)
}

func (ctx *CommonHttpCtx[PluginConfig]) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
requestID, _ := proxywasm.GetHttpRequestHeader("x-request-id")
_ = proxywasm.SetProperty([]string{"x_request_id"}, []byte(requestID))
config, err := ctx.plugin.GetMatchConfig()
if err != nil {
ctx.plugin.vm.log.Errorf("get match config failed, err:%v", err)
Expand Down

0 comments on commit 40f54b4

Please sign in to comment.