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

Possibility to specify custom header name for bounded request_id #324

Closed
badziyoussef opened this issue Sep 28, 2023 · 7 comments
Closed
Labels
how to How to do some specific use case with django-structlog

Comments

@badziyoussef
Copy link
Contributor

badziyoussef commented Sep 28, 2023

The application could be behind aws elb, that use a non customisable trace_id X-Amzn-Trace-Id, if we can specify request header name from settings, we can use same id generated by aws across all logs. What do you think?

@jrobichaud
Copy link
Owner

can it be achieved using bind_extra_request_metadata signal?

@jrobichaud
Copy link
Owner

I am not sure if you mean a request header to bind to the logs or return a an ID in a header in the response.

@badziyoussef
Copy link
Contributor Author

badziyoussef commented Sep 28, 2023

I am not sure if you mean a request header to bind to the logs or return a an ID in a header in the response.

Talking about this part of code

        request_id = get_request_header( 
             request, "x-request-id", "HTTP_X_REQUEST_ID" 
         ) or str(uuid.uuid4())

if the x-request-id could be customized

@badziyoussef
Copy link
Contributor Author

The idea is to use the traceId generated by the elb as request-id, which sometimes have a custom name, not always named x-request-id

@jrobichaud
Copy link
Owner

You can technically do this:

from django.contrib.sites.shortcuts import get_current_site
from django.dispatch import receiver
from django_structlog import signals
import structlog

@receiver(signals.bind_extra_request_metadata)
def bind_custom_id(request, logger, **kwargs):
    my_custom_id = "hey"
    structlog.contextvars.bind_contextvars(request_id=my_custom_id)

@badziyoussef
Copy link
Contributor Author

You can technically do this:

from django.contrib.sites.shortcuts import get_current_site
from django.dispatch import receiver
from django_structlog import signals
import structlog

@receiver(signals.bind_extra_request_metadata)
def bind_custom_id(request, logger, **kwargs):
    my_custom_id = "hey"
    structlog.contextvars.bind_contextvars(request_id=my_custom_id)

Yes I know, ok I will go with that, thank you.

@badziyoussef badziyoussef closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@jrobichaud
Copy link
Owner

I am considering to add a section "How-To Guides" with these different use-cases I saw over time (#325).

@jrobichaud jrobichaud added the how to How to do some specific use case with django-structlog label Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
how to How to do some specific use case with django-structlog
Projects
None yet
Development

No branches or pull requests

2 participants