Skip to content

Migrated to slog method signatures in service files - #40468

Merged
getvictor merged 1 commit into
mainfrom
victor/40054-slog-service
Feb 26, 2026
Merged

Migrated to slog method signatures in service files#40468
getvictor merged 1 commit into
mainfrom
victor/40054-slog-service

Conversation

@getvictor

@getvictor getvictor commented Feb 25, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #40054

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    • Changes present in previous PR

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

Release Notes

  • Refactor
    • Updated internal logging infrastructure to use context-aware logging methods throughout the system, improving context propagation for better debugging and observability while maintaining existing log coverage and behavior.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Feb 25, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates service layer files from go-kit/log to slog logging as part of the ongoing effort tracked in issue #40054. The migration converts logging method calls from the go-kit/log pattern (level.Error(logger).Log(...)) to slog's context-aware methods (logger.ErrorContext(ctx, ...)).

Changes:

  • Migrated logging calls in service files from go-kit/log to slog, converting level.{Error,Info,Debug,Warn}(logger).Log(...) patterns to logger.{Error,Info,Debug,Warn}Context(ctx, ...)
  • Updated logger adapters (NanoDEPLogger, slogAdapter) to use slog patterns with context support
  • Removed go-kit/log/level imports from files where logging has been fully migrated

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/service/users.go Migrated error logging calls to slog pattern
server/service/schedule/schedule.go Migrated all logging calls (debug, info, error) in schedule management to slog
server/service/queries.go Migrated query-related error logging to slog
server/service/orbit.go Migrated extensive logging across Orbit enrollment, disk encryption, and script/software installation flows
server/service/live_queries.go Migrated live query campaign logging to slog
server/service/hosts.go Migrated host detail and encryption key logging to slog
server/service/handler.go Updated NanoMDMLogger adapter and MDM enrollment middleware logging
server/service/devices.go Migrated fleetd error logging to slog
server/service/conditional_access_microsoft.go Migrated conditional access error logging to slog
server/service/appconfig.go Migrated app config validation logging to slog
server/mdm/apple/apple_mdm.go Updated DEP service to use new NanoDEPLogger signature with context
server/logging/nanodep.go Rewrote NanoDEPLogger adapter to use slog with context stored as field
ee/server/service/vpp.go Migrated VPP app error and warning logging to slog
ee/server/service/setup_experience.go Migrated setup experience warning logging to slog
ee/server/service/request_certificate.go Migrated certificate request error and info logging to slog
ee/server/service/in_house_apps.go Migrated in-house app error logging to slog
ee/server/service/hosts.go Migrated host wipe debug logging to slog
ee/server/service/devices.go Migrated device migration webhook debug logging to slog
ee/server/service/condaccess/log_adapter.go Renamed and rewrote adapter from kitlogAdapter to slogAdapter using slog with context
ee/server/service/condaccess/idp.go Updated IDP service to use slogAdapter instead of kitlogAdapter
ee/server/service/certificate_authorities.go Migrated certificate authority validation and batch processing logging to slog
cmd/fleet/vuln_process.go Updated vulnerability processing command logging and configureVulnPath signature
cmd/fleet/cron.go Updated cron job to pass context to configureVulnPath

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR continues the migration from go-kit/log level-based logging to context-aware slog logging. It removes the go-kit/log/level import dependency across multiple service files and replaces logging calls with context-aware logger methods (InfoContext, ErrorContext, DebugContext, WarnContext). Additionally, the PR updates logging adapters and adds context parameters to functions where needed, such as configureVulnPath, to enable context propagation through the logging chain.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is missing several required sections and details from the template, including input validation, endpoint compatibility, database migrations, and fleetd/orbit verification checklist items. Complete all checklist items in the PR description. At minimum, address the omitted sections: Changes file status, input validation/SQL safety, endpoint compatibility, testing details, database migration checks, and fleetd/orbit/Fleet Desktop verification.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of this PR - migrating service files to use slog method signatures instead of go-kit level logging.
Linked Issues check ✅ Passed The PR directly implements the objective of issue #40054 by migrating service files from go-kit level logging to slog method signatures (InfoContext, ErrorContext, DebugContext, WarnContext) across 20+ service files.
Out of Scope Changes check ✅ Passed All changes are within scope - consistently replacing go-kit logging with slog context-aware methods, removing unused go-kit imports, and updating related logging adapters (NanoDEPLogger, slogAdapter). One minor out-of-scope change involves platform logging refactoring in apple_mdm.go.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/40054-slog-service

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
ee/server/service/condaccess/log_adapter.go (1)

23-25: *ln methods should preserve line-style formatting semantics.

Line 24, Line 36, and Line 52 use fmt.Sprint(v...), which can collapse expected Println-style formatting. Consider fmt.Sprintln (trim trailing newline before logging if desired) for parity.

♻️ Proposed adjustment
 import (
 	"context"
 	"fmt"
 	"log/slog"
+	"strings"
 )
@@
 func (k *slogAdapter) Println(v ...any) {
-	k.logger.InfoContext(k.ctx, fmt.Sprint(v...))
+	k.logger.InfoContext(k.ctx, strings.TrimSuffix(fmt.Sprintln(v...), "\n"))
 }
@@
 func (k *slogAdapter) Fatalln(v ...any) {
-	k.logger.ErrorContext(k.ctx, fmt.Sprint(v...))
+	k.logger.ErrorContext(k.ctx, strings.TrimSuffix(fmt.Sprintln(v...), "\n"))
 }
@@
 func (k *slogAdapter) Panicln(v ...any) {
-	msg := fmt.Sprint(v...)
+	msg := strings.TrimSuffix(fmt.Sprintln(v...), "\n")
 	k.logger.ErrorContext(k.ctx, msg)
 	panic(msg)
 }

Also applies to: 35-37, 51-53

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ee/server/service/condaccess/log_adapter.go` around lines 23 - 25, The
Println-style methods on slogAdapter currently use fmt.Sprint(v...) which loses
the newline/spacing semantics; update each "*ln" method (e.g.,
slogAdapter.Println and the other ln-suffixed methods in the same file) to use
fmt.Sprintln(v...) and then trim the trailing newline (e.g., via
strings.TrimSuffix(..., "\n")) before passing the result into
k.logger.InfoContext/k.logger.ErrorContext so the logged message preserves
Println formatting while not including a literal trailing newline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ee/server/service/certificate_authorities.go`:
- Around line 506-507: The log message in the branch using
svc.logger.DebugContext incorrectly states "no certificate authority changes to
apply" while that branch is actually hit when dryRun is true and changes are
intentionally skipped; update the log call in the function handling batch apply
(where dryRun is checked) to a clear dry-run message such as "dry run enabled;
skipping application of certificate authority changes" (optionally include
contextual info like number of pending changes or identifiers) and keep the same
logger/context usage (svc.logger.DebugContext(ctx, ...), referencing the dryRun
variable and the surrounding batch apply logic).

In `@ee/server/service/request_certificate.go`:
- Around line 97-102: The ErrorContext calls in request_certificate.go are
logging sensitive identifiers (csr_email, csr_upn, idp_username) in
svc.logger.ErrorContext when CSR and IDP values mismatch; update the calls in
the svc.logger.ErrorContext usages (the ones referencing csrEmail, csrUsername
and introspectionResponse.Username, including the similar log at the later
occurrence around line 137) to stop emitting raw PII—either remove those
key/value pairs entirely or replace them with non-identifying placeholders
(e.g., "redacted" or a boolean/hash indicator) and keep the existing messages
and error handling (e.g., InvalidCSRError) intact so behavior is unchanged but
PII is not logged.

In `@server/service/users.go`:
- Line 136: The log call svc.logger.ErrorContext(ctx, "password not set during
admin user creation", "err", err) is logging a stale or nil err value; update
the branch in the admin user creation logic (the code path that checks for a
missing password) to either remove the "err" field from the ErrorContext call or
pass a real error value (e.g., create and use a new error like
errors.New("password not set") or wrap context with fmt.Errorf) so the logged
fields accurately reflect the failure; locate the check around the admin
creation function where svc.logger.ErrorContext is invoked and fix that single
call to avoid emitting a misleading nil/stale err.

---

Nitpick comments:
In `@ee/server/service/condaccess/log_adapter.go`:
- Around line 23-25: The Println-style methods on slogAdapter currently use
fmt.Sprint(v...) which loses the newline/spacing semantics; update each "*ln"
method (e.g., slogAdapter.Println and the other ln-suffixed methods in the same
file) to use fmt.Sprintln(v...) and then trim the trailing newline (e.g., via
strings.TrimSuffix(..., "\n")) before passing the result into
k.logger.InfoContext/k.logger.ErrorContext so the logged message preserves
Println formatting while not including a literal trailing newline.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c14bea4 and 26ef943.

📒 Files selected for processing (23)
  • cmd/fleet/cron.go
  • cmd/fleet/vuln_process.go
  • ee/server/service/certificate_authorities.go
  • ee/server/service/condaccess/idp.go
  • ee/server/service/condaccess/log_adapter.go
  • ee/server/service/devices.go
  • ee/server/service/hosts.go
  • ee/server/service/in_house_apps.go
  • ee/server/service/request_certificate.go
  • ee/server/service/setup_experience.go
  • ee/server/service/vpp.go
  • server/logging/nanodep.go
  • server/mdm/apple/apple_mdm.go
  • server/service/appconfig.go
  • server/service/conditional_access_microsoft.go
  • server/service/devices.go
  • server/service/handler.go
  • server/service/hosts.go
  • server/service/live_queries.go
  • server/service/orbit.go
  • server/service/queries.go
  • server/service/schedule/schedule.go
  • server/service/users.go

Comment thread ee/server/service/certificate_authorities.go
Comment thread ee/server/service/request_certificate.go
Comment thread server/service/users.go
@codecov

codecov Bot commented Feb 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.28571% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.26%. Comparing base (c14bea4) to head (26ef943).
⚠️ Report is 64 commits behind head on main.

Files with missing lines Patch % Lines
server/service/orbit.go 36.84% 24 Missing ⚠️
ee/server/service/condaccess/log_adapter.go 11.11% 16 Missing ⚠️
server/service/schedule/schedule.go 68.75% 10 Missing ⚠️
cmd/fleet/vuln_process.go 16.66% 5 Missing ⚠️
server/service/handler.go 44.44% 5 Missing ⚠️
server/service/live_queries.go 16.66% 5 Missing ⚠️
server/service/queries.go 0.00% 5 Missing ⚠️
ee/server/service/certificate_authorities.go 80.00% 4 Missing ⚠️
ee/server/service/request_certificate.go 77.77% 2 Missing ⚠️
ee/server/service/vpp.go 0.00% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #40468      +/-   ##
==========================================
- Coverage   66.27%   66.26%   -0.01%     
==========================================
  Files        2461     2461              
  Lines      197390   197385       -5     
  Branches     8716     8716              
==========================================
- Hits       130811   130799      -12     
- Misses      54739    54744       +5     
- Partials    11840    11842       +2     
Flag Coverage Δ
backend 68.14% <50.28%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@getvictor
getvictor marked this pull request as ready for review February 25, 2026 19:27
@getvictor
getvictor requested a review from a team as a code owner February 25, 2026 19:27
Comment thread server/service/handler.go

func (l *NanoMDMLogger) Info(keyvals ...interface{}) {
level.Info(l.logger).Log(keyvals...)
l.logger.InfoContext(context.TODO(), "", keyvals...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL context.TODO()

@getvictor
getvictor merged commit ae0ea39 into main Feb 26, 2026
52 checks passed
@getvictor
getvictor deleted the victor/40054-slog-service branch February 26, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slog migration (2)

3 participants