attributes.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package opentelemetry
  2. import (
  3. "go.opentelemetry.io/otel/attribute"
  4. semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
  5. grpc_codes "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. // Name of message transmitted or received.
  11. RPCNameKey = attribute.Key("name")
  12. // Type of message transmitted or received.
  13. RPCMessageTypeKey = attribute.Key("message.type")
  14. // Identifier of message transmitted or received.
  15. RPCMessageIDKey = attribute.Key("message.id")
  16. // The compressed size of the message transmitted or received in bytes.
  17. RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size")
  18. // The uncompressed size of the message transmitted or received in
  19. // bytes.
  20. RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size")
  21. )
  22. // Semantic conventions for common RPC attributes.
  23. var (
  24. // Semantic convention for gRPC as the remoting system.
  25. RPCSystemGRPC = semconv.RPCSystemKey.String("grpc")
  26. // Semantic convention for a message named message.
  27. RPCNameMessage = RPCNameKey.String("message")
  28. // Semantic conventions for RPC message types.
  29. RPCMessageTypeSent = RPCMessageTypeKey.String("SENT")
  30. RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED")
  31. )
  32. func StatusCodeAttr(c grpc_codes.Code) attribute.KeyValue {
  33. return GRPCStatusCodeKey.Int64(int64(c))
  34. }