feat: Integrate OpenTelemetry for distributed tracing in both frontend and backend applications.
This commit is contained in:
@@ -9,6 +9,8 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import org.slf4j.MDC;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
||||
/**
|
||||
* Interceptor: извлекает поддомен из Host header и кладёт в TenantContext.
|
||||
@@ -48,6 +50,8 @@ public class TenantInterceptor implements HandlerInterceptor {
|
||||
// (нужно чтобы админ мог добавить тенант даже если его домен не настроен)
|
||||
if (path.startsWith("/api/database")) {
|
||||
TenantContext.setCurrentTenant(tenant);
|
||||
MDC.put("tenant.id", tenant);
|
||||
Span.current().setAttribute("tenant.id", tenant);
|
||||
log.debug("Database API request, tenant '{}' (no strict check)", tenant);
|
||||
return true;
|
||||
}
|
||||
@@ -66,6 +70,8 @@ public class TenantInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
TenantContext.setCurrentTenant(tenant);
|
||||
MDC.put("tenant.id", tenant);
|
||||
Span.current().setAttribute("tenant.id", tenant);
|
||||
log.debug("Resolved tenant '{}' from Host '{}'", tenant, host);
|
||||
return true;
|
||||
}
|
||||
@@ -73,6 +79,7 @@ public class TenantInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
TenantContext.clear();
|
||||
MDC.remove("tenant.id");
|
||||
}
|
||||
|
||||
private String resolveTenant(String host) {
|
||||
|
||||
Reference in New Issue
Block a user