mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 09:45:27 -04:00
ca3d00229e
* use slog instead of log package and format to new log schema * update the environment name to LOG_OUTPUT_FORMAT * add the env to .env.example * fix log reference error * change the order of milldlewares * delete unused code * fix the concurrently session potential race condition * fix the log format in tests * update the duplicate code * refactor: convert log functions to slog structured format - Change log.Error/Info/Warn/Debug/Panic to accept msg + key-value pairs - Remove printf-style formatting from log functions - Update log calls in internal/cluster, internal/db, internal/core/session_manager - Remove unused 'initialized' variable from log package - Remaining files will be updated in follow-up commits 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: update all log call sites to use slog structured format Convert all log.Error, log.Info, log.Warn, log.Debug, and log.Panic calls from printf-style formatting to slog key-value pairs. Before: log.Error("failed to do something: %s", err.Error()) After: log.Error("failed to do something", "error", err) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: update cmd/ log calls to use slog structured format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: implement GnetLogger for structured logging in gnet * refactor: remove deprecated log visibility functions and related calls * feat: enhance session management with trace and identity context propagation * feat: implement serverless transaction handler and writer for plugin runtime * refactor: rename context field to traceCtx in RealBackwardsInvocation --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package debugging_runtime
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/utils/log"
|
|
)
|
|
|
|
func (r *RemotePluginRuntime) Stopped() bool {
|
|
return !r.alive
|
|
}
|
|
|
|
func (r *RemotePluginRuntime) Stop() {
|
|
r.alive = false
|
|
if r.conn == nil {
|
|
return
|
|
}
|
|
r.conn.Close()
|
|
}
|
|
|
|
func (r *RemotePluginRuntime) Type() plugin_entities.PluginRuntimeType {
|
|
return plugin_entities.PLUGIN_RUNTIME_TYPE_REMOTE
|
|
}
|
|
|
|
// spawn a core to handle CPU-intensive tasks
|
|
func (r *RemotePluginRuntime) SpawnCore() error {
|
|
var exitError error
|
|
|
|
r.response.Process(func(data []byte) {
|
|
plugin_entities.ParsePluginUniversalEvent(
|
|
data,
|
|
"",
|
|
func(session_id string, data []byte) {
|
|
r.messageCallbacksLock.RLock()
|
|
listeners := r.messageCallbacks[session_id][:]
|
|
r.messageCallbacksLock.RUnlock()
|
|
|
|
// handle session event
|
|
for _, listener := range listeners {
|
|
listener(data)
|
|
}
|
|
},
|
|
func() {
|
|
r.lastActiveAt = time.Now()
|
|
},
|
|
func(err string) {
|
|
log.Error("plugin error", "plugin", r.Configuration().Identity(), "error", err)
|
|
},
|
|
func(plugin_entities.PluginLogEvent) {}, // remote debugging logs stay on client side
|
|
)
|
|
})
|
|
|
|
return exitError
|
|
}
|
|
|
|
func (r *RemotePluginRuntime) HeartbeatMonitor() {
|
|
// close connection if it hangs for over 60 seconds
|
|
ticker := time.NewTicker(time.Second * 60)
|
|
defer ticker.Stop()
|
|
|
|
for range ticker.C {
|
|
if r.Stopped() {
|
|
return
|
|
}
|
|
|
|
if time.Since(r.lastActiveAt) > time.Second*60 {
|
|
r.Stop()
|
|
}
|
|
}
|
|
}
|
|
|
|
func (r *RemotePluginRuntime) Checksum() (string, error) {
|
|
return r.checksum, nil
|
|
}
|