Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ linters:
- path: ".*\\.pb\\.go$"
linters:
- lll
- path: '^log/slog\.go$'
linters:
- revive
text: '^(package-comments: should have a package comment|exported: exported function NewPluginLogger should have comment or be unexported)$'
- path: '^log/slog_test\.go$'
linters:
- gosec
text: '^G204: Subprocess launched with variable$'
source: '^\s*cmd := exec\.Command\(executable, "-test\.run=\^TestPluginLoggerProcess\$"\)$'
- path: '^log/slog_test\.go$'
linters:
- gosec
text: '^G204: Subprocess launched with variable$'
source: '^\s*cmd := exec\.Command\(executable, "-test\.run=\^TestReservedAttributeCollisions\$"\)$'
settings:
cyclop:
max-complexity: 8
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ API 1.1: `remote_user` owns workspaces; `user` selects the process user. API 1.2

[runtime.proto](proto/devsy/runtime/v1/runtime.proto) specifies RPCs.

## Plugin logging

Use `log.NewPluginLogger` to write structured provider diagnostics to stderr:

```go
import pluginlog "github.com/devsy-org/devsy-runtime-sdk/log"

logger := pluginlog.NewPluginLogger("example")
logger.Info("workspace started", "workspace_id", workspaceID)
```

The logger uses newline-delimited JSON with `ts`, `level`, and `msg` fields by default. It adds `component=provider` and the supplied provider name. `DEVSY_LOG_LEVEL` accepts `error`, `warn`, `info`, `debug`, or `trace`, and defaults to `info`. `DEVSY_LOG_FORMAT` accepts `json`, `text`, `plain`, `logfmt`, or `auto`. Empty and `auto` select JSON; `text`, `plain`, and `logfmt` select text. Values are case-insensitive and whitespace is not trimmed. Each invalid field independently falls back to `info` for the level or JSON for the format. The SDK emits one warning per invalid field when constructing a logger, without including the invalid value, even if the configured level would normally filter warnings. Configuration is read when each logger is constructed.

At the root, caller attributes and group names `ts`, `time`, `level`, `msg`, `message`, `component`, and `provider` receive a `user_` prefix. This also applies to attributes in inline groups. Nested named groups retain their original keys. Reserve the `user_` prefix for collision escaping to avoid duplicate keys.

The logger masks values selected from credential-like environment variable names and recognizable URL userinfo and Authorization header credentials. This applies to diagnostic messages, keys, groups, and nested values. It cannot discover every secret. Avoid logging sensitive input, and retain host-side redaction as a separate boundary. Logging a fatal severity does not terminate the process.

## Test and develop

Pass `Connect`, `Workspace`, and `Command` to `conformance.Run`. `Command` returns `*runtimev1.ExecStart` with matching `workspace_id`, `tty=false`, and nonempty argv. Map scenarios:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
)

require (
github.com/devsy-org/devsy/logging v0.0.0-20261121002232-42213a6fbc3f
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devsy-org/devsy/logging v0.0.0-20261121002232-42213a6fbc3f h1:ZEosyV/3ln3ofOJLSbzwAbS4+m/1vstAabv/I2L+lyk=
github.com/devsy-org/devsy/logging v0.0.0-20261121002232-42213a6fbc3f/go.mod h1:kpwoMhSdrhnJfTJ014ht04BLw0DS7FyF33RqIIe8CKs=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
Expand Down
39 changes: 39 additions & 0 deletions log/slog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package log

import (
"context"
"log/slog"
"os"
"time"

"github.com/devsy-org/devsy/logging"
"github.com/devsy-org/devsy/logging/redact"
)

func NewPluginLogger(providerName string) *slog.Logger {
config, invalid := logging.ResolveProvider(
os.Getenv("DEVSY_LOG_LEVEL"),
os.Getenv("DEVSY_LOG_FORMAT"),
)
handler := logging.NewHandler(os.Stderr, logging.HandlerOptions{
Level: config.Level,
Format: config.Format,
Redactor: redact.New(redact.Options{Environment: os.Environ()}),
ReservedKeys: logging.EscapeReserved,
TrustedAttrs: []slog.Attr{
slog.String("component", "provider"),
slog.String("provider", providerName),
},
})
if invalid.Level {
_ = handler.Handle(context.Background(), slog.NewRecord(
time.Now(), slog.LevelWarn, "invalid DEVSY_LOG_LEVEL; using info", 0,
))
}
if invalid.Format {
_ = handler.Handle(context.Background(), slog.NewRecord(
time.Now(), slog.LevelWarn, "invalid DEVSY_LOG_FORMAT; using json", 0,
))
}
return slog.New(handler)
}
Loading
Loading