Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/plugin-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
- go-elasticsearchv8
- goframe
- so11y
- cross-goroutine
steps:
- uses: actions/checkout@v2
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Release Notes.
* Fix cannot find file when exec build in test/plugins.
* Fix not set span error when http status code >= 400
* Fix http plugin cannot provide peer name when optional Host is empty.
* Fix Correctly instrument newproc1 for Go 1.23+ parameter counts

#### Issues and PR
- All issues are [here](https://github.com/apache/skywalking/milestone/219?closed=1)
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use (
./test/plugins/scenarios/metric-activation
./test/plugins/scenarios/goframe
./test/plugins/scenarios/so11y
./test/plugins/scenarios/cross-goroutine

./tools/go-agent

Expand Down
22 changes: 22 additions & 0 deletions test/plugins/scenarios/cross-goroutine/bin/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

home="$(cd "$(dirname $0)"; pwd)"
go build ${GO_BUILD_OPTS} -o cross-goroutine

./cross-goroutine
50 changes: 50 additions & 0 deletions test/plugins/scenarios/cross-goroutine/config/excepted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

segmentItems:
- serviceName: cross-goroutine
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: GET:/execute
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: nq 0
endTime: nq 0
componentId: 5004
isError: false
spanType: Entry
peer: ''
skipAnalysis: false
tags:
- {key: http.method, value: GET}
- {key: url, value: 'service:8080/execute'}
- {key: status_code, value: '200'}
- operationName: testGoroutineLocalSpan
parentSpanId: 0
spanId: 1
spanLayer: Unknown
startTime: nq 0
endTime: nq 0
componentId: 0
isError: false
spanType: Local
peer: ''
skipAnalysis: false
meterItems: []
logItems: []
3 changes: 3 additions & 0 deletions test/plugins/scenarios/cross-goroutine/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module test/plugins/scenarios/cross-goroutine

go 1.19
52 changes: 52 additions & 0 deletions test/plugins/scenarios/cross-goroutine/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package main

import (
"log"
"net/http"
"sync"
"time"

_ "github.com/apache/skywalking-go"
"github.com/apache/skywalking-go/toolkit/trace"
)

func executeHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for /execute")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
trace.CreateLocalSpan("testGoroutineLocalSpan")
time.Sleep(100 * time.Millisecond)
trace.StopSpan()
}()
wg.Wait()
log.Println("Goroutine finished, sending response")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("success"))
}

func main() {
http.HandleFunc("/execute", executeHandler)
http.HandleFunc("/health", func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusOK)
})
_ = http.ListenAndServe(":8080", nil)
}
28 changes: 28 additions & 0 deletions test/plugins/scenarios/cross-goroutine/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

entry-service: http://${HTTP_HOST}:${HTTP_PORT}/execute
health-checker: http://${HTTP_HOST}:${HTTP_PORT}/health
start-script: ./bin/startup.sh
framework: go
export-port: 8080
support-version:
- go: 1.19
- go: 1.20
- go: 1.21
- go: 1.22
- go: 1.23
- go: 1.24
4 changes: 1 addition & 3 deletions test/plugins/scenarios/irisv12/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ support-version:
- go: 1.19
framework:
- v12.2.0
- v12.1.0
- go: 1.21
framework:
- v12.2.5
- v12.2.0
- v12.1.0
- v12.2.0
42 changes: 41 additions & 1 deletion tools/go-agent/instrument/api/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

package api

import "path/filepath"
import (
"path/filepath"
"strconv"
"strings"
)

type CompileOptions struct {
Package string `swflag:"-p"`
Expand All @@ -35,3 +39,39 @@ func (c *CompileOptions) IsValid() bool {
func (c *CompileOptions) CompileBaseDir() string {
return filepath.Dir(filepath.Dir(c.Output))
}

func (c *CompileOptions) CheckGoVersionGreaterOrEqual(requiredMajor, requiredMinor int) bool {
if c.Lang == "" {
return false
}
if !strings.HasPrefix(c.Lang, "go") {
return false
}
versionStr := strings.TrimPrefix(c.Lang, "go")
parts := strings.SplitN(versionStr, ".", 3)
if len(parts) < 2 {
return false
}

majorStr := parts[0]
currentMajor64, err := strconv.ParseInt(majorStr, 10, 64)
if err != nil {
return false
}
currentMajor := int(currentMajor64)

minorStr := parts[1]
currentMinor64, err := strconv.ParseInt(minorStr, 10, 64)
if err != nil {
return false
}
currentMinor := int(currentMinor64)

if currentMajor > requiredMajor {
return true
}
if currentMajor == requiredMajor && currentMinor >= requiredMinor {
return true
}
return false
}
19 changes: 7 additions & 12 deletions tools/go-agent/instrument/runtime/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package runtime

import (
"strconv"
"strings"

"github.com/dave/dst"
"github.com/dave/dst/dstutil"

Expand Down Expand Up @@ -73,7 +70,11 @@ func (r *Instrument) FilterAndEdit(path string, curFile *dst.File, cursor *dstut
if len(n.Type.Results.List) != 1 {
return false
}
if len(n.Type.Params.List) != 3 {
expectedParamCount := 3
if r.opts.CheckGoVersionGreaterOrEqual(1, 23) {
expectedParamCount = 5
Copy link

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

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

According to the PR description, for Go 1.23 and later, runtime.newproc1 should expect 2 parameters rather than 5. Please update the logic to set the expected parameter count to 2 for Go 1.23+.

Suggested change
expectedParamCount = 5
expectedParamCount = 2

Copilot uses AI. Check for mistakes.
}
if len(n.Type.Params.List) != expectedParamCount {
return false
}
parameters := tools.EnhanceParameterNames(n.Type.Params, tools.FieldListTypeParam)
Expand Down Expand Up @@ -106,14 +107,8 @@ func (r *Instrument) AfterEnhanceFile(fromPath, newPath string) error {
}

func (r *Instrument) parseInternalAtomicPath() string {
if strings.HasPrefix(r.opts.Lang, "go1.") {
_, after, found := strings.Cut(r.opts.Lang, ".")
if found {
i, err := strconv.ParseInt(after, 10, 64)
if err == nil && i >= 23 {
return "internal/runtime/atomic"
}
}
if r.opts.CheckGoVersionGreaterOrEqual(1, 23) {
return "internal/runtime/atomic"
}
return defaultInternalAtomicPath
}
Expand Down