otel read through code

This commit is contained in:
Timo K 2023-04-27 14:00:27 +02:00
parent e3a3859739
commit ecf5f9916c
3 changed files with 22 additions and 48 deletions

View File

@ -45,48 +45,6 @@ import { ElementCallOpenTelemetry } from "./otel";
import { ObjectFlattener } from "./ObjectFlattener";
import { OTelCall } from "./OTelCall";
/**
* Flattens out an object into a single layer with components
* of the key separated by dots
*/
function flattenVoipEvent(event: VoipEvent): Attributes {
const flatObject = {};
flattenVoipEventRecursive(
event as unknown as Record<string, unknown>, // XXX Types
flatObject,
"matrix.event.",
0
);
return flatObject;
}
function flattenVoipEventRecursive(
obj: Record<string, unknown>,
flatObject: Record<string, unknown>,
prefix: string,
depth: number
) {
if (depth > 10)
throw new Error(
"Depth limit exceeded: aborting VoipEvent recursion. Prefix is " + prefix
);
for (const [k, v] of Object.entries(obj)) {
if (["string", "number", "boolean"].includes(typeof v) || v === null) {
flatObject[prefix + k] = v;
} else if (typeof v === "object") {
flattenVoipEventRecursive(
v as Record<string, unknown>,
flatObject,
prefix + k + ".",
depth + 1
);
}
}
}
/**
* Represent the span of time which we intend to be joined to a group call
*/
@ -179,7 +137,7 @@ export class OTelGroupCallMembership {
this.callMembershipSpan?.addEvent(
`matrix.roomStateEvent_${event.getType()}`,
flattenVoipEvent(event.getContent())
ObjectFlattener.flattenVoipEvent(event.getContent())
);
}
@ -247,12 +205,12 @@ export class OTelGroupCallMembership {
if (event.type === "toDevice") {
callTrackingInfo.span.addEvent(
`matrix.sendToDeviceEvent_${event.eventType}`,
flattenVoipEvent(event)
ObjectFlattener.flattenVoipEvent(event)
);
} else if (event.type === "sendEvent") {
callTrackingInfo.span.addEvent(
`matrix.sendToRoomEvent_${event.eventType}`,
flattenVoipEvent(event)
ObjectFlattener.flattenVoipEvent(event)
);
}
}
@ -284,7 +242,7 @@ export class OTelGroupCallMembership {
call.span.addEvent("matrix.receive_voip_event", {
"sender.userId": event.getSender(),
...flattenVoipEvent(event.getContent()),
...ObjectFlattener.flattenVoipEvent(event.getContent()),
});
}

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { Attributes } from "@opentelemetry/api";
import { VoipEvent } from "matrix-js-sdk/src/webrtc/call";
import { GroupCallStatsReport } from "matrix-js-sdk/src/webrtc/groupCall";
import {
ByteSentStatsReport,
@ -61,6 +62,21 @@ export class ObjectFlattener {
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<string, unknown>, // XXX Types
flatObject,
"matrix.event.",
0
);
return flatObject;
}
public static flattenObjectRecursive(
obj: Object,
flatObject: Attributes,

View File

@ -42,7 +42,7 @@ export class ElementCallOpenTelemetry {
const config = Config.get();
// 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)
// The posthog exporteer is always enabled, posthog reporting is enabled or disabled
// The posthog exporter is always enabled, posthog reporting is enabled or disabled
// within the posthog code.
const shouldEnableOtlp = Boolean(config.opentelemetry?.collector_url);
@ -65,7 +65,7 @@ export class ElementCallOpenTelemetry {
collectorUrl: string | undefined,
rageshakeUrl: string | undefined
) {
// This is how we can make Jaeger show a reaonsable service in the dropdown on the left.
// This is how we can make Jaeger show a reasonable service in the dropdown on the left.
const providerConfig = {
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,