Fix tracing causing issues

This commit is contained in:
MTRNord
2023-09-03 11:50:20 +02:00
parent 0add0aa78c
commit 2d12e5cbc0
3 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -146,7 +146,7 @@ export class MjolnirAppService {
* @param context Additional context for the Matrix event.
*/
@trace
public async onEvent(request: Request<WeakEvent>, context: BridgeContext, parentSpan: Span | undefined) {
public async onEvent(request: Request<WeakEvent>, context: BridgeContext) {
const activeSpan = api.trace.getSpan(api.context.active())
const mxEvent = request.getData();
// Provision a new mjolnir for the invitee when the appservice bot (designated by this.bridge.botUserId) is invited to a room.
@@ -156,12 +156,12 @@ export class MjolnirAppService {
log.info(`${mxEvent.sender} has sent an invitation to the appservice bot ${this.bridge.botUserId}, attempting to provision them a mjolnir`);
try {
await this.mjolnirManager.provisionNewMjolnir(mxEvent.sender)
parentSpan?.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.PROVISION_OUTCOME, DRAUPNIR_RESULT.SUCCESS);
activeSpan?.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.PROVISION_OUTCOME, DRAUPNIR_RESULT.SUCCESS);
// Send a notive that the invite must be accepted
await this.bridge.getBot().getClient().sendText(mxEvent.room_id, "Please accept the invites to the newly provisioned rooms. These will be the home of your Draupnir Instance. This room will not be used in the future.");
} catch (e: any) {
log.error(`Failed to provision a mjolnir for ${mxEvent.sender} after they invited ${this.bridge.botUserId}:`, e, { traceId: activeSpan?.spanContext().traceId });
parentSpan?.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.PROVISION_OUTCOME, DRAUPNIR_RESULT.FAILURE);
activeSpan?.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.PROVISION_OUTCOME, DRAUPNIR_RESULT.FAILURE);
// continue, we still want to reject this invitation.
// Send a notive that the invite must be accepted
await this.bridge.getBot().getClient().sendText(mxEvent.room_id, "Please make sure you are allowed to provision a bot. Otherwise notify the admin please. The provisioning request was rejected.");
@@ -39,7 +39,7 @@ import { CommandInvocationRecord, InterfaceAcceptor, PromptableArgumentStream, P
import { ParameterDescription } from "./ParameterParsing";
import { matrixPromptForAccept } from "./MatrixPromptForAccept";
import { trace } from "../../utils";
import { Span } from "@opentelemetry/api";
import * as api from "@opentelemetry/api";
import { DRAUPNIR_SYSTEM_TYPES, DRAUPNIR_TRACING_ATTRIBUTES } from "../../tracer";
export interface MatrixContext {
@@ -77,8 +77,8 @@ export class MatrixInterfaceAdaptor<C extends MatrixContext, ExecutorType extend
@trace
public async invoke(executorContext: ThisParameterType<ExecutorType>, matrixContext: C, ...args: ReadItem[]): Promise<void> {
// The span is always the last element due to order of args. And since we try to hide it we dont have it in the type and need to go via unknown here.
const parentSpan: Span = args.pop() as unknown as Span;
parentSpan.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.SYSTEM, DRAUPNIR_SYSTEM_TYPES.BOT);
const activeSpan = api.trace.getSpan(api.context.active())
activeSpan.setAttribute(DRAUPNIR_TRACING_ATTRIBUTES.SYSTEM, DRAUPNIR_SYSTEM_TYPES.BOT);
const invocationRecord = new MatrixInvocationRecord<ThisParameterType<ExecutorType>>(this.interfaceCommand, executorContext, matrixContext);
const stream = new PromptableArgumentStream(args, this, invocationRecord);
const executorResult: Awaited<ReturnType<typeof this.interfaceCommand.parseThenInvoke>> = await this.interfaceCommand.parseThenInvoke(executorContext, stream);
+3 -3
View File
@@ -522,7 +522,7 @@ export function trace(originalMethod: any, { name }: ClassMethodDecoratorContext
);
return tracer.startActiveSpan(spanName, async (parentSpan: Span) => {
const result = await originalMethod.call(this, ...args, parentSpan);
const result = await originalMethod.call(this, ...args);
parentSpan.end();
return result;
});
@@ -534,7 +534,7 @@ export function trace(originalMethod: any, { name }: ClassMethodDecoratorContext
);
return tracer.startActiveSpan(spanName, (parentSpan: Span) => {
const result = originalMethod.call(this, ...args, parentSpan);
const result = originalMethod.call(this, ...args);
parentSpan.end();
return result;
});
@@ -570,7 +570,7 @@ export function independentTrace(originalMethod: any, { name }: ClassMethodDecor
);
const span = tracer.startSpan(spanName);
const result = originalMethod.call(this, ...args, span);
const result = originalMethod.call(this, ...args);
span.end();
return result;
};