From 28589cacdc0e53efab151a74f54349e696e3d50c Mon Sep 17 00:00:00 2001 From: liuyuming Date: Wed, 24 Sep 2025 20:58:16 +0800 Subject: [PATCH 1/4] Add nil check to prevent panic during init execution --- tools/go-agent/instrument/logger/context.go | 15 +++++++++------ .../logger/frameworks/logrus_adapt.go | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/go-agent/instrument/logger/context.go b/tools/go-agent/instrument/logger/context.go index 10072acc..9405de53 100644 --- a/tools/go-agent/instrument/logger/context.go +++ b/tools/go-agent/instrument/logger/context.go @@ -79,12 +79,15 @@ func (span *NoopSpan) GetEndPointName() string { } func GetLogContext(withEndpoint bool) interface{} { - report, ok := GetOperator().LogReporter().(LogReporter) - if !ok || report == nil { - return nil - } - - return report.GetLogContext(withEndpoint) + operator := GetOperator() + if operator == nil { + return nil + } + report, ok := operator.LogReporter().(LogReporter) + if !ok || report == nil { + return nil + } + return report.GetLogContext(withEndpoint) } func GetLogContextString() string { diff --git a/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go b/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go index f57b0b3a..fb2f2c15 100644 --- a/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go +++ b/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go @@ -22,12 +22,18 @@ import ( ) func UpdateLogrusLogger(l *logrus.Logger) { - if LogTracingContextEnable { - if _, wrapperd := l.Formatter.(*WrapFormat); !wrapperd { - l.Formatter = Wrap(l.Formatter, LogTracingContextKey) - } - } - ChangeLogger(NewLogrusAdapter(l)) + if l == nil { + return + } + + if LogTracingContextEnable { + if _, wrapperd := l.Formatter.(*WrapFormat); !wrapperd { + l.Formatter = Wrap(l.Formatter, LogTracingContextKey) + } + } + if ChangeLogger != nil { + ChangeLogger(NewLogrusAdapter(l)) + } } type LogrusAdapter struct { From f7344727bdb7a719e14d73be5d0f3a5eaaa3286e Mon Sep 17 00:00:00 2001 From: liuyuming Date: Thu, 25 Sep 2025 10:18:13 +0800 Subject: [PATCH 2/4] test: test workflow --- .github/workflows/plugin-tests.yaml | 6 +++++ tools/go-agent/instrument/logger/context.go | 16 ++++++------- .../logger/frameworks/logrus_adapt.go | 24 +++++++++---------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/plugin-tests.yaml b/.github/workflows/plugin-tests.yaml index 58d3833f..6d00b707 100644 --- a/.github/workflows/plugin-tests.yaml +++ b/.github/workflows/plugin-tests.yaml @@ -21,7 +21,13 @@ concurrency: cancel-in-progress: true on: + push: + branches: + - '**' pull_request: + branches: + - '**' +# pull_request: jobs: build: diff --git a/tools/go-agent/instrument/logger/context.go b/tools/go-agent/instrument/logger/context.go index 9405de53..debdf4b5 100644 --- a/tools/go-agent/instrument/logger/context.go +++ b/tools/go-agent/instrument/logger/context.go @@ -80,14 +80,14 @@ func (span *NoopSpan) GetEndPointName() string { func GetLogContext(withEndpoint bool) interface{} { operator := GetOperator() - if operator == nil { - return nil - } - report, ok := operator.LogReporter().(LogReporter) - if !ok || report == nil { - return nil - } - return report.GetLogContext(withEndpoint) + if operator == nil { + return nil + } + report, ok := operator.LogReporter().(LogReporter) + if !ok || report == nil { + return nil + } + return report.GetLogContext(withEndpoint) } func GetLogContextString() string { diff --git a/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go b/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go index fb2f2c15..da473c5a 100644 --- a/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go +++ b/tools/go-agent/instrument/logger/frameworks/logrus_adapt.go @@ -22,18 +22,18 @@ import ( ) func UpdateLogrusLogger(l *logrus.Logger) { - if l == nil { - return - } - - if LogTracingContextEnable { - if _, wrapperd := l.Formatter.(*WrapFormat); !wrapperd { - l.Formatter = Wrap(l.Formatter, LogTracingContextKey) - } - } - if ChangeLogger != nil { - ChangeLogger(NewLogrusAdapter(l)) - } + if l == nil { + return + } + + if LogTracingContextEnable { + if _, wrapperd := l.Formatter.(*WrapFormat); !wrapperd { + l.Formatter = Wrap(l.Formatter, LogTracingContextKey) + } + } + if ChangeLogger != nil { + ChangeLogger(NewLogrusAdapter(l)) + } } type LogrusAdapter struct { From fa3c48eeb72f301b383cfae415fdcc93c4a42032 Mon Sep 17 00:00:00 2001 From: liuyuming Date: Thu, 25 Sep 2025 10:19:30 +0800 Subject: [PATCH 3/4] test: test workflow --- .github/workflows/skywalking-go.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/skywalking-go.yaml b/.github/workflows/skywalking-go.yaml index 1a29fe0a..f7fb8fb5 100644 --- a/.github/workflows/skywalking-go.yaml +++ b/.github/workflows/skywalking-go.yaml @@ -17,7 +17,12 @@ name: CI on: + push: + branches: + - '**' pull_request: + branches: + - '**' jobs: tests: From 65db3de5664f47018191372cabe3c21de986abf6 Mon Sep 17 00:00:00 2001 From: liuyuming Date: Thu, 25 Sep 2025 11:03:19 +0800 Subject: [PATCH 4/4] test: test workflow --- .github/workflows/plugin-tests.yaml | 6 ------ .github/workflows/skywalking-go.yaml | 5 ----- 2 files changed, 11 deletions(-) diff --git a/.github/workflows/plugin-tests.yaml b/.github/workflows/plugin-tests.yaml index 6d00b707..58d3833f 100644 --- a/.github/workflows/plugin-tests.yaml +++ b/.github/workflows/plugin-tests.yaml @@ -21,13 +21,7 @@ concurrency: cancel-in-progress: true on: - push: - branches: - - '**' pull_request: - branches: - - '**' -# pull_request: jobs: build: diff --git a/.github/workflows/skywalking-go.yaml b/.github/workflows/skywalking-go.yaml index f7fb8fb5..1a29fe0a 100644 --- a/.github/workflows/skywalking-go.yaml +++ b/.github/workflows/skywalking-go.yaml @@ -17,12 +17,7 @@ name: CI on: - push: - branches: - - '**' pull_request: - branches: - - '**' jobs: tests: