fix golint issues (#992)
This commit is contained in:
@@ -3,43 +3,38 @@ package opentelemetry
|
||||
import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
grpc_codes "google.golang.org/grpc/codes"
|
||||
gcodes "google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
const (
|
||||
// GRPCStatusCodeKey is convention for numeric status code of a gRPC request.
|
||||
GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code")
|
||||
|
||||
// Name of message transmitted or received.
|
||||
// RPCNameKey is the name of message transmitted or received.
|
||||
RPCNameKey = attribute.Key("name")
|
||||
|
||||
// Type of message transmitted or received.
|
||||
// RPCMessageTypeKey is the type of message transmitted or received.
|
||||
RPCMessageTypeKey = attribute.Key("message.type")
|
||||
|
||||
// Identifier of message transmitted or received.
|
||||
// RPCMessageIDKey is the identifier of message transmitted or received.
|
||||
RPCMessageIDKey = attribute.Key("message.id")
|
||||
|
||||
// The compressed size of the message transmitted or received in bytes.
|
||||
// RPCMessageCompressedSizeKey is the compressed size of the message transmitted or received in bytes.
|
||||
RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size")
|
||||
|
||||
// The uncompressed size of the message transmitted or received in
|
||||
// bytes.
|
||||
// RPCMessageUncompressedSizeKey is the uncompressed size of the message
|
||||
// transmitted or received in bytes.
|
||||
RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size")
|
||||
)
|
||||
|
||||
// Semantic conventions for common RPC attributes.
|
||||
var (
|
||||
// Semantic convention for gRPC as the remoting system.
|
||||
// RPCSystemGRPC is the semantic convention for gRPC as the remoting system.
|
||||
RPCSystemGRPC = semconv.RPCSystemKey.String("grpc")
|
||||
|
||||
// Semantic convention for a message named message.
|
||||
// RPCNameMessage is the semantic convention for a message named message.
|
||||
RPCNameMessage = RPCNameKey.String("message")
|
||||
|
||||
// Semantic conventions for RPC message types.
|
||||
RPCMessageTypeSent = RPCMessageTypeKey.String("SENT")
|
||||
// RPCMessageTypeSent is the semantic conventions for sent RPC message types.
|
||||
RPCMessageTypeSent = RPCMessageTypeKey.String("SENT")
|
||||
// RPCMessageTypeReceived is the semantic conventions for the received RPC message types.
|
||||
RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED")
|
||||
)
|
||||
|
||||
func StatusCodeAttr(c grpc_codes.Code) attribute.KeyValue {
|
||||
// StatusCodeAttr returns a attribute.KeyValue that represents the give c.
|
||||
func StatusCodeAttr(c gcodes.Code) attribute.KeyValue {
|
||||
return GRPCStatusCodeKey.Int64(int64(c))
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
receiveEndEvent streamEventType = iota
|
||||
errorEvent
|
||||
)
|
||||
|
||||
var _ = proto.Marshal
|
||||
|
||||
type streamEventType int
|
||||
|
||||
type streamEvent struct {
|
||||
@@ -16,11 +23,6 @@ type streamEvent struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
const (
|
||||
receiveEndEvent streamEventType = iota
|
||||
errorEvent
|
||||
)
|
||||
|
||||
type clientStream struct {
|
||||
grpc.ClientStream
|
||||
|
||||
@@ -33,11 +35,8 @@ type clientStream struct {
|
||||
sentMessageID int
|
||||
}
|
||||
|
||||
var _ = proto.Marshal
|
||||
|
||||
func (w *clientStream) RecvMsg(m interface{}) error {
|
||||
err := w.ClientStream.RecvMsg(m)
|
||||
|
||||
if err == nil && !w.desc.ServerStreams {
|
||||
w.sendStreamEvent(receiveEndEvent, nil)
|
||||
} else if err == io.EOF {
|
||||
@@ -54,10 +53,8 @@ func (w *clientStream) RecvMsg(m interface{}) error {
|
||||
|
||||
func (w *clientStream) SendMsg(m interface{}) error {
|
||||
err := w.ClientStream.SendMsg(m)
|
||||
|
||||
w.sentMessageID++
|
||||
MessageSent.Event(w.Context(), w.sentMessageID, m)
|
||||
|
||||
if err != nil {
|
||||
w.sendStreamEvent(errorEvent, err)
|
||||
}
|
||||
@@ -90,6 +87,7 @@ func (w *clientStream) sendStreamEvent(eventType streamEventType, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// WrapClientStream wraps s with given ctx and desc.
|
||||
func WrapClientStream(ctx context.Context, s grpc.ClientStream, desc *grpc.StreamDesc) *clientStream {
|
||||
events := make(chan streamEvent)
|
||||
eventsDone := make(chan struct{})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package opentelemetry
|
||||
|
||||
// TraceName represents the tracing name.
|
||||
const TraceName = "go-zero"
|
||||
|
||||
// A Config is a opentelemetry config.
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
MessageSent = messageType(RPCMessageTypeSent)
|
||||
// MessageSent is the type of sent messages.
|
||||
MessageSent = messageType(RPCMessageTypeSent)
|
||||
// MessageReceived is the type of received messages.
|
||||
MessageReceived = messageType(RPCMessageTypeReceived)
|
||||
)
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ func (w *serverStream) SendMsg(m interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// WrapServerStream wraps the given grpc.ServerStream with the given context.
|
||||
func WrapServerStream(ctx context.Context, ss grpc.ServerStream) *serverStream {
|
||||
return &serverStream{
|
||||
ServerStream: ss,
|
||||
|
||||
@@ -36,12 +36,14 @@ func (s *metadataSupplier) Keys() []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// Inject injects the metadata into ctx.
|
||||
func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) {
|
||||
p.Inject(ctx, &metadataSupplier{
|
||||
metadata: metadata,
|
||||
})
|
||||
}
|
||||
|
||||
// Extract extracts the metadata from ctx.
|
||||
func Extract(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) (baggage.Baggage, trace.SpanContext) {
|
||||
ctx = p.Extract(ctx, &metadataSupplier{
|
||||
metadata: metadata,
|
||||
|
||||
@@ -10,14 +10,17 @@ import (
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
|
||||
// PeerFromCtx returns the peer from ctx.
|
||||
func PeerFromCtx(ctx context.Context) string {
|
||||
p, ok := peer.FromContext(ctx)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return p.Addr.String()
|
||||
}
|
||||
|
||||
// SpanInfo returns the span info.
|
||||
func SpanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
|
||||
attrs := []attribute.KeyValue{RPCSystemGRPC}
|
||||
name, mAttrs := ParseFullMethod(fullMethod)
|
||||
@@ -26,6 +29,7 @@ func SpanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
|
||||
return name, attrs
|
||||
}
|
||||
|
||||
// ParseFullMethod returns the method name and attributes.
|
||||
func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
|
||||
name := strings.TrimLeft(fullMethod, "/")
|
||||
parts := strings.SplitN(name, "/", 2)
|
||||
@@ -41,9 +45,11 @@ func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
|
||||
if method := parts[1]; method != "" {
|
||||
attrs = append(attrs, semconv.RPCMethodKey.String(method))
|
||||
}
|
||||
|
||||
return name, attrs
|
||||
}
|
||||
|
||||
// PeerAttr returns the peer attributes.
|
||||
func PeerAttr(addr string) []attribute.KeyValue {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
|
||||
@@ -51,6 +51,7 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
// Done returns the channel that notifies the process quitting.
|
||||
func Done() <-chan struct{} {
|
||||
return done
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package trace
|
||||
|
||||
const (
|
||||
// TraceIdKey is the trace id header.
|
||||
TraceIdKey = "X-Trace-ID"
|
||||
|
||||
spanIdKey = "X-Span-ID"
|
||||
|
||||
Reference in New Issue
Block a user