http-headers
X-Request-ID
수색…
소개
X-Request-ID 헤더는 클라이언트에서 서버 및 백엔드로 웹 서비스 (예 : REST API)에 대한 개별 요청을 추적하는 데 사용할 수 있습니다.
통사론
- X-Request-ID : <값>
비고
클라이언트는 HTTP 헤더 X-Request-ID: some-value 보낼 수 있습니다. 서버는 제공된 값을 사용하여 초기 요청을 제공하기 위해 서비스를 백엔드하는 모든 요청에 제공해야합니다. 응답을 보낼 때 서버는 동일한 헤더를 클라이언트에 반환합니다. 추적을 위해 서버는 로그에 값을 포함시켜 해당 로그와의 상관 관계 요청 및 응답을 가능하게합니다.
nginx
역방향 프록시는 클라이언트가 X-Request-ID 헤더를 제공하는지 여부를 감지하여이를 백엔드 서버로 전달합니다. 헤더가 제공되지 않으면 임의의 값을 제공 할 수 있습니다.
map $http_x_request_id $reqid {
default $http_x_request_id;
"" $request_id;
}
위의 코드는 요청 ID를 변수 $reqid 에 저장하고 이후에 로그에서 사용할 수 있습니다.
log_format trace '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
'"$http_x_forwarded_for" $reqid';
또한 백엔드 서비스로 전달되어야합니다.
location @proxy_to_app {
proxy_set_header X-Request-ID $reqid;
proxy_pass http://backend;
access_log /var/log/nginx/access_trace.log trace;
}
헤로 꾸
Heroku는 항상 클라이언트가 보내는 X-Request-ID 헤더를 전달하거나 자체 헤더를 생성합니다.
HTTP 요청 ID의 설명서를 참조하십시오.
장고
Django를 웹 서비스 프레임 워크로 사용할 때 패키지 django-log-request-id 를 사용하여 요청 ID를 구문 분석하고 기록 할 수 있습니다.
설정
MIDDLEWARE_CLASSES = (
'log_request_id.middleware.RequestIDMiddleware',
# ... other middleware goes here
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'request_id': {
'()': 'log_request_id.filters.RequestIDFilter'
}
},
'formatters': {
'standard': {
'format': '%(levelname)-8s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'filters': ['request_id'],
'formatter': 'standard',
},
},
'loggers': {
'myapp': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}
}
요청 ID (요청 / 응답)
동일한 X-Request-ID 헤더는 요청의 클라이언트 나 응답의 서버에서 보낼 수 있습니다.
X-Request-ID: f9ed4675f1c53513c61a3b3b4e25b4c0
이 값은 고유의의 L를 가지지 않지만, 상호 연관된 요청 W 응답을 식별하는 토큰입니다.
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow