Skip to content

Conversation

lymboy
Copy link

@lymboy lymboy commented Sep 24, 2025

Changes

Added nil check in

  • tools/go-agent/instrument/logger/context.go
  • tools/go-agent/instrument/logger/frameworks/logrus_adapt.go

Reason for Change

Our project worked normally with Go 1.21 + go-agent v0.4.

After upgrading to Go 1.24 + go-agent v0.6, it compiled successfully but crashed with a nil panic at startup.

Investigation showed that the panic occurred because Logrus was accessed during initialization (init), while the underlying WrapFormat called GetLogContext before Logrus was fully initialized.

Full investigation details are documented on my blog: https://lymboy.com/archives/go-skywalking-agent-logrus-nil-panic

@wu-sheng wu-sheng added the enhancement New feature or request label Sep 24, 2025
Copy link

@Copilot Copilot AI left a comment

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 fixes a nil panic that occurs during application startup when using Go 1.24 and go-agent v0.6, caused by initialization order issues where Logrus components are accessed before being fully initialized.

  • Added nil checks in logger context retrieval and Logrus logger update functions
  • Protected against accessing uninitialized operator and logger instances during init execution

Reviewed Changes

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

File Description
tools/go-agent/instrument/logger/frameworks/logrus_adapt.go Added nil check for logger parameter and ChangeLogger callback
tools/go-agent/instrument/logger/context.go Added nil check for operator before accessing LogReporter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if l == nil {
return
}

Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The empty line after the return statement is unnecessary and inconsistent with the formatting of the rest of the function. Consider removing it for better code consistency.

Suggested change

Copilot uses AI. Check for mistakes.

Comment on lines 83 to 90
if operator == nil {
return nil
}
report, ok := operator.LogReporter().(LogReporter)
if !ok || report == nil {
return nil
}
return report.GetLogContext(withEndpoint)
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: line 83 uses spaces while line 82 uses tabs. The indentation should be consistent throughout the function.

Copilot uses AI. Check for mistakes.

@mrproliu
Copy link
Contributor

Thanks for your report. Please fix the CI first, then add a plugin test case to verify whether logrus and go are working correctly.

Comment on lines 24 to 30
push:
branches:
- '**'
pull_request:
branches:
- '**'
# pull_request:
Copy link
Member

Choose a reason for hiding this comment

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

This should not be added. Please run these tests locally. And PR will trigger CI automatically.

Copy link
Author

Choose a reason for hiding this comment

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

Got it, thanks! I’m testing the workflow to meet the CI requirements. I’ll create a new branch to avoid affecting this PR.

Comment on lines 25 to 36
if l == nil {
return
}

if LogTracingContextEnable {
if _, wrapperd := l.Formatter.(*WrapFormat); !wrapperd {
l.Formatter = Wrap(l.Formatter, LogTracingContextKey)
}
}
if ChangeLogger != nil {
ChangeLogger(NewLogrusAdapter(l))
}
Copy link
Member

Choose a reason for hiding this comment

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

Why these changes? It seems code style change, please revert and follow the upstream pattern.

Copy link
Author

Choose a reason for hiding this comment

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

Got it, thanks! I’m testing the workflow to meet the CI requirements. I’ll create a new branch to avoid affecting this PR.

@lymboy
Copy link
Author

lymboy commented Sep 25, 2025

image image

Just a side note: the link to the Go agent v0.6 documentation actually points to v0.5, and opening it results in a 404 Not Found. Could this be fixed?

@wu-sheng
Copy link
Member

Should be fixed by apache/skywalking-website@18edf0f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants