diff --git a/src/initializer.tsx b/src/initializer.tsx index d0797e9d..2ecd1162 100644 --- a/src/initializer.tsx +++ b/src/initializer.tsx @@ -26,7 +26,6 @@ import { import { getUrlParams } from "./UrlParams"; import { Config } from "./config/Config"; -import { ElementCallOpenTelemetry } from "./otel/otel"; import { platform } from "./Platform"; import { isFailure } from "./utils/fetch"; @@ -101,7 +100,6 @@ enum LoadState { class DependencyLoadStates { public config: LoadState = LoadState.None; public sentry: LoadState = LoadState.None; - public openTelemetry: LoadState = LoadState.None; public allDepsAreLoaded(): boolean { return !Object.values(this).some((s) => s !== LoadState.Loaded); @@ -266,15 +264,6 @@ export class Initializer { this.loadStates.sentry = LoadState.Loaded; } - // OpenTelemetry (also only after config loaded) - if ( - this.loadStates.openTelemetry === LoadState.None && - this.loadStates.config === LoadState.Loaded - ) { - ElementCallOpenTelemetry.globalInit(); - this.loadStates.openTelemetry = LoadState.Loaded; - } - if (this.loadStates.allDepsAreLoaded()) { // resolve if there is no dependency that is not loaded resolve(); diff --git a/src/otel/OTelCall.ts b/src/otel/OTelCall.ts deleted file mode 100644 index e70cedf2..00000000 --- a/src/otel/OTelCall.ts +++ /dev/null @@ -1,188 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { type Span } from "@opentelemetry/api"; -import { type MatrixCall } from "matrix-js-sdk"; -import { CallEvent } from "matrix-js-sdk/lib/webrtc/call"; -import { - type TransceiverStats, - type CallFeedStats, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -import { ObjectFlattener } from "./ObjectFlattener"; -import { ElementCallOpenTelemetry } from "./otel"; -import { type OTelCallAbstractMediaStreamSpan } from "./OTelCallAbstractMediaStreamSpan"; -import { OTelCallTransceiverMediaStreamSpan } from "./OTelCallTransceiverMediaStreamSpan"; -import { OTelCallFeedMediaStreamSpan } from "./OTelCallFeedMediaStreamSpan"; - -type StreamId = string; -type MID = string; - -/** - * Tracks an individual call within a group call, either to a full-mesh peer or a focus - */ -export class OTelCall { - private readonly trackFeedSpan = new Map< - StreamId, - OTelCallAbstractMediaStreamSpan - >(); - private readonly trackTransceiverSpan = new Map< - MID, - OTelCallAbstractMediaStreamSpan - >(); - - public constructor( - public userId: string, - public deviceId: string, - public call: MatrixCall, - public span: Span, - ) { - if (call.peerConn) { - this.addCallPeerConnListeners(); - } else { - this.call.once( - CallEvent.PeerConnectionCreated, - this.addCallPeerConnListeners, - ); - } - } - - public dispose(): void { - this.call.peerConn?.removeEventListener( - "connectionstatechange", - this.onCallConnectionStateChanged, - ); - this.call.peerConn?.removeEventListener( - "signalingstatechange", - this.onCallSignalingStateChanged, - ); - this.call.peerConn?.removeEventListener( - "iceconnectionstatechange", - this.onIceConnectionStateChanged, - ); - this.call.peerConn?.removeEventListener( - "icegatheringstatechange", - this.onIceGatheringStateChanged, - ); - this.call.peerConn?.removeEventListener( - "icecandidateerror", - this.onIceCandidateError, - ); - } - - private addCallPeerConnListeners = (): void => { - this.call.peerConn?.addEventListener( - "connectionstatechange", - this.onCallConnectionStateChanged, - ); - this.call.peerConn?.addEventListener( - "signalingstatechange", - this.onCallSignalingStateChanged, - ); - this.call.peerConn?.addEventListener( - "iceconnectionstatechange", - this.onIceConnectionStateChanged, - ); - this.call.peerConn?.addEventListener( - "icegatheringstatechange", - this.onIceGatheringStateChanged, - ); - this.call.peerConn?.addEventListener( - "icecandidateerror", - this.onIceCandidateError, - ); - }; - - public onCallConnectionStateChanged = (): void => { - this.span.addEvent("matrix.call.callConnectionStateChange", { - callConnectionState: this.call.peerConn?.connectionState, - }); - }; - - public onCallSignalingStateChanged = (): void => { - this.span.addEvent("matrix.call.callSignalingStateChange", { - callSignalingState: this.call.peerConn?.signalingState, - }); - }; - - public onIceConnectionStateChanged = (): void => { - this.span.addEvent("matrix.call.iceConnectionStateChange", { - iceConnectionState: this.call.peerConn?.iceConnectionState, - }); - }; - - public onIceGatheringStateChanged = (): void => { - this.span.addEvent("matrix.call.iceGatheringStateChange", { - iceGatheringState: this.call.peerConn?.iceGatheringState, - }); - }; - - public onIceCandidateError = (ev: Event): void => { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive(ev, flatObject, "error.", 0); - - this.span.addEvent("matrix.call.iceCandidateError", flatObject); - }; - - public onCallFeedStats(callFeeds: CallFeedStats[]): void { - let prvFeeds: StreamId[] = [...this.trackFeedSpan.keys()]; - - callFeeds.forEach((feed) => { - if (!this.trackFeedSpan.has(feed.stream)) { - this.trackFeedSpan.set( - feed.stream, - new OTelCallFeedMediaStreamSpan( - ElementCallOpenTelemetry.instance, - this.span, - feed, - ), - ); - } - this.trackFeedSpan.get(feed.stream)?.update(feed); - prvFeeds = prvFeeds.filter((prvStreamId) => prvStreamId !== feed.stream); - }); - - prvFeeds.forEach((prvStreamId) => { - this.trackFeedSpan.get(prvStreamId)?.end(); - this.trackFeedSpan.delete(prvStreamId); - }); - } - - public onTransceiverStats(transceiverStats: TransceiverStats[]): void { - let prvTransSpan: MID[] = [...this.trackTransceiverSpan.keys()]; - - transceiverStats.forEach((transStats) => { - if (!this.trackTransceiverSpan.has(transStats.mid)) { - this.trackTransceiverSpan.set( - transStats.mid, - new OTelCallTransceiverMediaStreamSpan( - ElementCallOpenTelemetry.instance, - this.span, - transStats, - ), - ); - } - this.trackTransceiverSpan.get(transStats.mid)?.update(transStats); - prvTransSpan = prvTransSpan.filter( - (prvStreamId) => prvStreamId !== transStats.mid, - ); - }); - - prvTransSpan.forEach((prvMID) => { - this.trackTransceiverSpan.get(prvMID)?.end(); - this.trackTransceiverSpan.delete(prvMID); - }); - } - - public end(): void { - this.trackFeedSpan.forEach((feedSpan) => feedSpan.end()); - this.trackTransceiverSpan.forEach((transceiverSpan) => - transceiverSpan.end(), - ); - this.span.end(); - } -} diff --git a/src/otel/OTelCallAbstractMediaStreamSpan.ts b/src/otel/OTelCallAbstractMediaStreamSpan.ts deleted file mode 100644 index 69e41547..00000000 --- a/src/otel/OTelCallAbstractMediaStreamSpan.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import opentelemetry, { type Span } from "@opentelemetry/api"; -import { type TrackStats } from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -import { type ElementCallOpenTelemetry } from "./otel"; -import { OTelCallMediaStreamTrackSpan } from "./OTelCallMediaStreamTrackSpan"; - -type TrackId = string; - -export abstract class OTelCallAbstractMediaStreamSpan { - protected readonly trackSpans = new Map< - TrackId, - OTelCallMediaStreamTrackSpan - >(); - public readonly span; - - public constructor( - protected readonly oTel: ElementCallOpenTelemetry, - protected readonly callSpan: Span, - protected readonly type: string, - ) { - const ctx = opentelemetry.trace.setSpan( - opentelemetry.context.active(), - callSpan, - ); - const options = { - links: [ - { - context: callSpan.spanContext(), - }, - ], - }; - this.span = oTel.tracer.startSpan(this.type, options, ctx); - } - - protected upsertTrackSpans(tracks: TrackStats[]): void { - let prvTracks: TrackId[] = [...this.trackSpans.keys()]; - tracks.forEach((t) => { - if (!this.trackSpans.has(t.id)) { - this.trackSpans.set( - t.id, - new OTelCallMediaStreamTrackSpan(this.oTel, this.span, t), - ); - } - this.trackSpans.get(t.id)?.update(t); - prvTracks = prvTracks.filter((prvTrackId) => prvTrackId !== t.id); - }); - - prvTracks.forEach((prvTrackId) => { - this.trackSpans.get(prvTrackId)?.end(); - this.trackSpans.delete(prvTrackId); - }); - } - - public abstract update(data: object): void; - - public end(): void { - this.trackSpans.forEach((tSpan) => { - tSpan.end(); - }); - this.span.end(); - } -} diff --git a/src/otel/OTelCallFeedMediaStreamSpan.ts b/src/otel/OTelCallFeedMediaStreamSpan.ts deleted file mode 100644 index 59c780a5..00000000 --- a/src/otel/OTelCallFeedMediaStreamSpan.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { type Span } from "@opentelemetry/api"; -import { - type CallFeedStats, - type TrackStats, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -import { type ElementCallOpenTelemetry } from "./otel"; -import { OTelCallAbstractMediaStreamSpan } from "./OTelCallAbstractMediaStreamSpan"; - -export class OTelCallFeedMediaStreamSpan extends OTelCallAbstractMediaStreamSpan { - private readonly prev: { isAudioMuted: boolean; isVideoMuted: boolean }; - - public constructor( - protected readonly oTel: ElementCallOpenTelemetry, - protected readonly callSpan: Span, - callFeed: CallFeedStats, - ) { - const postFix = - callFeed.type === "local" && callFeed.prefix === "from-call-feed" - ? "(clone)" - : ""; - super(oTel, callSpan, `matrix.call.feed.${callFeed.type}${postFix}`); - this.span.setAttribute("feed.streamId", callFeed.stream); - this.span.setAttribute("feed.type", callFeed.type); - this.span.setAttribute("feed.readFrom", callFeed.prefix); - this.span.setAttribute("feed.purpose", callFeed.purpose); - this.prev = { - isAudioMuted: callFeed.isAudioMuted, - isVideoMuted: callFeed.isVideoMuted, - }; - this.span.addEvent("matrix.call.feed.initState", this.prev); - } - - public update(callFeed: CallFeedStats): void { - if (this.prev.isAudioMuted !== callFeed.isAudioMuted) { - this.span.addEvent("matrix.call.feed.audioMuted", { - isAudioMuted: callFeed.isAudioMuted, - }); - this.prev.isAudioMuted = callFeed.isAudioMuted; - } - if (this.prev.isVideoMuted !== callFeed.isVideoMuted) { - this.span.addEvent("matrix.call.feed.isVideoMuted", { - isVideoMuted: callFeed.isVideoMuted, - }); - this.prev.isVideoMuted = callFeed.isVideoMuted; - } - - const trackStats: TrackStats[] = []; - if (callFeed.video) { - trackStats.push(callFeed.video); - } - if (callFeed.audio) { - trackStats.push(callFeed.audio); - } - this.upsertTrackSpans(trackStats); - } -} diff --git a/src/otel/OTelCallMediaStreamTrackSpan.ts b/src/otel/OTelCallMediaStreamTrackSpan.ts deleted file mode 100644 index c81acd4f..00000000 --- a/src/otel/OTelCallMediaStreamTrackSpan.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { type TrackStats } from "matrix-js-sdk/lib/webrtc/stats/statsReport"; -import opentelemetry, { type Span } from "@opentelemetry/api"; - -import { type ElementCallOpenTelemetry } from "./otel"; - -export class OTelCallMediaStreamTrackSpan { - private readonly span: Span; - private prev: TrackStats; - - public constructor( - protected readonly oTel: ElementCallOpenTelemetry, - protected readonly streamSpan: Span, - data: TrackStats, - ) { - const ctx = opentelemetry.trace.setSpan( - opentelemetry.context.active(), - streamSpan, - ); - const options = { - links: [ - { - context: streamSpan.spanContext(), - }, - ], - }; - const type = `matrix.call.track.${data.label}.${data.kind}`; - this.span = oTel.tracer.startSpan(type, options, ctx); - this.span.setAttribute("track.trackId", data.id); - this.span.setAttribute("track.kind", data.kind); - this.span.setAttribute("track.constrainDeviceId", data.constrainDeviceId); - this.span.setAttribute("track.settingDeviceId", data.settingDeviceId); - this.span.setAttribute("track.label", data.label); - - this.span.addEvent("matrix.call.track.initState", { - readyState: data.readyState, - muted: data.muted, - enabled: data.enabled, - }); - this.prev = data; - } - - public update(data: TrackStats): void { - if (this.prev.muted !== data.muted) { - this.span.addEvent("matrix.call.track.muted", { muted: data.muted }); - } - if (this.prev.enabled !== data.enabled) { - this.span.addEvent("matrix.call.track.enabled", { - enabled: data.enabled, - }); - } - if (this.prev.readyState !== data.readyState) { - this.span.addEvent("matrix.call.track.readyState", { - readyState: data.readyState, - }); - } - this.prev = data; - } - - public end(): void { - this.span.end(); - } -} diff --git a/src/otel/OTelCallTransceiverMediaStreamSpan.ts b/src/otel/OTelCallTransceiverMediaStreamSpan.ts deleted file mode 100644 index 675d793e..00000000 --- a/src/otel/OTelCallTransceiverMediaStreamSpan.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { type Span } from "@opentelemetry/api"; -import { - type TrackStats, - type TransceiverStats, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -import { type ElementCallOpenTelemetry } from "./otel"; -import { OTelCallAbstractMediaStreamSpan } from "./OTelCallAbstractMediaStreamSpan"; - -export class OTelCallTransceiverMediaStreamSpan extends OTelCallAbstractMediaStreamSpan { - private readonly prev: { - direction: string; - currentDirection: string; - }; - - public constructor( - protected readonly oTel: ElementCallOpenTelemetry, - protected readonly callSpan: Span, - stats: TransceiverStats, - ) { - super(oTel, callSpan, `matrix.call.transceiver.${stats.mid}`); - this.span.setAttribute("transceiver.mid", stats.mid); - - this.prev = { - direction: stats.direction, - currentDirection: stats.currentDirection, - }; - this.span.addEvent("matrix.call.transceiver.initState", this.prev); - } - - public update(stats: TransceiverStats): void { - if (this.prev.currentDirection !== stats.currentDirection) { - this.span.addEvent("matrix.call.transceiver.currentDirection", { - currentDirection: stats.currentDirection, - }); - this.prev.currentDirection = stats.currentDirection; - } - if (this.prev.direction !== stats.direction) { - this.span.addEvent("matrix.call.transceiver.direction", { - direction: stats.direction, - }); - this.prev.direction = stats.direction; - } - - const trackStats: TrackStats[] = []; - if (stats.sender) { - trackStats.push(stats.sender); - } - if (stats.receiver) { - trackStats.push(stats.receiver); - } - this.upsertTrackSpans(trackStats); - } -} diff --git a/src/otel/OTelGroupCallMembership.ts b/src/otel/OTelGroupCallMembership.ts deleted file mode 100644 index 668b989c..00000000 --- a/src/otel/OTelGroupCallMembership.ts +++ /dev/null @@ -1,477 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import opentelemetry, { - type Span, - type Attributes, - type Context, -} from "@opentelemetry/api"; -import { - type GroupCall, - type MatrixClient, - type MatrixEvent, - type RoomMember, -} from "matrix-js-sdk"; -import { logger } from "matrix-js-sdk/lib/logger"; -import { - type CallError, - type CallState, - type MatrixCall, - type VoipEvent, -} from "matrix-js-sdk/lib/webrtc/call"; -import { - type CallsByUserAndDevice, - type GroupCallError, - GroupCallEvent, - type GroupCallStatsReport, -} from "matrix-js-sdk/lib/webrtc/groupCall"; -import { - type ConnectionStatsReport, - type ByteSentStatsReport, - type SummaryStatsReport, - type CallFeedReport, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -import { ElementCallOpenTelemetry } from "./otel"; -import { ObjectFlattener } from "./ObjectFlattener"; -import { OTelCall } from "./OTelCall"; - -/** - * Represent the span of time which we intend to be joined to a group call - */ -export class OTelGroupCallMembership { - private callMembershipSpan?: Span; - private groupCallContext?: Context; - private myUserId = "unknown"; - private myDeviceId: string; - private myMember?: RoomMember; - private callsByCallId = new Map(); - private statsReportSpan: { - span: Span | undefined; - stats: OTelStatsReportEvent[]; - }; - private readonly speakingSpans = new Map>(); - - public constructor( - private groupCall: GroupCall, - client: MatrixClient, - ) { - const clientId = client.getUserId(); - if (clientId) { - this.myUserId = clientId; - const myMember = groupCall.room.getMember(clientId); - if (myMember) { - this.myMember = myMember; - } - } - this.myDeviceId = client.getDeviceId() || "unknown"; - this.statsReportSpan = { span: undefined, stats: [] }; - this.groupCall.on(GroupCallEvent.CallsChanged, this.onCallsChanged); - } - - public dispose(): void { - this.groupCall.removeListener( - GroupCallEvent.CallsChanged, - this.onCallsChanged, - ); - } - - public onJoinCall(): void { - if (!ElementCallOpenTelemetry.instance) return; - if (this.callMembershipSpan !== undefined) { - logger.warn("Call membership span is already started"); - return; - } - - // Create the main span that tracks the time we intend to be in the call - this.callMembershipSpan = - ElementCallOpenTelemetry.instance.tracer.startSpan( - "matrix.groupCallMembership", - ); - this.callMembershipSpan.setAttribute( - "matrix.confId", - this.groupCall.groupCallId, - ); - this.callMembershipSpan.setAttribute("matrix.userId", this.myUserId); - this.callMembershipSpan.setAttribute("matrix.deviceId", this.myDeviceId); - this.callMembershipSpan.setAttribute( - "matrix.displayName", - this.myMember ? this.myMember.name : "unknown-name", - ); - - this.groupCallContext = opentelemetry.trace.setSpan( - opentelemetry.context.active(), - this.callMembershipSpan, - ); - - this.callMembershipSpan?.addEvent("matrix.joinCall"); - } - - public onLeaveCall(): void { - if (this.callMembershipSpan === undefined) { - logger.warn("Call membership span is already ended"); - return; - } - - this.callMembershipSpan.addEvent("matrix.leaveCall"); - // and end the span to indicate we've left - this.callMembershipSpan.end(); - this.callMembershipSpan = undefined; - this.groupCallContext = undefined; - } - - public onUpdateRoomState(event: MatrixEvent): void { - if ( - !event || - (!event.getType().startsWith("m.call") && - !event.getType().startsWith("org.matrix.msc3401.call")) - ) { - return; - } - - this.callMembershipSpan?.addEvent( - `matrix.roomStateEvent_${event.getType()}`, - ObjectFlattener.flattenVoipEvent(event.getContent()), - ); - } - - public onCallsChanged(calls: CallsByUserAndDevice): void { - for (const [userId, userCalls] of calls.entries()) { - for (const [deviceId, call] of userCalls.entries()) { - if (!this.callsByCallId.has(call.callId)) { - if (ElementCallOpenTelemetry.instance) { - const span = ElementCallOpenTelemetry.instance.tracer.startSpan( - `matrix.call`, - undefined, - this.groupCallContext, - ); - // XXX: anonymity - span.setAttribute("matrix.call.target.userId", userId); - span.setAttribute("matrix.call.target.deviceId", deviceId); - const displayName = - this.groupCall.room.getMember(userId)?.name ?? "unknown"; - span.setAttribute("matrix.call.target.displayName", displayName); - this.callsByCallId.set( - call.callId, - new OTelCall(userId, deviceId, call, span), - ); - } - } - } - } - - for (const callTrackingInfo of this.callsByCallId.values()) { - const userCalls = calls.get(callTrackingInfo.userId); - if ( - !userCalls || - !userCalls.has(callTrackingInfo.deviceId) || - userCalls.get(callTrackingInfo.deviceId)?.callId !== - callTrackingInfo.call.callId - ) { - callTrackingInfo.end(); - this.callsByCallId.delete(callTrackingInfo.call.callId); - } - } - } - - public onCallStateChange(call: MatrixCall, newState: CallState): void { - const callTrackingInfo = this.callsByCallId.get(call.callId); - if (!callTrackingInfo) { - logger.error(`Got call state change for unknown call ID ${call.callId}`); - return; - } - - callTrackingInfo.span.addEvent("matrix.call.stateChange", { - state: newState, - }); - } - - public onSendEvent(call: MatrixCall, event: VoipEvent): void { - const eventType = event.eventType as string; - if ( - !eventType.startsWith("m.call") && - !eventType.startsWith("org.matrix.call") - ) - return; - - const callTrackingInfo = this.callsByCallId.get(call.callId); - if (!callTrackingInfo) { - logger.error(`Got call send event for unknown call ID ${call.callId}`); - return; - } - - if (event.type === "toDevice") { - callTrackingInfo.span.addEvent( - `matrix.sendToDeviceEvent_${event.eventType}`, - ObjectFlattener.flattenVoipEvent(event), - ); - } else if (event.type === "sendEvent") { - callTrackingInfo.span.addEvent( - `matrix.sendToRoomEvent_${event.eventType}`, - ObjectFlattener.flattenVoipEvent(event), - ); - } - } - - public onReceivedVoipEvent(event: MatrixEvent): void { - // These come straight from CallEventHandler so don't have - // a call already associated (in principle we could receive - // events for calls we don't know about). - const callId = event.getContent().call_id; - if (!callId) { - this.callMembershipSpan?.addEvent("matrix.receive_voip_event_no_callid", { - "sender.userId": event.getSender(), - }); - logger.error("Received call event with no call ID!"); - return; - } - - const call = this.callsByCallId.get(callId); - if (!call) { - this.callMembershipSpan?.addEvent( - "matrix.receive_voip_event_unknown_callid", - { - "sender.userId": event.getSender(), - }, - ); - logger.error("Received call event for unknown call ID " + callId); - return; - } - - call.span.addEvent("matrix.receive_voip_event", { - "sender.userId": event.getSender(), - ...ObjectFlattener.flattenVoipEvent(event.getContent()), - }); - } - - public onToggleMicrophoneMuted(newValue: boolean): void { - this.callMembershipSpan?.addEvent("matrix.toggleMicMuted", { - "matrix.microphone.muted": newValue, - }); - } - - public onSetMicrophoneMuted(setMuted: boolean): void { - this.callMembershipSpan?.addEvent("matrix.setMicMuted", { - "matrix.microphone.muted": setMuted, - }); - } - - public onToggleLocalVideoMuted(newValue: boolean): void { - this.callMembershipSpan?.addEvent("matrix.toggleVidMuted", { - "matrix.video.muted": newValue, - }); - } - - public onSetLocalVideoMuted(setMuted: boolean): void { - this.callMembershipSpan?.addEvent("matrix.setVidMuted", { - "matrix.video.muted": setMuted, - }); - } - - public onToggleScreensharing(newValue: boolean): void { - this.callMembershipSpan?.addEvent("matrix.setVidMuted", { - "matrix.screensharing.enabled": newValue, - }); - } - - public onSpeaking( - member: RoomMember, - deviceId: string, - speaking: boolean, - ): void { - if (speaking) { - // Ensure that there's an audio activity span for this speaker - let deviceMap = this.speakingSpans.get(member); - if (deviceMap === undefined) { - deviceMap = new Map(); - this.speakingSpans.set(member, deviceMap); - } - - if (!deviceMap.has(deviceId)) { - const span = ElementCallOpenTelemetry.instance.tracer.startSpan( - "matrix.audioActivity", - undefined, - this.groupCallContext, - ); - span.setAttribute("matrix.userId", member.userId); - span.setAttribute("matrix.displayName", member.rawDisplayName); - - deviceMap.set(deviceId, span); - } - } else { - // End the audio activity span for this speaker, if any - const deviceMap = this.speakingSpans.get(member); - deviceMap?.get(deviceId)?.end(); - deviceMap?.delete(deviceId); - - if (deviceMap?.size === 0) this.speakingSpans.delete(member); - } - } - - public onCallError(error: CallError, call: MatrixCall): void { - const callTrackingInfo = this.callsByCallId.get(call.callId); - if (!callTrackingInfo) { - logger.error(`Got error for unknown call ID ${call.callId}`); - return; - } - - callTrackingInfo.span.recordException(error); - } - - public onGroupCallError(error: GroupCallError): void { - this.callMembershipSpan?.recordException(error); - } - - public onUndecryptableToDevice(event: MatrixEvent): void { - this.callMembershipSpan?.addEvent("matrix.toDevice.undecryptable", { - "sender.userId": event.getSender(), - }); - } - - public onCallFeedStatsReport( - report: GroupCallStatsReport, - ): void { - if (!ElementCallOpenTelemetry.instance) return; - let call: OTelCall | undefined; - const callId = report.report?.callId; - - if (callId) { - call = this.callsByCallId.get(callId); - } - - if (!call) { - this.callMembershipSpan?.addEvent( - OTelStatsReportType.CallFeedReport + "_unknown_callId", - { - "call.callId": callId, - "call.opponentMemberId": report.report?.opponentMemberId - ? report.report?.opponentMemberId - : "unknown", - }, - ); - logger.error( - `Received ${OTelStatsReportType.CallFeedReport} with unknown call ID: ${callId}`, - ); - return; - } else { - call.onCallFeedStats(report.report.callFeeds); - call.onTransceiverStats(report.report.transceiver); - } - } - - public onConnectionStatsReport( - statsReport: GroupCallStatsReport, - ): void { - this.buildCallStatsSpan( - OTelStatsReportType.ConnectionReport, - statsReport.report, - ); - } - - public onByteSentStatsReport( - statsReport: GroupCallStatsReport, - ): void { - this.buildCallStatsSpan( - OTelStatsReportType.ByteSentReport, - statsReport.report, - ); - } - - public buildCallStatsSpan( - type: OTelStatsReportType, - report: ByteSentStatsReport | ConnectionStatsReport, - ): void { - if (!ElementCallOpenTelemetry.instance) return; - let call: OTelCall | undefined; - const callId = report?.callId; - - if (callId) { - call = this.callsByCallId.get(callId); - } - - if (!call) { - this.callMembershipSpan?.addEvent(type + "_unknown_callid", { - "call.callId": callId, - "call.opponentMemberId": report.opponentMemberId - ? report.opponentMemberId - : "unknown", - }); - logger.error(`Received ${type} with unknown call ID: ${callId}`); - return; - } - const data = ObjectFlattener.flattenReportObject(type, report); - const ctx = opentelemetry.trace.setSpan( - opentelemetry.context.active(), - call.span, - ); - - const options = { - links: [ - { - context: call.span.spanContext(), - }, - ], - }; - - const span = ElementCallOpenTelemetry.instance.tracer.startSpan( - type, - options, - ctx, - ); - - span.setAttribute("matrix.callId", callId ?? "unknown"); - span.setAttribute( - "matrix.opponentMemberId", - report.opponentMemberId ? report.opponentMemberId : "unknown", - ); - span.addEvent("matrix.call.connection_stats_event", data); - span.end(); - } - - public onSummaryStatsReport( - statsReport: GroupCallStatsReport, - ): void { - if (!ElementCallOpenTelemetry.instance) return; - - const type = OTelStatsReportType.SummaryReport; - const data = ObjectFlattener.flattenSummaryStatsReportObject(statsReport); - if (this.statsReportSpan.span === undefined && this.callMembershipSpan) { - const ctx = opentelemetry.trace.setSpan( - opentelemetry.context.active(), - this.callMembershipSpan, - ); - const span = ElementCallOpenTelemetry.instance?.tracer.startSpan( - "matrix.groupCallMembership.summaryReport", - undefined, - ctx, - ); - if (span === undefined) { - return; - } - span.setAttribute("matrix.confId", this.groupCall.groupCallId); - span.setAttribute("matrix.userId", this.myUserId); - span.setAttribute( - "matrix.displayName", - this.myMember ? this.myMember.name : "unknown-name", - ); - span.addEvent(type, data); - span.end(); - } - } -} - -interface OTelStatsReportEvent { - type: OTelStatsReportType; - data: Attributes; -} - -enum OTelStatsReportType { - ConnectionReport = "matrix.call.stats.connection", - ByteSentReport = "matrix.call.stats.byteSent", - SummaryReport = "matrix.stats.summary", - CallFeedReport = "matrix.stats.call_feed", -} diff --git a/src/otel/ObjectFlattener.test.ts b/src/otel/ObjectFlattener.test.ts deleted file mode 100644 index 5685617c..00000000 --- a/src/otel/ObjectFlattener.test.ts +++ /dev/null @@ -1,266 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { type GroupCallStatsReport } from "matrix-js-sdk/lib/webrtc/groupCall"; -import { - type AudioConcealment, - type ByteSentStatsReport, - type ConnectionStatsReport, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; -import { describe, expect, it } from "vitest"; - -import { ObjectFlattener } from "../../src/otel/ObjectFlattener"; - -describe("ObjectFlattener", () => { - const noConcealment: AudioConcealment = { - concealedAudio: 0, - totalAudioDuration: 0, - }; - - const statsReport: GroupCallStatsReport = { - report: { - callId: "callId", - opponentMemberId: "opponentMemberId", - bandwidth: { upload: 426, download: 0 }, - bitrate: { - upload: 426, - download: 0, - audio: { - upload: 124, - download: 0, - }, - video: { - upload: 302, - download: 0, - }, - }, - packetLoss: { - total: 0, - download: 0, - upload: 0, - }, - framerate: { - local: new Map([ - ["LOCAL_AUDIO_TRACK_ID", 0], - ["LOCAL_VIDEO_TRACK_ID", 30], - ]), - remote: new Map([ - ["REMOTE_AUDIO_TRACK_ID", 0], - ["REMOTE_VIDEO_TRACK_ID", 60], - ]), - }, - resolution: { - local: new Map([ - ["LOCAL_AUDIO_TRACK_ID", { height: -1, width: -1 }], - ["LOCAL_VIDEO_TRACK_ID", { height: 460, width: 780 }], - ]), - remote: new Map([ - ["REMOTE_AUDIO_TRACK_ID", { height: -1, width: -1 }], - ["REMOTE_VIDEO_TRACK_ID", { height: 960, width: 1080 }], - ]), - }, - jitter: new Map([ - ["REMOTE_AUDIO_TRACK_ID", 2], - ["REMOTE_VIDEO_TRACK_ID", 50], - ]), - codec: { - local: new Map([ - ["LOCAL_AUDIO_TRACK_ID", "opus"], - ["LOCAL_VIDEO_TRACK_ID", "v8"], - ]), - remote: new Map([ - ["REMOTE_AUDIO_TRACK_ID", "opus"], - ["REMOTE_VIDEO_TRACK_ID", "v9"], - ]), - }, - transport: [ - { - ip: "ff11::5fa:abcd:999c:c5c5:50000", - type: "udp", - localIp: "2aaa:9999:2aaa:999:8888:2aaa:2aaa:7777:50000", - isFocus: true, - localCandidateType: "host", - remoteCandidateType: "host", - networkType: "ethernet", - rtt: NaN, - }, - { - ip: "10.10.10.2:22222", - type: "tcp", - localIp: "10.10.10.100:33333", - isFocus: true, - localCandidateType: "srfx", - remoteCandidateType: "srfx", - networkType: "ethernet", - rtt: 0, - }, - ], - audioConcealment: new Map([ - ["REMOTE_AUDIO_TRACK_ID", noConcealment], - ["REMOTE_VIDEO_TRACK_ID", noConcealment], - ]), - totalAudioConcealment: noConcealment, - }, - }; - - describe("on flattenObjectRecursive", () => { - it("should flatter an Map object", () => { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive( - statsReport.report.resolution, - flatObject, - "matrix.call.stats.connection.resolution.", - 0, - ); - expect(flatObject).toEqual({ - "matrix.call.stats.connection.resolution.local.LOCAL_AUDIO_TRACK_ID.height": - -1, - "matrix.call.stats.connection.resolution.local.LOCAL_AUDIO_TRACK_ID.width": - -1, - - "matrix.call.stats.connection.resolution.local.LOCAL_VIDEO_TRACK_ID.height": 460, - "matrix.call.stats.connection.resolution.local.LOCAL_VIDEO_TRACK_ID.width": 780, - - "matrix.call.stats.connection.resolution.remote.REMOTE_AUDIO_TRACK_ID.height": - -1, - "matrix.call.stats.connection.resolution.remote.REMOTE_AUDIO_TRACK_ID.width": - -1, - - "matrix.call.stats.connection.resolution.remote.REMOTE_VIDEO_TRACK_ID.height": 960, - "matrix.call.stats.connection.resolution.remote.REMOTE_VIDEO_TRACK_ID.width": 1080, - }); - }); - it("should flatter an Array object", () => { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive( - statsReport.report.transport, - flatObject, - "matrix.call.stats.connection.transport.", - 0, - ); - expect(flatObject).toEqual({ - "matrix.call.stats.connection.transport.0.ip": - "ff11::5fa:abcd:999c:c5c5:50000", - "matrix.call.stats.connection.transport.0.type": "udp", - "matrix.call.stats.connection.transport.0.localIp": - "2aaa:9999:2aaa:999:8888:2aaa:2aaa:7777:50000", - "matrix.call.stats.connection.transport.0.isFocus": true, - "matrix.call.stats.connection.transport.0.localCandidateType": "host", - "matrix.call.stats.connection.transport.0.remoteCandidateType": "host", - "matrix.call.stats.connection.transport.0.networkType": "ethernet", - "matrix.call.stats.connection.transport.0.rtt": "NaN", - "matrix.call.stats.connection.transport.1.ip": "10.10.10.2:22222", - "matrix.call.stats.connection.transport.1.type": "tcp", - "matrix.call.stats.connection.transport.1.localIp": - "10.10.10.100:33333", - "matrix.call.stats.connection.transport.1.isFocus": true, - "matrix.call.stats.connection.transport.1.localCandidateType": "srfx", - "matrix.call.stats.connection.transport.1.remoteCandidateType": "srfx", - "matrix.call.stats.connection.transport.1.networkType": "ethernet", - "matrix.call.stats.connection.transport.1.rtt": 0, - }); - }); - }); - - describe("on flattenReportObject Connection Stats", () => { - it("should flatten a Report to otel Attributes Object", () => { - expect( - ObjectFlattener.flattenReportObject( - "matrix.call.stats.connection", - statsReport.report, - ), - ).toEqual({ - "matrix.call.stats.connection.callId": "callId", - "matrix.call.stats.connection.opponentMemberId": "opponentMemberId", - "matrix.call.stats.connection.bandwidth.download": 0, - "matrix.call.stats.connection.bandwidth.upload": 426, - "matrix.call.stats.connection.bitrate.audio.download": 0, - "matrix.call.stats.connection.bitrate.audio.upload": 124, - "matrix.call.stats.connection.bitrate.download": 0, - "matrix.call.stats.connection.bitrate.upload": 426, - "matrix.call.stats.connection.bitrate.video.download": 0, - "matrix.call.stats.connection.bitrate.video.upload": 302, - "matrix.call.stats.connection.codec.local.LOCAL_AUDIO_TRACK_ID": "opus", - "matrix.call.stats.connection.codec.local.LOCAL_VIDEO_TRACK_ID": "v8", - "matrix.call.stats.connection.codec.remote.REMOTE_AUDIO_TRACK_ID": - "opus", - "matrix.call.stats.connection.codec.remote.REMOTE_VIDEO_TRACK_ID": "v9", - "matrix.call.stats.connection.framerate.local.LOCAL_AUDIO_TRACK_ID": 0, - "matrix.call.stats.connection.framerate.local.LOCAL_VIDEO_TRACK_ID": 30, - "matrix.call.stats.connection.framerate.remote.REMOTE_AUDIO_TRACK_ID": 0, - "matrix.call.stats.connection.framerate.remote.REMOTE_VIDEO_TRACK_ID": 60, - "matrix.call.stats.connection.jitter.REMOTE_AUDIO_TRACK_ID": 2, - "matrix.call.stats.connection.jitter.REMOTE_VIDEO_TRACK_ID": 50, - "matrix.call.stats.connection.packetLoss.download": 0, - "matrix.call.stats.connection.packetLoss.total": 0, - "matrix.call.stats.connection.packetLoss.upload": 0, - "matrix.call.stats.connection.resolution.local.LOCAL_AUDIO_TRACK_ID.height": - -1, - "matrix.call.stats.connection.resolution.local.LOCAL_AUDIO_TRACK_ID.width": - -1, - "matrix.call.stats.connection.resolution.local.LOCAL_VIDEO_TRACK_ID.height": 460, - "matrix.call.stats.connection.resolution.local.LOCAL_VIDEO_TRACK_ID.width": 780, - "matrix.call.stats.connection.resolution.remote.REMOTE_AUDIO_TRACK_ID.height": - -1, - "matrix.call.stats.connection.resolution.remote.REMOTE_AUDIO_TRACK_ID.width": - -1, - "matrix.call.stats.connection.resolution.remote.REMOTE_VIDEO_TRACK_ID.height": 960, - "matrix.call.stats.connection.resolution.remote.REMOTE_VIDEO_TRACK_ID.width": 1080, - "matrix.call.stats.connection.transport.0.ip": - "ff11::5fa:abcd:999c:c5c5:50000", - "matrix.call.stats.connection.transport.0.type": "udp", - "matrix.call.stats.connection.transport.0.localIp": - "2aaa:9999:2aaa:999:8888:2aaa:2aaa:7777:50000", - "matrix.call.stats.connection.transport.0.isFocus": true, - "matrix.call.stats.connection.transport.0.localCandidateType": "host", - "matrix.call.stats.connection.transport.0.remoteCandidateType": "host", - "matrix.call.stats.connection.transport.0.networkType": "ethernet", - "matrix.call.stats.connection.transport.0.rtt": "NaN", - "matrix.call.stats.connection.transport.1.ip": "10.10.10.2:22222", - "matrix.call.stats.connection.transport.1.type": "tcp", - "matrix.call.stats.connection.transport.1.localIp": - "10.10.10.100:33333", - "matrix.call.stats.connection.transport.1.isFocus": true, - "matrix.call.stats.connection.transport.1.localCandidateType": "srfx", - "matrix.call.stats.connection.transport.1.remoteCandidateType": "srfx", - "matrix.call.stats.connection.transport.1.networkType": "ethernet", - "matrix.call.stats.connection.transport.1.rtt": 0, - "matrix.call.stats.connection.audioConcealment.REMOTE_AUDIO_TRACK_ID.concealedAudio": 0, - "matrix.call.stats.connection.audioConcealment.REMOTE_AUDIO_TRACK_ID.totalAudioDuration": 0, - "matrix.call.stats.connection.audioConcealment.REMOTE_VIDEO_TRACK_ID.concealedAudio": 0, - "matrix.call.stats.connection.audioConcealment.REMOTE_VIDEO_TRACK_ID.totalAudioDuration": 0, - "matrix.call.stats.connection.totalAudioConcealment.concealedAudio": 0, - "matrix.call.stats.connection.totalAudioConcealment.totalAudioDuration": 0, - }); - }); - }); - - describe("on flattenByteSendStatsReportObject", () => { - const byteSentStatsReport = new Map< - string, - number - >() as ByteSentStatsReport; - byteSentStatsReport.callId = "callId"; - byteSentStatsReport.opponentMemberId = "opponentMemberId"; - byteSentStatsReport.set("4aa92608-04c6-428e-8312-93e17602a959", 132093); - byteSentStatsReport.set("a08e4237-ee30-4015-a932-b676aec894b1", 913448); - - it("should flatten a Report to otel Attributes Object", () => { - expect( - ObjectFlattener.flattenReportObject( - "matrix.call.stats.bytesSend", - byteSentStatsReport, - ), - ).toEqual({ - "matrix.call.stats.bytesSend.4aa92608-04c6-428e-8312-93e17602a959": 132093, - "matrix.call.stats.bytesSend.a08e4237-ee30-4015-a932-b676aec894b1": 913448, - }); - expect(byteSentStatsReport.callId).toEqual("callId"); - expect(byteSentStatsReport.opponentMemberId).toEqual("opponentMemberId"); - }); - }); -}); diff --git a/src/otel/ObjectFlattener.ts b/src/otel/ObjectFlattener.ts deleted file mode 100644 index a963c743..00000000 --- a/src/otel/ObjectFlattener.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ -import { type Attributes } from "@opentelemetry/api"; -import { type VoipEvent } from "matrix-js-sdk/lib/webrtc/call"; -import { type GroupCallStatsReport } from "matrix-js-sdk/lib/webrtc/groupCall"; -import { - type ByteSentStatsReport, - type ConnectionStatsReport, - type SummaryStatsReport, -} from "matrix-js-sdk/lib/webrtc/stats/statsReport"; - -export class ObjectFlattener { - public static flattenReportObject( - prefix: string, - report: ConnectionStatsReport | ByteSentStatsReport, - ): Attributes { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive(report, flatObject, `${prefix}.`, 0); - return flatObject; - } - - public static flattenByteSentStatsReportObject( - statsReport: GroupCallStatsReport, - ): Attributes { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive( - statsReport.report, - flatObject, - "matrix.stats.bytesSent.", - 0, - ); - return flatObject; - } - - public static flattenSummaryStatsReportObject( - statsReport: GroupCallStatsReport, - ): Attributes { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive( - statsReport.report, - flatObject, - "matrix.stats.summary.", - 0, - ); - return flatObject; - } - - /* Flattens out an object into a single layer with components - * of the key separated by dots - */ - public static flattenVoipEvent(event: VoipEvent): Attributes { - const flatObject = {}; - ObjectFlattener.flattenObjectRecursive( - event as unknown as Record, // XXX Types - flatObject, - "matrix.event.", - 0, - ); - - return flatObject; - } - - public static flattenObjectRecursive( - obj: object, - flatObject: Attributes, - prefix: string, - depth: number, - ): void { - if (depth > 10) - throw new Error( - "Depth limit exceeded: aborting VoipEvent recursion. Prefix is " + - prefix, - ); - let entries; - if (obj instanceof Map) { - entries = obj.entries(); - } else { - entries = Object.entries(obj); - } - for (const [k, v] of entries) { - if (["string", "number", "boolean"].includes(typeof v) || v === null) { - let value; - value = v === null ? "null" : v; - value = typeof v === "number" && Number.isNaN(v) ? "NaN" : value; - flatObject[prefix + k] = value; - } else if (typeof v === "object") { - ObjectFlattener.flattenObjectRecursive( - v, - flatObject, - prefix + k + ".", - depth + 1, - ); - } - } - } -} diff --git a/src/otel/otel.test.ts b/src/otel/otel.test.ts deleted file mode 100644 index 0bf0573f..00000000 --- a/src/otel/otel.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2025 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { - expect, - describe, - it, - vi, - beforeEach, - beforeAll, - afterAll, -} from "vitest"; - -import { ElementCallOpenTelemetry } from "./otel"; -import { mockConfig } from "../utils/test"; - -describe("ElementCallOpenTelemetry", () => { - describe("embedded package", () => { - beforeAll(() => { - vi.stubEnv("VITE_PACKAGE", "embedded"); - }); - - beforeEach(() => { - mockConfig({}); - }); - - afterAll(() => { - vi.unstubAllEnvs(); - }); - - it("does not create instance without config value", () => { - ElementCallOpenTelemetry.globalInit(); - expect(ElementCallOpenTelemetry.instance?.isOtlpEnabled).toBe(false); - }); - - it("ignores config value and does not create instance", () => { - mockConfig({ - opentelemetry: { - collector_url: "https://collector.example.com.localhost", - }, - }); - ElementCallOpenTelemetry.globalInit(); - expect(ElementCallOpenTelemetry.instance?.isOtlpEnabled).toBe(false); - }); - }); - - describe("full package", () => { - beforeAll(() => { - vi.stubEnv("VITE_PACKAGE", "full"); - }); - - beforeEach(() => { - mockConfig({}); - }); - - afterAll(() => { - vi.unstubAllEnvs(); - }); - - it("does not create instance without config value", () => { - ElementCallOpenTelemetry.globalInit(); - expect(ElementCallOpenTelemetry.instance?.isOtlpEnabled).toBe(false); - }); - - it("creates instance with config value", () => { - mockConfig({ - opentelemetry: { - collector_url: "https://collector.example.com.localhost", - }, - }); - ElementCallOpenTelemetry.globalInit(); - expect(ElementCallOpenTelemetry.instance?.isOtlpEnabled).toBe(true); - }); - }); -}); diff --git a/src/otel/otel.ts b/src/otel/otel.ts deleted file mode 100644 index 915c3d58..00000000 --- a/src/otel/otel.ts +++ /dev/null @@ -1,117 +0,0 @@ -/* -Copyright 2023, 2024 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE in the repository root for full details. -*/ - -import { - SimpleSpanProcessor, - type SpanProcessor, -} from "@opentelemetry/sdk-trace-base"; -import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"; -import { WebTracerProvider } from "@opentelemetry/sdk-trace-web"; -import opentelemetry, { type Tracer } from "@opentelemetry/api"; -import { resourceFromAttributes } from "@opentelemetry/resources"; -import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions"; -import { logger } from "matrix-js-sdk/lib/logger"; - -import { PosthogSpanProcessor } from "../analytics/PosthogSpanProcessor"; -import { Config } from "../config/Config"; -import { RageshakeSpanProcessor } from "../analytics/RageshakeSpanProcessor"; -import { getRageshakeSubmitUrl } from "../settings/submit-rageshake"; - -const SERVICE_NAME = "element-call"; - -let sharedInstance: ElementCallOpenTelemetry; - -export class ElementCallOpenTelemetry { - private _provider: WebTracerProvider; - private _tracer: Tracer; - private otlpExporter?: OTLPTraceExporter; - public readonly rageshakeProcessor?: RageshakeSpanProcessor; - - public static globalInit(): void { - // this is only supported in the full package as the is currently no support for passing in the collector URL from the widget host - const collectorUrl = - import.meta.env.VITE_PACKAGE === "full" - ? Config.get().opentelemetry?.collector_url - : undefined; - // we always enable opentelemetry in general. We only enable the OTLP - // collector if a URL is defined (and in future if another setting is defined) - // Posthog reporting is enabled or disabled - // within the posthog code. - const shouldEnableOtlp = Boolean(collectorUrl); - - if (!sharedInstance || sharedInstance.isOtlpEnabled !== shouldEnableOtlp) { - logger.info("(Re)starting OpenTelemetry debug reporting"); - sharedInstance?.dispose(); - - sharedInstance = new ElementCallOpenTelemetry( - collectorUrl, - getRageshakeSubmitUrl(), - ); - } - } - - public static get instance(): ElementCallOpenTelemetry { - return sharedInstance; - } - - private constructor( - collectorUrl: string | undefined, - rageshakeUrl: string | undefined, - ) { - const spanProcessors: SpanProcessor[] = []; - - if (collectorUrl) { - logger.info("Enabling OTLP collector with URL " + collectorUrl); - this.otlpExporter = new OTLPTraceExporter({ - url: collectorUrl, - }); - spanProcessors.push(new SimpleSpanProcessor(this.otlpExporter)); - } else { - logger.info("OTLP collector disabled"); - } - - if (rageshakeUrl) { - this.rageshakeProcessor = new RageshakeSpanProcessor(); - spanProcessors.push(this.rageshakeProcessor); - } - - spanProcessors.push(new PosthogSpanProcessor()); - - this._provider = new WebTracerProvider({ - resource: resourceFromAttributes({ - // This is how we can make Jaeger show a reasonable service in the dropdown on the left. - [ATTR_SERVICE_NAME]: SERVICE_NAME, - }), - spanProcessors, - }); - - opentelemetry.trace.setGlobalTracerProvider(this._provider); - this._tracer = opentelemetry.trace.getTracer( - // This is not the serviceName shown in jaeger - "my-element-call-otl-tracer", - ); - } - - public dispose(): void { - opentelemetry.trace.disable(); - this._provider?.shutdown().catch((e) => { - logger.error("Failed to shutdown OpenTelemetry", e); - }); - } - - public get isOtlpEnabled(): boolean { - return Boolean(this.otlpExporter); - } - - public get tracer(): Tracer { - return this._tracer; - } - - public get provider(): WebTracerProvider { - return this._provider; - } -} diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index b17d3aae..72a35da6 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -48,7 +48,6 @@ import { useCallViewKeyboardShortcuts } from "../useCallViewKeyboardShortcuts"; import { ElementWidgetActions, widget } from "../widget"; import styles from "./InCallView.module.css"; import { GridTile } from "../tile/GridTile"; -import { type OTelGroupCallMembership } from "../otel/OTelGroupCallMembership"; import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal"; import { useRageshakeRequestModal } from "../settings/submit-rageshake"; import { RageshakeRequestModal } from "./RageshakeRequestModal"; @@ -180,7 +179,6 @@ export interface InCallViewProps { matrixRoom: MatrixRoom; muteStates: MuteStates; header: HeaderStyle; - otelGroupCallMembership?: OTelGroupCallMembership; onShareClick: (() => void) | null; } diff --git a/src/settings/submit-rageshake.ts b/src/settings/submit-rageshake.ts index bfd55126..276d8e60 100644 --- a/src/settings/submit-rageshake.ts +++ b/src/settings/submit-rageshake.ts @@ -17,7 +17,6 @@ import { type CryptoApi } from "matrix-js-sdk/lib/crypto-api"; import { getLogsForReport } from "./rageshake"; import { useClient } from "../ClientContext"; import { Config } from "../config/Config"; -import { ElementCallOpenTelemetry } from "../otel/otel"; import { type RageshakeRequestModal } from "../room/RageshakeRequestModal"; import { getUrlParams } from "../UrlParams"; @@ -274,14 +273,6 @@ export function useSubmitRageshake( for (const entry of logs) { body.append("compressed-log", await gzip(entry.lines), entry.id); } - - body.append( - "file", - await gzip( - ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump(), - ), - "traces.json.gz", - ); } if (opts.rageshakeRequestId) {