diff --git a/pom.xml b/pom.xml
index ecd83385f..59310ebde 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
5.7.2
1.13.8
3.4.3
- 1.1-170-g3f48c50
+ 1.1-178-ga09ed33
1.0-127-g6c65524
12.0.35
@@ -65,12 +65,6 @@
${project.groupId}
jicoco-config
${jicoco.version}
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
-
-
${project.groupId}
@@ -125,7 +119,7 @@
${project.groupId}
jitsi-xmpp-extensions
- 1.0-110-g00660c3
+ 1.0-118-g64ecd07
com.datadoghq
@@ -181,13 +175,7 @@
${project.groupId}
jitsi-metaconfig
- 1.0-11-g8cf950e
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
-
-
+ 1.0-12-g02d4bd5
${project.groupId}
@@ -197,7 +185,7 @@
com.typesafe
config
- 1.4.0
+ 1.4.2
@@ -278,6 +266,11 @@
${jicoco.version}
compile
+
+ org.jitsi
+ jicoco-tracing
+ ${jicoco.version}
+
diff --git a/src/main/kotlin/org/jitsi/jibri/api/xmpp/XmppApi.kt b/src/main/kotlin/org/jitsi/jibri/api/xmpp/XmppApi.kt
index f96619c8a..d348210cc 100644
--- a/src/main/kotlin/org/jitsi/jibri/api/xmpp/XmppApi.kt
+++ b/src/main/kotlin/org/jitsi/jibri/api/xmpp/XmppApi.kt
@@ -19,6 +19,13 @@ package org.jitsi.jibri.api.xmpp
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
+import io.opentelemetry.api.trace.Span
+import io.opentelemetry.api.trace.SpanContext
+import io.opentelemetry.api.trace.SpanKind
+import io.opentelemetry.api.trace.StatusCode
+import io.opentelemetry.api.trace.TraceFlags
+import io.opentelemetry.api.trace.TraceState
+import io.opentelemetry.context.Context
import org.jitsi.jibri.FileRecordingRequestParams
import org.jitsi.jibri.JibriBusyException
import org.jitsi.jibri.JibriManager
@@ -36,7 +43,10 @@ import org.jitsi.jibri.status.ComponentState
import org.jitsi.jibri.status.JibriStatus
import org.jitsi.jibri.status.JibriStatusManager
import org.jitsi.jibri.util.getCallUrlInfoFromJid
+import org.jitsi.tracing.TracingGlobal
import org.jitsi.utils.logging2.createLogger
+import org.jitsi.xmpp.extensions.TraceParent
+import org.jitsi.xmpp.extensions.TraceParentProvider
import org.jitsi.xmpp.extensions.jibri.JibriIq
import org.jitsi.xmpp.extensions.jibri.JibriIqProvider
import org.jitsi.xmpp.extensions.jibri.JibriStatusPacketExt
@@ -52,6 +62,34 @@ import org.jivesoftware.smack.provider.ProviderManager
import org.jivesoftware.smackx.ping.PingManager
import org.jxmpp.jid.impl.JidCreate
+/**
+ * Extracts a remote [Span] from the `traceparent` extension of an IQ, if present.
+ *
+ * Inlined from jicoco-tracing's TracingUtil, which was removed because it pulled in a Smack
+ * dependency that isn't available on Maven Central: https://github.com/jitsi/jicoco/pull/241
+ */
+private fun remoteSpanFromIq(iq: IQ): Span? {
+ val extension = iq.getExtension(TraceParent::class.java) ?: return null
+ return Span.wrap(
+ SpanContext.createFromRemoteParent(
+ extension.traceId,
+ extension.parentId,
+ TraceFlags.fromHex(extension.traceFlags, 0),
+ TraceState.getDefault()
+ )
+ )
+}
+
+/**
+ * Extracts a remote [Context] from the `traceparent` extension of an IQ, if present, or the root
+ * context otherwise.
+ */
+private fun remoteContextFromIq(iq: IQ): Context {
+ val root = Context.root()
+ val span = remoteSpanFromIq(iq) ?: return root
+ return root.with(span)
+}
+
private class UnsupportedIqMode(val iqMode: String) : Exception()
/**
@@ -71,6 +109,7 @@ class XmppApi(
private val jibriStatusManager: JibriStatusManager,
) : IQListener {
private val logger = createLogger()
+ private val tracer = TracingGlobal.sdk.getTracer("org.jitsi.jibri.xmpp")
private val connectionStateListener = object : ConnectionStateListener {
override fun connected(mucClient: MucClient) {
@@ -136,6 +175,11 @@ class XmppApi(
JibriIq.NAMESPACE,
JibriIqProvider()
)
+ ProviderManager.addExtensionProvider(
+ TraceParent.ELEMENT,
+ TraceParent.NAMESPACE,
+ TraceParentProvider()
+ )
updatePresence(jibriStatusManager.overallStatus)
jibriStatusManager.addStatusHandler(::updatePresence)
@@ -343,10 +387,23 @@ class XmppApi(
* response with [JibriIq.Status.OFF].
*/
private fun handleStopJibriIq(stopJibriIq: JibriIq): IQ {
- jibriManager.stopService()
- // By this point the service has been fully stopped
- return stopJibriIq.createResult {
- status = JibriIq.Status.OFF
+ val span = tracer.spanBuilder("jibri.stop")
+ .setAttribute("session.id", stopJibriIq.sessionId)
+ .setParent(remoteContextFromIq(stopJibriIq))
+ .setSpanKind(SpanKind.SERVER)
+ .startSpan()
+ try {
+ jibriManager.stopService()
+ // By this point the service has been fully stopped
+ return stopJibriIq.createResult {
+ status = JibriIq.Status.OFF
+ }
+ } catch (e: Throwable) {
+ span.setStatus(StatusCode.ERROR, e.message ?: "")
+ span.recordException(e)
+ throw e
+ } finally {
+ span.end()
}
}
@@ -360,6 +417,32 @@ class XmppApi(
xmppEnvironment: XmppEnvironmentConfig,
environmentContext: EnvironmentContext,
serviceStatusHandler: JibriServiceStatusHandler
+ ) {
+ val span = tracer.spanBuilder("jibri.start")
+ .setParent(remoteContextFromIq(startIq))
+ .setAttribute("room", startIq.room.toString())
+ .setAttribute("session.id", startIq.sessionId)
+ .setAttribute("recording-mode", startIq.recordingMode.toString())
+ .setSpanKind(SpanKind.SERVER)
+ .startSpan()
+ try {
+ span.makeCurrent().use {
+ doHandleStartService(startIq, xmppEnvironment, environmentContext, serviceStatusHandler)
+ }
+ } catch (e: Throwable) {
+ span.setStatus(StatusCode.ERROR, e.message ?: "")
+ span.recordException(e)
+ throw e
+ } finally {
+ span.end()
+ }
+ }
+
+ private fun doHandleStartService(
+ startIq: JibriIq,
+ xmppEnvironment: XmppEnvironmentConfig,
+ environmentContext: EnvironmentContext,
+ serviceStatusHandler: JibriServiceStatusHandler
) {
val callUrlInfo = getCallUrlInfoFromJid(
startIq.room,
diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf
index 721e3bd1a..10f16065e 100644
--- a/src/main/resources/reference.conf
+++ b/src/main/resources/reference.conf
@@ -197,3 +197,8 @@ jibri {
ice-connection-timeout = 30 seconds
}
}
+
+tracing {
+ enabled = false
+ service-name = "jibri"
+}