diff --git a/bin/hbase b/bin/hbase
index d2307c50c33a..496ce49220cd 100755
--- a/bin/hbase
+++ b/bin/hbase
@@ -475,6 +475,11 @@ add_jdk11_deps_to_classpath() {
done
}
+enable_trace() {
+ agent_jar=$(find lib/trace -type f -name "opentelemetry-javaagent-*")
+ HBASE_OPTS="$HBASE_OPTS -javaagent:$agent_jar $HBASE_TRACE_OPTS"
+}
+
#Add the development env class path stuff
if $in_dev_env; then
add_maven_deps_to_classpath "cached_classpath.txt"
@@ -767,6 +772,11 @@ elif [ "${DEBUG}" = "true" ]; then
echo "JDK11 jars skipped from classpath."
fi
+if [[ -n "${HBASE_TRACE_OPTS}" ]]; then
+ echo "Attach opentelemetry agent to enable trace"
+ enable_trace
+fi
+
# Have JVM dump heap if we run out of memory. Files will be 'launch directory'
# and are named like the following: java_pid21612.hprof. Apparently it doesn't
# 'cost' to have this flag enabled. Its a 1.6 flag only. See:
diff --git a/conf/hbase-env.sh b/conf/hbase-env.sh
index e0f9c01bc995..e1dff2b7e3e2 100644
--- a/conf/hbase-env.sh
+++ b/conf/hbase-env.sh
@@ -142,3 +142,8 @@
# Override text processing tools for use by these launch scripts.
# export GREP="${GREP-grep}"
# export SED="${SED-sed}"
+
+# Uncomment to enable trace, you can change the options to use other exporters such as jaeger or
+# zipkin. See https://github.com/open-telemetry/opentelemetry-java-instrumentation on how to config
+# exporters and other components through system properties.
+# export HBASE_TRACE_OPTS="-Dotel.config.sampler.probability=0.1 -Dotel.exporter=logging"
diff --git a/hbase-assembly/pom.xml b/hbase-assembly/pom.xml
index 805351767e37..248f0ce1f953 100644
--- a/hbase-assembly/pom.xml
+++ b/hbase-assembly/pom.xml
@@ -339,5 +339,11 @@
log4j
log4j
+
+
+ io.opentelemetry.javaagent
+ opentelemetry-javaagent
+ all
+
diff --git a/hbase-assembly/src/main/assembly/hadoop-three-compat.xml b/hbase-assembly/src/main/assembly/hadoop-three-compat.xml
index 1c172e9c31ff..25d533b41543 100644
--- a/hbase-assembly/src/main/assembly/hadoop-three-compat.xml
+++ b/hbase-assembly/src/main/assembly/hadoop-three-compat.xml
@@ -113,6 +113,7 @@
org.apache.yetus:audience-annotations
org.slf4j:slf4j-api
org.slf4j:slf4j-log4j12
+ io.opentelemetry.javaagent:*
@@ -225,7 +226,7 @@
lib/jdk11
true
- com.sun.activation:javax.activation
+ com.sun.activation:javax.activation