Skip to content

instrumentation, log: add support for otel log collection.#663

Merged
kad merged 7 commits into
containers:mainfrom
klihub:devel/otel/logging
Jun 18, 2026
Merged

instrumentation, log: add support for otel log collection.#663
kad merged 7 commits into
containers:mainfrom
klihub:devel/otel/logging

Conversation

@klihub

@klihub klihub commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Note: this PR is stacked on #664.

This patch series:

  • reworks the internal logging backend using slog, adding support for structured logging
  • cleans up logging calls to consistently use the f-variants for formatted/non-structured logging
  • adds support for exporting logs to an opentelemetry compatible collector
  • adds a test case of otel log collection
  • updates documentation

Comment thread Makefile Outdated
Comment thread pkg/version/version.go
Comment thread pkg/instrumentation/logging/logging.go
@klihub klihub force-pushed the devel/otel/logging branch 10 times, most recently from 44bc753 to b164f8a Compare April 22, 2026 12:48
@klihub klihub marked this pull request as ready for review April 22, 2026 12:50
@klihub klihub force-pushed the devel/otel/logging branch from b164f8a to 4a3cd98 Compare April 23, 2026 16:21
@fmuyassarov

Copy link
Copy Markdown
Collaborator

Sorry for delay, I will go through it tomorrow.

@klihub klihub mentioned this pull request Jun 18, 2026

@kad kad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's rebase on top of current main, update deps and then it is lgtm from me.

Copilot AI left a comment

Copy link
Copy Markdown

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 refactors the internal logging subsystem to use log/slog, adds structured logging support, and introduces OpenTelemetry log exporting (OTLP) with an accompanying e2e test and documentation/CRD updates.

Changes:

  • Replace the legacy klog-based logging implementation with a slog-based backend and handlers (including an OTEL bridge handler).
  • Add OpenTelemetry log exporting support under instrumentation (OTLP HTTP/gRPC) and wire it into instrumentation startup.
  • Add an e2e test scenario + collector manifests for validating OTLP log collection; update docs and CRDs to expose new config fields.

Reviewed changes

Copilot reviewed 32 out of 34 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
test/e2e/policies.test-suite/topology-aware/n4c16/test40-otel-logging/otel-collector.yaml.in Adds an OTEL collector deployment/config for log collection in e2e.
test/e2e/policies.test-suite/topology-aware/n4c16/test40-otel-logging/custom-config.yaml.in Adds topology-aware test config enabling OTLP log export.
test/e2e/policies.test-suite/topology-aware/n4c16/test40-otel-logging/code.var.sh Adds an e2e validation script that asserts CreateContainer logs are exported.
pkg/resmgr/cache/cache.go Switches fatal logging to the formatted variant (Fatalf).
pkg/log/stdlog.go Redirects log stdlib output through the new logger and uses Debugf.
pkg/log/slog.go Introduces the new slog-backed logger implementation and text formatting handler.
pkg/log/slog-logger.go Removes the previous slog bridge implementation.
pkg/log/signal.go Removes the previous signal-based debug toggling implementation.
pkg/log/ratelimit.go Removes the previous rate-limiting logger implementation.
pkg/log/ratelimit_test.go Removes tests for the removed rate-limiter.
pkg/log/otel.go Adds an OTEL handler indirection layer to dynamically attach/detach an OTEL slog handler.
pkg/log/logger.go Defines the new Logger interface, levels, and attributes based on slog.
pkg/log/log.go Removes the legacy logging backend implementation.
pkg/log/default.go Updates the default logger initialization and flush behavior.
pkg/log/config.go Reworks logging config parsing/state and debug toggling.
pkg/instrumentation/tracing/tracing.go Updates semconv dependency version.
pkg/instrumentation/resource.go Updates semconv dependency version.
pkg/instrumentation/logging/logging.go Adds OTLP log exporting (OTEL log SDK + otelslog bridge).
pkg/instrumentation/instrumentation.go Starts logging export as part of instrumentation startup.
pkg/apis/config/v1alpha1/instrumentation/zz_generated.deepcopy.go Deep-copies the new LogExportPeriod field.
pkg/apis/config/v1alpha1/instrumentation/config.go Adds new config fields for log exporting and kubebuilder markers.
go.mod Adds OTEL log/otelslog deps and bumps OTEL + other module versions.
go.sum Updates checksums for the new/bumped dependencies.
docs/resource-policy/setup.md Documents debug config changes and OTEL log exporting setup.
deployment/helm/topology-aware/crds/config.nri_topologyawarepolicies.yaml Exposes new instrumentation log fields in helm CRD schema.
deployment/helm/template/crds/config.nri_templatepolicies.yaml Exposes new instrumentation log fields in helm CRD schema.
deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml Exposes new instrumentation log fields in helm CRD schema.
config/crd/bases/config.nri_topologyawarepolicies.yaml Exposes new instrumentation log fields in base CRD schema.
config/crd/bases/config.nri_templatepolicies.yaml Exposes new instrumentation log fields in base CRD schema.
config/crd/bases/config.nri_balloonspolicies.yaml Exposes new instrumentation log fields in base CRD schema.
cmd/plugins/topology-aware/policy/topology-aware-policy.go Updates a call site to use Infof rather than the removed Info.
cmd/plugins/topology-aware/main.go Switches Fatal to Fatalf.
cmd/plugins/template/main.go Switches Fatal to Fatalf.
cmd/plugins/balloons/main.go Switches Fatal to Fatalf.
Files not reviewed (1)
  • pkg/apis/config/v1alpha1/instrumentation/zz_generated.deepcopy.go: Generated file

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

Comment thread pkg/log/slog.go
Comment on lines +212 to +226
func (h *Handler) WithAttrs(attrs []Attr) slog.Handler {
n := &Handler{
source: h.source,
}

if h.group == nil {
n.attrs = slices.Clone(h.attrs)
n.attrs = append(n.attrs, attrs...)
} else {
n.group = h.group.Clone()
n.group.attrs = slices.Clone(attrs)
}

return n
}
Comment thread pkg/log/slog.go
Comment on lines +303 to +306
func (h *Handler) FormatAttrs(buf *bytes.Buffer, r *slog.Record) {
prefix := ""
groups := []*group{}

Comment thread pkg/log/slog.go
Comment thread pkg/log/config.go
Comment thread pkg/log/config.go
Comment thread config/crd/bases/config.nri_topologyawarepolicies.yaml
Comment thread config/crd/bases/config.nri_templatepolicies.yaml
Comment thread config/crd/bases/config.nri_balloonspolicies.yaml
Comment thread docs/resource-policy/setup.md
Comment thread docs/resource-policy/setup.md Outdated
@klihub klihub force-pushed the devel/otel/logging branch 2 times, most recently from 109858c to 33159d3 Compare June 18, 2026 12:56
uniemimu and others added 7 commits June 18, 2026 15:59
Signed-off-by: Ukri Niemimuukko <ukri.niemimuukko@intel.com>
Use log.Infof and log.Fatalf consistently everywhere for formatted
logging.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Rework internal logger implementation using slog, allowing us
to eventually move to structured logging.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Add minimal documentation about Opentelemetry-based log exporting.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub klihub force-pushed the devel/otel/logging branch from 33159d3 to c69731f Compare June 18, 2026 13:00

@askervin askervin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@askervin

Copy link
Copy Markdown
Collaborator

Let's swallow this, close #688 (included here), and sometimes later see if we could have an e2e test for this... Thanks @klihub!

@kad kad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@kad kad merged commit 417f237 into containers:main Jun 18, 2026
10 checks passed
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.

6 participants