Skip to content

Conversation

@rogercoll
Copy link
Contributor

@rogercoll rogercoll commented Oct 24, 2025

Adds a new internal package to initialize a global slog logger instance: internal/global/logging.go.

It can be overridden anytime, like when used as a collector receiver, which uses a zap adapter.

The global package provides some adapter functions for minimal changes in the codebase (non-structured logging), we should aim (follow-up PR/issue) to gradually move to a structured logging strategy to benefit from slog.

This changes aligns the formatting when running with the OTel collector:

2025-10-24T12:50:28.987+0200    info    builders/builders.go:26 Development component. May change in the future.        {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "debug", "otelcol.component.kind": "exporter", "otelcol.signal": "profiles"}
2025-10-24T12:50:28.989+0200    info    [email protected]/service.go:211 Starting otelcol-ebpf-profiler...       {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "Version": "0.137.0", "NumCPU": 20}
2025-10-24T12:50:28.989+0200    info    extensions/extensions.go:41     Starting extensions...  {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}}
2025-10-24T12:50:28.989+0200    info    Interpreter tracers: perl,php,python,hotspot,ruby,v8,dotnet,go,labels   {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.392+0200    info    Found offsets: task stack 0x20, pt_regs 0x3f48, tpbase 0x1640   {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.647+0200    info    Supports generic eBPF map batch operations      {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.647+0200    info    Supports LPM trie eBPF map batch operations     {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.648+0200    info    eBPF tracer loaded      {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.671+0200    info    Attached tracer program {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "otelcol.component.id": "profiling", "otelcol.component.kind": "receiver", "otelcol.signal": "profiles"}
2025-10-24T12:50:29.693+0200    info    [email protected]/service.go:234 Everything is ready. Begin running and processing data. {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}}
^C2025-10-24T12:50:32.118+0200  info    [email protected]/collector.go:358       Received signal from OS {"resource": {"service.instance.id": "41dcefbf-4790-44e8-9d37-788b20df323a", "service.name": "otelcol-ebpf-profiler", "service.version": "0.137.0"}, "signal": "interrupt"}

Fixes #417

@rogercoll rogercoll marked this pull request as ready for review October 24, 2025 10:57
@rogercoll rogercoll requested review from a team as code owners October 24, 2025 10:57
globalLogger.Store(&l)
}

// SetDebugLogger configures the global logger to write debug-level logs to stderr.
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of SetDebugLogger an API should be provided to set the log level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The slog Handler does not provide any mechanism to change the log level in runtime, a new logger needs to be created instead. Any suggestion on the naming?

Also, keep in mind that this will be removed once we transition to just having the otel receiver (verbosity will be defined from the collector's configuration)

Copy link
Contributor

Choose a reason for hiding this comment

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

In the example provided with slog.SetLogLoggerLevel, changing the severity level after setting the logger just works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That function only works in case we were using the default slog.Logger instance, in this case we created a new non default logger.

rogercoll and others added 2 commits October 30, 2025 15:18
@rogercoll
Copy link
Contributor Author

@open-telemetry/ebpf-profiler-maintainers Anything left to be addressed?

@christos68k christos68k merged commit 5443dd2 into open-telemetry:main Nov 4, 2025
26 checks passed
@rogercoll rogercoll deleted the set_global_logger branch November 4, 2025 15:57
Comment on lines -168 to +169
lowAddress, highAddress, mapBase libpf.Address, stubTypeOrHdrMap uint64) {
lowAddress, highAddress, mapBase libpf.Address, stubTypeOrHdrMap uint64,
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR has a ton of these unrelated stylistic changes. This makes rebasing other PRs really painful.
Please stop changing code unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. Would it be fine for you if I create a specific PR to format all the Go code? Something like what we did in OpAMP-go and all other OpenTelemetry Go projects: open-telemetry/opamp-go#356

Most IDEs or editors configurations auto-format on save.

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.

Improve logging in the codebase

4 participants