Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adrys-lab opened this issue Feb 7, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@adrys-lab
Copy link

adrys-lab commented Feb 7, 2025

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 adrys-lab added the bug Something isn't working label Feb 7, 2025
@adrys-lab adrys-lab changed the title [BUG]: Trace is marked as error even though tagging it as error false [BUG]: Trace is marked as error even despite tagging trace as error false Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant