alibaba / opentelemetry-go-auto-instrumentation

OpenTelemetry Compile-Time Instrumentation for Golang
Apache License 2.0
101 stars 16 forks source link

logrus rules call none exist function #96

Open shengjiangfeng opened 5 hours ago

shengjiangfeng commented 5 hours ago

Describe the bug

image

我在使用过程中发现logrus自动注入的rule,里面引用了logrus v1.9.3中不存在的方法,这个是版本导致的问题?

Steps to reproduce

github.com/sirupsen/logrus v1.8.1 你可以用一个引用了logrus的demo main.go试下

// Copyright (c) 2024 Alibaba Group Holding Ltd.
//
// Licensed 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 (
    "github.com/sirupsen/logrus"
    "go.opentelemetry.io/otel/sdk/trace"
)

func logNewOnExit(call logrus.CallContext) {
    std := logrus.StandardLogger()
    std.AddHook(&logHook{})
    return
}

type logHook struct{}

func (hook *logHook) Levels() []logrus.Level {
    return logrus.AllLevels
}

func (hook *logHook) Fire(entry *logrus.Entry) error {
    // 修改日志内容
    traceId, spanId := trace.GetTraceAndSpanId()
    if traceId != "" {
        entry.Data["trace_id"] = traceId
    }
    if spanId != "" {
        entry.Data["span_id"] = spanId
    }
    return nil
}

go.mod

module ssaaaa

go 1.21

require (
    github.com/sirupsen/logrus v1.9.1
    go.opentelemetry.io/otel/sdk v1.28.0
)

require (
    github.com/go-logr/logr v1.4.2 // indirect
    github.com/go-logr/stdr v1.2.2 // indirect
    github.com/google/uuid v1.6.0 // indirect
    go.opentelemetry.io/otel v1.28.0 // indirect
    go.opentelemetry.io/otel/metric v1.28.0 // indirect
    go.opentelemetry.io/otel/trace v1.28.0 // indirect
    golang.org/x/sys v0.25.0 // indirect
)

replace go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v1.28.0

Expected behavior

image

Rule can work.

Actual behavior

image

opentelemetry-go-auto-instrumentation version

0c1efac5b2708b81f51452f15b054d7bee5ab428

Environment

Go: OS:

Additional context

No response

123liuziming commented 5 hours ago

The implementation of CallContext interface will be injected by otelbuild in compile time. Can you compile your application with otelbuild correctly?

shengjiangfeng commented 5 hours ago

好的,明白,我能获取到otel build的时候的所有的代码么,不让它restore, 有个logrus没有打印trace_id的问题需要debug, 有参数么?

123liuziming commented 4 hours ago

You can use otelbuild -debug according to https://github.com/alibaba/opentelemetry-go-auto-instrumentation/blob/main/docs/how-to-debug.md. And you can see the implementation of CallContext in debug file. image