-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Send trace context with logs from web applications #3448
Changes from 1 commit
9a20be9
cf283c4
583d076
5be368e
28e3a6c
cdc96b4
fb83ab6
9a20c4e
f8b7e65
65efdcd
f78cc2e
33b92dd
5cc798f
6ef3f49
14c2545
199ada0
425c8ef
1047fd5
46012eb
43148bf
de02a1d
ffb57c4
8fd8f31
4480027
ad00bdb
8ed81ad
a6b25bb
6123764
3caccc7
4589a06
2889cfc
53738d7
1957077
bf683f7
51cdb39
2479d91
6c04196
f70c84e
6fc4b21
2106bfc
c66fc31
035c4a7
bd8c1b4
51bf193
6b90d1e
0c6c4f6
fe8a3d5
4dff904
9bac365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from google.cloud.logging.handlers.middleware.request import RequestMiddleware | ||
|
||
__all__ = ['RequestMiddleware'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
try: | ||
from threading import local | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
except ImportError: | ||
from django.utils._threading_local import local | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
_thread_locals = local() | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
|
||
def get_request(): | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
"""Get Django request from thread local. | ||
|
||
:rtype: str | ||
:returns: Django request. | ||
""" | ||
return getattr(_thread_locals, 'request', None) | ||
|
||
class RequestMiddleware(object): | ||
"""Saves the request in thread local""" | ||
|
||
def process_request(self, request): | ||
"""Called on each request, before Django decides which view to execute. | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
:type request: :class:`~django.http.request.HttpRequest` | ||
:param request: Django http request. | ||
""" | ||
_thread_locals.request = request | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.