-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: toolkit span add event impl #200
Conversation
Signed-off-by: shyunny <[email protected]>
Please make sure CI pass. |
When we use a separate We can view the mixed compiled code package trace
// Event related constant definitions
const (
skywalking_operatorVarTracedefaultEventType = "info"
skywalking_operatorVarTracedefaultEmptyEvent = "unknown"
) add_event.go: package trace
type skywalking_operatorTypeTraceAddEventInterceptor struct {
}
func (h *skywalking_operatorTypeTraceAddEventInterceptor) BeforeInvoke(invocation skywalking_operatorTypeOperatorInvocation) error {
......
if span != nil {
if et == "" {
et = skywalking_operatorTypeTracedefaultEventType
}
if event == "" {
event = skywalking_operatorTypeTracedefaultEmptyEvent
}
}
......
return nil
} async_event.go: func (h *skywalking_operatorTypeTraceAsyncAddEventInterceptor) AfterInvoke(invocation skywalking_operatorTypeOperatorInvocation, _ ...interface{}) error {
......
if et == "" {
et = skywalking_operatorTypeTracedefaultEventType
}
event := invocation.Args()[1].(string)
if event == "" {
event = skywalking_operatorTypeTracedefaultEmptyEvent
}
......
return nil
} After analysis, this is because when WDYT? |
Please check these code: https://github.com/apache/skywalking-go/blob/main/tools/go-agent/instrument/plugins/rewrite/rewrite.go#L126-L155 |
I have done relevant checks, as I said above. When enhancing |
Can we add a var mapping check when rewriting LRs data? |
In LRs Ident, it can be Const or Var. But we don’t know these, so we can’t map them. |
We have already mapping all var and const, so we know all about it in the rewrite files. Why we can't rewrite about this? |
For example, the following code: if et == "" {
et = defaultEventType
} The corresponding AST result is "Rhs": [
{
"Loc": {
"End": {
"Filename": "main.go",
"Offset": 407,
"Line": 16,
"Column": 25
},
"Start": {
"Filename": "main.go",
"Offset": 391,
"Line": 16,
"Column": 9
}
},
"Name": "defaultEventType", # <--- we know
"_type": "Ident"
} When we rewrite, we need to determine its type, but the AST lacks the type and can only know the value of |
Therefore, in the rewrite phase, it can only perform the default rewrite and cannot match it. You can try it. To solve this problem, I rebuilt the code in the interceptor to avoid introducing too many external dependencies. I think this is a good way |
Read the rewrite logic carefully in go agent, when And I have tried, you need to check the const and adding them to the var rewrite strategy, that's enough: https://github.com/apache/skywalking-go/blob/main/tools/go-agent/instrument/plugins/rewrite/rewrite.go#L126-L155 |
I added a small feature to the original rewrite, which prevents it from rewriting when the type has SWNoRewrite suffix. This mainly solves the following problems:
So we prevent it from rewriting, which ensures that when mixed compilation, the EventType type of the interceptor can point to the type defined in the
|
Signed-off-by: shyunny <[email protected]>
Signed-off-by: shyunny <[email protected]>
Signed-off-by: shyunny <[email protected]>
What type of PR?
What did you do?