telemetry/logging: share the slog setup every service builds by hand
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- observability
Hướng nghiên cứu
Start with the existing telemetry/logging package and the dependent work in #359, then compare the logging implementations named in the issue: openndx-core internal/logging, nsw-srilanka internal/bootstrap/logging.go, and agency backend/internal/logging. Review openndx-core#708 for its logging rules and tests. Done means a shared setup covers the listed configuration, trace IDs, optional OTLP export with level filtering, common service attributes, and the default logger and correlation ID wiring; several design decisions and consumer migrations remain.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Current Limitation
Every OpenNSW service builds its slog setup by hand. All of them build the same chain: base handler → trace ID decorator → (optional) OTLP export → slog.SetDefault → httputil.CorrelationIDFunc. Each one does it a little differently:
openndx-core internal/logging |
nsw-srilanka internal/bootstrap/logging.go |
agency backend/internal/logging |
|
|---|---|---|---|
| Level from config | logging.level |
server.logLevel |
Not configurable |
| Format | json or text, configurable |
text only |
json only |
service / environment / version on every line |
Yes | No | No |
Trace ID decorator (trace/logging) |
No | Yes | Yes |
httputil.CorrelationIDFunc wired |
No | Yes | Yes |
OTLP log export (otelslog + slog.NewMultiHandler) |
No | Yes | No |
Level filter in front of otelslog |
— | Yes | — |
AddSource at debug |
No | Yes | No |
So:
- A combined log stream can't be filtered by service, because only one of the three adds
service, and its value isn't tied to the OTelservice.name. - Fixes stay where they were found. nsw-srilanka found that
otelslogreports every level as enabled, so behindslog.NewMultiHandlerthe multi-handler'sEnabledis true for DEBUG even when the configured level is INFO. DEBUG records were exported and debug-gated payload logging turned on. ItslevelFilterfixes this. Any other service that adds OTLP log export will hit the same bug. - Config keys and defaults differ (
logging.levelvsserver.logLevel,jsonvstext), so operators configure each service differently.
Suggested Improvement
Add the logging setup to telemetry/logging, beside the trace_id / span_id decorator from #359.
package logging // github.com/OpenNSW/core/telemetry/logging
// Config is the logging section of a service's config file.
type Config struct {
// Level is debug, info, warn or error. Default info.
Level string `yaml:"level"`
// Format is json or text. Default json.
Format string `yaml:"format"`
}
// DefaultConfig returns the values used for keys the config file leaves out.
func DefaultConfig() Config
// Validate reports an unknown level or format.
func (c Config) Validate() error
// Setup builds the logger, sets it as slog's default and returns it. cfg must be valid.
func Setup(cfg Config, p *telemetry.Provider) *slog.Logger
// NewHandler adds trace_id and span_id from the span in ctx (#359).
func NewHandler(next slog.Handler) slog.Handler
Setup builds:
slog.JSONHandlerorslog.TextHandleron stdout, atcfg.Level, withAddSourceat debugNewHandleraround it, fortrace_id/span_id- When
pexports logs over OTLP:p.SlogHandler()behind a level filter andNewHandler, fanned out withslog.NewMultiHandler service,environmentandversionattributes, taken from the same values as theProvider's resource (service.name,deployment.environment,service.version), so the log field and the OTel attribute can't driftslog.SetDefault, andhttputil.CorrelationIDFunc = telemetry.TraceID
Each main then has:
p, err := telemetry.Start(ctx, cfg.Telemetry)
// ...
logging.Setup(cfg.Logging, p)
Service-specific behavior stays in the service, such as nsw-srilanka's warning that audit records are suppressed above info.
Consumers to migrate
- openndx/openndx-core:
internal/logging(openndx/openndx-core#708) is deleted, andcmd/<service>/main.gocallslogging.Setup. - OpenNSW/nsw-srilanka:
internal/bootstrap/logging.go, includinglevelFilter.server.logLeveleither moves to aloggingsection or is mapped intologging.Configby its config code. - OpenNSW/agency:
backend/internal/logging.
Decisions to settle in review
- Default format:
json(openndx-core, agency) ortext(nsw-srilanka). Suggestjsonfor production, since log pipelines parse it. - Config key:
logging.level/logging.formatas one section, or leave each service to map its own keys intoConfig. - Is
Setupusable without telemetry? For example withp == nilit writes stdout only and adds no trace IDs. Or does every service starttelemetryfirst?
Version
github.com/OpenNSW/core/trace v0.2.0
Additional Context
- Depends on #359 for
telemetry.Provider,telemetry.TraceIDandtelemetry/logging.NewHandler. - openndx/openndx-core#708 has a description of openndx's logging rules (one setup, one global logger,
...Contextcalls, common fields). Itsinternal/loggingpackage is the starting point forConfig,Validateand the common fields.
- Ngôn ngữ chính
- Go
- Star
- 6
- Fork
- 8
- Merge trung bình
- 21 giờ 36 phút
- Pull request đã merge (30 ngày)
- 42
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenNSW/core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
payment: test fixtures hardcode real gateway names (govpay/lankapay) instead of generic placeholdersĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
nsw-sl cleanup Type/Improvement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
remote: let the host inject a logger, and log with one consistent policyCó thể đã có người làm @mushrafmim đã nhận 5 ngày trước. Đang mởType/Improvement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
agent-research-finding chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jordansmall/spindrift#7370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
☢️ Bug v3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The repo's gates check is clean and runs need no swapsCó thể đã có người làm @turbot-agent-fleet đã nhận hôm nay. Đang mởagent:ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
turbot/tailpipe#677 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-kind needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
crossplane-contrib/provider-keycloak#806 ·
Maintainer thường phản hồi trong vòng 1 ngày