Files
Byron.wang ca3d00229e Feat/Implement structured logging and Trace ID propagation (#552)
* 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>
2025-12-30 11:00:48 +08:00

93 lines
2.8 KiB
Go

package main
import (
"os"
"strings"
"github.com/langgenius/dify-plugin-daemon/cmd/commandline/signature"
"github.com/langgenius/dify-plugin-daemon/pkg/plugin_packager/decoder"
"github.com/langgenius/dify-plugin-daemon/pkg/utils/log"
"github.com/spf13/cobra"
)
var (
signatureGenerateCommand = &cobra.Command{
Use: "generate",
Short: "Generate a key pair",
Long: "Generate a key pair",
Args: cobra.ExactArgs(0),
Run: func(c *cobra.Command, args []string) {
keyPairName := c.Flag("filename").Value.String()
if keyPairName == "" {
keyPairName = "dify_plugin_signing_key"
}
err := signature.GenerateKeyPair(keyPairName)
if err != nil {
os.Exit(1)
}
},
}
signatureSignCommand = &cobra.Command{
Use: "sign [difypkg_path]",
Short: "Sign a difypkg file",
Long: "Sign a difypkg file with the specified private key",
Args: cobra.ExactArgs(1),
Run: func(c *cobra.Command, args []string) {
difypkgPath := args[0]
privateKeyPath := c.Flag("private_key").Value.String()
authorizedCategory := c.Flag("authorized_category").Value.String()
if authorizedCategory != "" {
if !strings.EqualFold(authorizedCategory, string(decoder.AUTHORIZED_CATEGORY_LANGGENIUS)) &&
!strings.EqualFold(authorizedCategory, string(decoder.AUTHORIZED_CATEGORY_PARTNER)) &&
!strings.EqualFold(authorizedCategory, string(decoder.AUTHORIZED_CATEGORY_COMMUNITY)) {
log.Error("invalid authorized category", "category", authorizedCategory)
os.Exit(1)
}
}
err := signature.Sign(difypkgPath, privateKeyPath, &decoder.Verification{
AuthorizedCategory: decoder.AuthorizedCategory(authorizedCategory),
})
if err != nil {
os.Exit(1)
}
},
}
signatureVerifyCommand = &cobra.Command{
Use: "verify [difypkg_path]",
Short: "Verify a difypkg file",
Long: "Verify a difypkg file with the specified public key. If no public key is provided, the official public key will be used",
Args: cobra.ExactArgs(1),
Run: func(c *cobra.Command, args []string) {
difypkgPath := args[0]
publicKeyPath := c.Flag("public_key").Value.String()
err := signature.Verify(difypkgPath, publicKeyPath)
if err != nil {
os.Exit(1)
}
},
}
)
func init() {
signatureCommand.AddCommand(signatureGenerateCommand)
signatureCommand.AddCommand(signatureSignCommand)
signatureCommand.AddCommand(signatureVerifyCommand)
signatureGenerateCommand.Flags().StringP("filename", "f", "", "filename of the key pair")
signatureSignCommand.Flags().StringP("private_key", "p", "", "private key file")
signatureSignCommand.MarkFlagRequired("private_key")
signatureSignCommand.Flags().StringP(
"authorized_category",
"c",
string(decoder.AUTHORIZED_CATEGORY_LANGGENIUS),
"authorized category",
)
signatureVerifyCommand.Flags().StringP("public_key", "p", "", "public key file")
}