chore: added errorcode and exception to http_server_requests for better slo (#38892)

## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13107852244>
> Commit: cc763a76e87863bb806b9740d8c7d239d8f02af8
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13107852244&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 03 Feb 2025 07:58:57 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Observability Improvements**
	- Enhanced error tracking and monitoring capabilities
	- Added detailed error context for server request observations
- Improved error information logging with specific error codes and
titles
- Introduced a new constant for representing a "none" state in the
application
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Apeksha Bhosale 2025-02-03 13:50:56 +05:30 committed by GitHub
parent 9bd1a40513
commit 2a35c93311
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.appsmith.server.configurations;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.exceptions.AppsmithException;
import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention;
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention;
@Configuration
public class ObservationConfig {
@Bean
public ServerRequestObservationConvention customObservationConvention() {
return new DefaultServerRequestObservationConvention() {
@Override
public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) {
KeyValues keyValues = super.getLowCardinalityKeyValues(context);
// Extract error code safely
String errorCode = context.getError() != null && context.getError() instanceof AppsmithException
? (((AppsmithException) context.getError()).getAppErrorCode())
: FieldName.NONE;
String errorTitle = context.getError() != null && context.getError() instanceof AppsmithException
? (((AppsmithException) context.getError()).getTitle())
: FieldName.NONE;
return keyValues.and(KeyValue.of("errorCode", errorCode)).and(KeyValue.of("exception", errorTitle));
}
};
}
}

View File

@ -203,4 +203,5 @@ public class FieldNameCE {
public static final String ARTIFACT_CONTEXT = "artifactContext";
public static final String ARTIFACT_ID = "artifactId";
public static final String BODY = "body";
public static final String NONE = "none";
}

View File

@ -10,6 +10,7 @@ import com.appsmith.server.helpers.CommonGitFileUtils;
import com.appsmith.server.helpers.RedisUtils;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.SessionUserService;
import io.micrometer.common.KeyValue;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -17,6 +18,7 @@ import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.LockFailedException;
import org.springframework.core.io.buffer.DataBufferLimitException;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ControllerAdvice;
@ -84,6 +86,12 @@ public class GlobalExceptionHandler {
e.getAppErrorCode(), e.getErrorType(), e.getMessage(), e.getTitle(), e.getReferenceDoc()));
}
ServerRequestObservationContext.findCurrent(exchange.getAttributes()).ifPresent(context -> {
context.setError(e);
context.addLowCardinalityKeyValue(KeyValue.of("errorCode", e.getAppErrorCode()));
context.addLowCardinalityKeyValue(KeyValue.of("exception", e.getTitle()));
});
return getResponseDTOMono(urlPath, response);
}