001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.trace;
019
020import io.opentelemetry.api.common.AttributeKey;
021import io.opentelemetry.semconv.SemanticAttributes;
022import java.nio.ByteBuffer;
023import java.util.List;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * The constants in this class correspond with the guidance outlined by the OpenTelemetry <a href=
028 * "https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions">Semantic
029 * Conventions</a>.
030 */
031@InterfaceAudience.Private
032public final class HBaseSemanticAttributes {
033  public static final AttributeKey<String> DB_SYSTEM = SemanticAttributes.DB_SYSTEM;
034  public static final String DB_SYSTEM_VALUE = SemanticAttributes.DbSystemValues.HBASE;
035  public static final AttributeKey<String> DB_CONNECTION_STRING =
036    SemanticAttributes.DB_CONNECTION_STRING;
037  public static final AttributeKey<String> DB_USER = SemanticAttributes.DB_USER;
038  public static final AttributeKey<String> DB_NAME = SemanticAttributes.DB_NAME;
039  public static final AttributeKey<String> DB_OPERATION = SemanticAttributes.DB_OPERATION;
040  public static final AttributeKey<String> TABLE_KEY = AttributeKey.stringKey("db.hbase.table");
041  /**
042   * For operations that themselves ship one or more operations, such as {@link Operation#BATCH} and
043   * {@link Operation#CHECK_AND_MUTATE}.
044   */
045  public static final AttributeKey<List<String>> CONTAINER_DB_OPERATIONS_KEY =
046    AttributeKey.stringArrayKey("db.hbase.container_operations");
047  public static final AttributeKey<List<String>> REGION_NAMES_KEY =
048    AttributeKey.stringArrayKey("db.hbase.regions");
049  public static final AttributeKey<String> RPC_SYSTEM = SemanticAttributes.RPC_SYSTEM;
050  public static final AttributeKey<String> RPC_SERVICE = SemanticAttributes.RPC_SERVICE;
051  public static final AttributeKey<String> RPC_METHOD = SemanticAttributes.RPC_METHOD;
052  public static final AttributeKey<String> SERVER_NAME_KEY =
053    AttributeKey.stringKey("db.hbase.server.name");
054  public static final AttributeKey<String> NET_PEER_NAME = SemanticAttributes.NET_PEER_NAME;
055  public static final AttributeKey<Long> NET_PEER_PORT = SemanticAttributes.NET_PEER_PORT;
056  public static final AttributeKey<Boolean> ROW_LOCK_READ_LOCK_KEY =
057    AttributeKey.booleanKey("db.hbase.rowlock.readlock");
058  public static final AttributeKey<String> WAL_IMPL = AttributeKey.stringKey("db.hbase.wal.impl");
059
060  public static final AttributeKey<String> EXCEPTION_TYPE = SemanticAttributes.EXCEPTION_TYPE;
061  public static final AttributeKey<String> EXCEPTION_MESSAGE = SemanticAttributes.EXCEPTION_MESSAGE;
062  public static final String EXCEPTION_EVENT_NAME = SemanticAttributes.EXCEPTION_EVENT_NAME;
063
064  /**
065   * Indicates the amount of data was read into a {@link ByteBuffer} of type
066   * {@link ByteBuffer#isDirect() direct}.
067   */
068  public static final AttributeKey<Long> DIRECT_BYTES_READ_KEY =
069    AttributeKey.longKey("db.hbase.io.direct_bytes_read");
070  /**
071   * Indicates the amount of data was read into a {@link ByteBuffer} not of type
072   * {@link ByteBuffer#isDirect() direct}.
073   */
074  public static final AttributeKey<Long> HEAP_BYTES_READ_KEY =
075    AttributeKey.longKey("db.hbase.io.heap_bytes_read");
076  /**
077   * Indicates the {@link org.apache.hadoop.hbase.io.compress.Compression.Algorithm} used to encode
078   * an HFile.
079   */
080  public static final AttributeKey<String> COMPRESSION_ALGORITHM_KEY =
081    AttributeKey.stringKey("db.hbase.io.hfile.data_block_encoding");
082  /**
083   * Indicates the {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoding} algorithm used to
084   * encode this HFile.
085   */
086  public static final AttributeKey<String> DATA_BLOCK_ENCODING_KEY =
087    AttributeKey.stringKey("db.hbase.io.hfile.data_block_encoding");
088  /**
089   * Indicates the {@link org.apache.hadoop.hbase.io.crypto.Cipher} used to encrypt this HFile.
090   */
091  public static final AttributeKey<String> ENCRYPTION_CIPHER_KEY =
092    AttributeKey.stringKey("db.hbase.io.hfile.encryption_cipher");
093  /**
094   * Indicates the {@link org.apache.hadoop.hbase.util.ChecksumType} used to encode this HFile.
095   */
096  public static final AttributeKey<String> CHECKSUM_KEY =
097    AttributeKey.stringKey("db.hbase.io.hfile.checksum_type");
098  /**
099   * Indicates the name of the HFile accessed.
100   */
101  public static final AttributeKey<String> HFILE_NAME_KEY =
102    AttributeKey.stringKey("db.hbase.io.hfile.file_name");
103  /**
104   * Indicated the type of read.
105   */
106  public static final AttributeKey<String> READ_TYPE_KEY =
107    AttributeKey.stringKey("db.hbase.io.hfile.read_type");
108  /**
109   * Identifies an entry in the Block Cache.
110   */
111  public static final AttributeKey<String> BLOCK_CACHE_KEY_KEY =
112    AttributeKey.stringKey("db.hbase.io.hfile.block_cache_key");
113
114  /**
115   * These values represent the different IO read strategies HBase may employ for accessing
116   * filesystem data.
117   */
118  public enum ReadType {
119    // TODO: promote this to the FSReader#readBlockData API. Or somehow instead use Scan.ReadType.
120    POSITIONAL_READ,
121    SEEK_PLUS_READ,
122  }
123
124  /**
125   * These are values used with {@link #DB_OPERATION}. They correspond with the implementations of
126   * {@code org.apache.hadoop.hbase.client.Operation}, as well as
127   * {@code org.apache.hadoop.hbase.client.CheckAndMutate}, and "MULTI", meaning a batch of multiple
128   * operations.
129   */
130  public enum Operation {
131    APPEND,
132    BATCH,
133    CHECK_AND_MUTATE,
134    COPROC_EXEC,
135    DELETE,
136    GET,
137    INCREMENT,
138    PUT,
139    SCAN,
140  }
141
142  /**
143   * These are values used with {@link #RPC_SYSTEM}. Only a single value for now; more to come as we
144   * add tracing over our gateway components.
145   */
146  public enum RpcSystem {
147    HBASE_RPC,
148  }
149
150  private HBaseSemanticAttributes() {
151  }
152}