Merge pull request #1028 from toger5/otel_read_through
Remove duplicated code in OpenTelemetry files
This commit is contained in:
commit
836c3b5614
3 changed files with 22 additions and 48 deletions
|
@ -45,48 +45,6 @@ import { ElementCallOpenTelemetry } from "./otel";
|
||||||
import { ObjectFlattener } from "./ObjectFlattener";
|
import { ObjectFlattener } from "./ObjectFlattener";
|
||||||
import { OTelCall } from "./OTelCall";
|
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
|
* 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(
|
this.callMembershipSpan?.addEvent(
|
||||||
`matrix.roomStateEvent_${event.getType()}`,
|
`matrix.roomStateEvent_${event.getType()}`,
|
||||||
flattenVoipEvent(event.getContent())
|
ObjectFlattener.flattenVoipEvent(event.getContent())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,12 +205,12 @@ export class OTelGroupCallMembership {
|
||||||
if (event.type === "toDevice") {
|
if (event.type === "toDevice") {
|
||||||
callTrackingInfo.span.addEvent(
|
callTrackingInfo.span.addEvent(
|
||||||
`matrix.sendToDeviceEvent_${event.eventType}`,
|
`matrix.sendToDeviceEvent_${event.eventType}`,
|
||||||
flattenVoipEvent(event)
|
ObjectFlattener.flattenVoipEvent(event)
|
||||||
);
|
);
|
||||||
} else if (event.type === "sendEvent") {
|
} else if (event.type === "sendEvent") {
|
||||||
callTrackingInfo.span.addEvent(
|
callTrackingInfo.span.addEvent(
|
||||||
`matrix.sendToRoomEvent_${event.eventType}`,
|
`matrix.sendToRoomEvent_${event.eventType}`,
|
||||||
flattenVoipEvent(event)
|
ObjectFlattener.flattenVoipEvent(event)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,7 +242,7 @@ export class OTelGroupCallMembership {
|
||||||
|
|
||||||
call.span.addEvent("matrix.receive_voip_event", {
|
call.span.addEvent("matrix.receive_voip_event", {
|
||||||
"sender.userId": event.getSender(),
|
"sender.userId": event.getSender(),
|
||||||
...flattenVoipEvent(event.getContent()),
|
...ObjectFlattener.flattenVoipEvent(event.getContent()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { Attributes } from "@opentelemetry/api";
|
import { Attributes } from "@opentelemetry/api";
|
||||||
|
import { VoipEvent } from "matrix-js-sdk/src/webrtc/call";
|
||||||
import { GroupCallStatsReport } from "matrix-js-sdk/src/webrtc/groupCall";
|
import { GroupCallStatsReport } from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
import {
|
import {
|
||||||
ByteSentStatsReport,
|
ByteSentStatsReport,
|
||||||
|
@ -61,6 +62,21 @@ export class ObjectFlattener {
|
||||||
return flatObject;
|
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(
|
public static flattenObjectRecursive(
|
||||||
obj: Object,
|
obj: Object,
|
||||||
flatObject: Attributes,
|
flatObject: Attributes,
|
||||||
|
|
|
@ -42,7 +42,7 @@ export class ElementCallOpenTelemetry {
|
||||||
const config = Config.get();
|
const config = Config.get();
|
||||||
// we always enable opentelemetry in general. We only enable the OTLP
|
// 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)
|
// 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.
|
// within the posthog code.
|
||||||
const shouldEnableOtlp = Boolean(config.opentelemetry?.collector_url);
|
const shouldEnableOtlp = Boolean(config.opentelemetry?.collector_url);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ export class ElementCallOpenTelemetry {
|
||||||
collectorUrl: string | undefined,
|
collectorUrl: string | undefined,
|
||||||
rageshakeUrl: 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 = {
|
const providerConfig = {
|
||||||
resource: new Resource({
|
resource: new Resource({
|
||||||
[SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,
|
[SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,
|
||||||
|
|
Loading…
Add table
Reference in a new issue