dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

[BUG]: Trace is marked as error even despite tagging trace as error false

Open adrys-lab opened this issue 1 year ago • 1 comments

Tracer Version(s)

5.24.0

Node.js Version(s)

20

Bug Report

We want to mark our traces which end up in a business error, as NOT ERROR, even though we tried several options, we don't succeed on not flagging them as errored traces.

notice we are using graphQLMiddleware, and although we are throwing an error, we are trying to span?.finish()

can you please help us ?

thank you in advance

´´´

      export const handler = graphQLMiddleware(
        async (
          graphqlRequest: GraphQLRequest | GraphQLRequest[],
          context: AWSLambda.Context,
        ): Promise<BaseGraphQLResponse<unknown>> => {

      const controller = resolvers[requestQuery.parentTypeName][
            requestQuery.fieldName
          ] as BaseController<
            AppSyncIdentityCognito | LambdaIamIdentity,
            BaseGraphQLRequestArguments,
            BaseGraphQLRequestSource,
            unknown
          >;

      return await tracer.trace(
            "contacts.graphql",
            {
              resource: `myQuery`,
              type: "graphql",
            },
            async (span) => {
              try {
                const response = await controller.call({
                  args,
                  identity,
                  source,
                });
    
      logger.info("[HANDLER - GRAPHQL] - OUTGOING_REQUEST", {
        output: { response },
      });

      return response;
    } catch (error) {
      let errorToHandle: GraphQLError;

      if (
        error instanceof ValidationError ||
        error instanceof RequestValidationError
      ) {
        errorToHandle = GraphQLError.BadRequest(request);
      } else if (error instanceof EntityNotFoundError) {
        errorToHandle = GraphQLError.NotFound(
          controller.constructor.name.toString(),
          request,
        );
      } else {
        errorToHandle = GraphQLError.InternalServerError(request, error);
      }

      const logLevel = errorToHandle.is5XX() ? "error" : "warn";
      logger[logLevel]("[CONTROLLER][GRAPHQL] - ERROR", {
        error: (error as Error).message,
        stack: (error as Error).stack,
      });

      span?.setTag("error.name", errorToHandle.name);
      span?.setTag("error.status", errorToHandle.status);

      if (logLevel === "warn") {
        span?.setTag("error.level", "warning");
        span?.setTag("error", false);
      } else {
        span?.setTag("error", true);
      }

      span?.finish();
      throw errorToHandle.error;
    }
  },
);

´´´

Reproduction Code

No response

Error Logs

No response

Tracer Config

No response

Operating System

No response

Bundling

ESBuild

adrys-lab avatar Feb 07 '25 11:02 adrys-lab

@adrys-lab could you please reach out to our support to request this as feature?

We currently do not support it and that way it can be prioritized higher.

BridgeAR avatar May 08 '25 04:05 BridgeAR