Thank you for your help and sorry for taking your time.
I'm beginner at drf-api-logger, I would like everyone to help me to find this problem.
Problem:
The drf-api-logger did not write any data to database when it's not local environment (but other endpoints are written). But request body's data was committed to database at table metrics
It's happen on endpoint POST /metrics
What I try:
I tried to debug it on my local environment by insert print to each every line at __call___ on /drf_api_logger/middleware/api_logger_middleware.py
Make a request to POST /metrics
Result is it reaches to LOGGER_THREAD.put_log_data(data=d) inside if LOGGER_THREAD: with valid data from request/response body.
Quesitons:
How can I debug it on another environment?
For settings, view and serializer of /metrics
file: settings.py
class MetricDataSerializer(serializers.Serializer):
{fields}
def create(self, validated_data):
for data in validated_data:
Metric.objects.create(
{fields}
)
return len(validated_data)
class MetricInfoSerializer(serializers.Serializer):
{fields}
data = MetricDataSerializer(many=True)
def create(self, validated_data):
{fields}
return dict(
message="OK",
data_size=created_size,
send_time=validated_data.get("send_time"),
data=[],
)
file: MyCustomAuthen
from rest_framework.authentication import TokenAuthentication
from rest_framework import HTTP_HEADER_ENCODING, exceptions
from django.utils.translation import gettext_lazy as _
class MyCustomAuthen(TokenAuthentication):
def authenticate(self, request):
auth = request.META.get("HTTP_AUTHORIZATION", b"")
if not auth:
msg = _("Invalid token header. No credentials provided.")
raise exceptions.AuthenticationFailed(msg)
(_key, _token) = auth.split()
if not _key and not _token:
msg = _("Invalid token")
raise exceptions.AuthenticationFailed(msg)
if _key.lower() != self.keyword.lower():
msg = _("Invalid token")
raise exceptions.AuthenticationFailed(msg)
return self.authenticate_credentials(_token, request)
def authenticate_credentials(self, key, request):
try:
ip = self.get_client_ip(request)
token = get_token(key)
except:
raise exceptions.AuthenticationFailed(_("Invalid token."))
return (token.name, token)
def get_client_ip(self, request):
"""
Get the client's IP address from the request.
"""
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
if x_forwarded_for:
ip = x_forwarded_for.split(",")[0]
else:
ip = request.META.get("REMOTE_ADDR")
return ip
Hi everyone,
Thank you for your help and sorry for taking your time. I'm beginner at drf-api-logger, I would like everyone to help me to find this problem.
Problem: The drf-api-logger did not write any data to database when it's not local environment (but other endpoints are written). But request body's data was committed to database at table
metrics
It's happen on endpointPOST /metrics
What I try:
/drf_api_logger/middleware/api_logger_middleware.py
POST /metrics
Result is it reaches to
LOGGER_THREAD.put_log_data(data=d)
insideif LOGGER_THREAD:
with valid data from request/response body.Quesitons:
For settings, view and serializer of
/metrics
file: settings.pyfile: views/metric.py
file: serializers/metric.py
file: MyCustomAuthen
request body schema: