From 2d12e5cbc055b4e3c839e9afd51accdb014029cc Mon Sep 17 00:00:00 2001 From: MTRNord Date: Sun, 3 Sep 2023 11:50:20 +0200 Subject: [PATCH] Fix tracing causing issues --- src/appservice/AppService.ts | 6 +++--- src/commands/interface-manager/MatrixInterfaceAdaptor.ts | 6 +++--- src/utils.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/appservice/AppService.ts b/src/appservice/AppService.ts index 5928cbc1..773f7751 100644 --- a/src/appservice/AppService.ts +++ b/src/appservice/AppService.ts @@ -146,7 +146,7 @@ export class MjolnirAppService { * @param context Additional context for the Matrix event. */ @trace - public async onEvent(request: Request, context: BridgeContext, parentSpan: Span | undefined) { + public async onEvent(request: Request, 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."); diff --git a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts index 8a4b01ef..9e2036bc 100644 --- a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts +++ b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts @@ -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, matrixContext: C, ...args: ReadItem[]): Promise { // 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>(this.interfaceCommand, executorContext, matrixContext); const stream = new PromptableArgumentStream(args, this, invocationRecord); const executorResult: Awaited> = await this.interfaceCommand.parseThenInvoke(executorContext, stream); diff --git a/src/utils.ts b/src/utils.ts index d8e5558f..a43567bd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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; };