Skip to content

[Bug] go agent enhance multiple arguments of the same type #11753

@zealotjx

Description

@zealotjx

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

OAP server (apache/skywalking)

What happened

When using go agent to enhance a function with multiple parameters of the same type, If the function is in the following format: func myFunc(x, y, z string) {}, it can only be obtained in invocation.Args() of Interceptor.BeforeInvoke a parameter x

What you expected to happen

I think we should be able to get the three parameters x, y and z

How to reproduce

Enhance a function like the following
func myFunc(x, y, z string) {}

Anything else

I checked the source code and found that when traversing dst.Field.Names, break was used. Should it be continue?

func EnhanceParameterNames(fields *dst.FieldList, fieldType FieldListType) []*ParameterInfo {
	if fields == nil {
		return nil
	}
	result := make([]*ParameterInfo, 0)
	for i, f := range fields.List {
		var defineName string
		switch fieldType {
		case FieldListTypeParam:
			defineName = fmt.Sprintf("skywalking_param_%d", i)
		case FieldListTypeResult:
			defineName = fmt.Sprintf("skywalking_result_%d", i)
		case FieldListTypeRecv:
			defineName = fmt.Sprintf("skywalking_recv_%d", i)
		}
		if len(f.Names) == 0 {
			f.Names = []*dst.Ident{{Name: defineName}}
			result = append(result, newParameterInfo(defineName, f.Type))
		} else {
			for _, n := range f.Names {
				if n.Name == "_" {
					*n = *dst.NewIdent(defineName)
					break
				}
			}

			for _, n := range f.Names {
				result = append(result, newParameterInfo(n.Name, f.Type))
				break
			}
		}
	}
	return result
}

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

Labels

agentLanguage agent related.goGo agent

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions