Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<kotest.version>5.7.2</kotest.version>
<mockk.version>1.13.8</mockk.version>
<ktor.version>3.4.3</ktor.version>
<jicoco.version>1.1-170-g3f48c50</jicoco.version>
<jicoco.version>1.1-178-ga09ed33</jicoco.version>
<jitsi.utils.version>1.0-127-g6c65524</jitsi.utils.version>
<jetty.version>12.0.35</jetty.version>
</properties>
Expand Down Expand Up @@ -65,12 +65,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>jicoco-config</artifactId>
<version>${jicoco.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -125,7 +119,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-xmpp-extensions</artifactId>
<version>1.0-110-g00660c3</version>
<version>1.0-118-g64ecd07</version>
</dependency>
<dependency>
<groupId>com.datadoghq</groupId>
Expand Down Expand Up @@ -181,13 +175,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-metaconfig</artifactId>
<version>1.0-11-g8cf950e</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
</exclusions>
<version>1.0-12-g02d4bd5</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand All @@ -197,7 +185,7 @@
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.0</version>
<version>1.4.2</version>
</dependency>
<!-- testing -->
<dependency>
Expand Down Expand Up @@ -278,6 +266,11 @@
<version>${jicoco.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jitsi</groupId>
<artifactId>jicoco-tracing</artifactId>
<version>${jicoco.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
91 changes: 87 additions & 4 deletions src/main/kotlin/org/jitsi/jibri/api/xmpp/XmppApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -136,6 +175,11 @@ class XmppApi(
JibriIq.NAMESPACE,
JibriIqProvider()
)
ProviderManager.addExtensionProvider(
TraceParent.ELEMENT,
TraceParent.NAMESPACE,
TraceParentProvider()
)
updatePresence(jibriStatusManager.overallStatus)
jibriStatusManager.addStatusHandler(::updatePresence)

Expand Down Expand Up @@ -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()
Comment thread
JulianGCalderon marked this conversation as resolved.
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()
}
}

Expand All @@ -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()
Comment thread
JulianGCalderon marked this conversation as resolved.
try {
span.makeCurrent().use {
doHandleStartService(startIq, xmppEnvironment, environmentContext, serviceStatusHandler)
}
Comment thread
JulianGCalderon marked this conversation as resolved.
} 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,
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,8 @@ jibri {
ice-connection-timeout = 30 seconds
}
}

tracing {
enabled = false
service-name = "jibri"
}
Comment thread
JulianGCalderon marked this conversation as resolved.