attributes.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package trace
  2. import (
  3. "go.opentelemetry.io/otel/attribute"
  4. semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
  5. gcodes "google.golang.org/grpc/codes"
  6. )
  7. const (
  8. // GRPCStatusCodeKey is convention for numeric status code of a gRPC request.
  9. GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code")
  10. // RPCNameKey is the name of message transmitted or received.
  11. RPCNameKey = attribute.Key("name")
  12. // RPCMessageTypeKey is the type of message transmitted or received.
  13. RPCMessageTypeKey = attribute.Key("message.type")
  14. // RPCMessageIDKey is the identifier of message transmitted or received.
  15. RPCMessageIDKey = attribute.Key("message.id")
  16. // RPCMessageCompressedSizeKey is the compressed size of the message transmitted or received in bytes.
  17. RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size")
  18. // RPCMessageUncompressedSizeKey is the uncompressed size of the message
  19. // transmitted or received in bytes.
  20. RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size")
  21. )
  22. // Semantic conventions for common RPC attributes.
  23. var (
  24. // RPCSystemGRPC is the semantic convention for gRPC as the remoting system.
  25. RPCSystemGRPC = semconv.RPCSystemKey.String("grpc")
  26. // RPCNameMessage is the semantic convention for a message named message.
  27. RPCNameMessage = RPCNameKey.String("message")
  28. // RPCMessageTypeSent is the semantic conventions for sent RPC message types.
  29. RPCMessageTypeSent = RPCMessageTypeKey.String("SENT")
  30. // RPCMessageTypeReceived is the semantic conventions for the received RPC message types.
  31. RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED")
  32. )
  33. // StatusCodeAttr returns an attribute.KeyValue that represents the give c.
  34. func StatusCodeAttr(c gcodes.Code) attribute.KeyValue {
  35. return GRPCStatusCodeKey.Int64(int64(c))
  36. }