-
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,57 @@ | ||
# Copyright 2017 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. | ||
|
||
import unittest | ||
|
||
|
||
class TestFlaskTrace(unittest.TestCase): | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
def create_app(self): | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
import flask | ||
|
||
app = flask.Flask(__name__) | ||
|
||
@app.route('/') | ||
def index(): | ||
return 'test flask trace' | ||
|
||
return app | ||
|
||
def setUp(self): | ||
self.app = self.create_app() | ||
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. |
||
|
||
def test_trace_id_no_context_header(self): | ||
from google.cloud.logging.handlers._helpers import get_trace_id_from_flask | ||
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. |
||
from google.cloud.logging.handlers._helpers import _EMPTY_TRACE_ID | ||
|
||
with self.app.test_request_context( | ||
path='/', | ||
headers={}): | ||
trace_id = get_trace_id_from_flask() | ||
|
||
self.assertEqual(trace_id, _EMPTY_TRACE_ID) | ||
|
||
def test_trace_id_valid_context_header(self): | ||
from google.cloud.logging.handlers._helpers import get_trace_id_from_flask | ||
|
||
FLASK_TRACE_HEADER = 'X_CLOUD_TRACE_CONTEXT' | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
FLASK_TRACE_ID = 'testtraceid/testspanid' | ||
|
||
with self.app.test_request_context( | ||
path='/', | ||
headers={FLASK_TRACE_HEADER:FLASK_TRACE_ID}): | ||
trace_id = get_trace_id_from_flask() | ||
|
||
EXPECTED_TRACE_ID = 'testtraceid' | ||
self.assertEqual(trace_id, EXPECTED_TRACE_ID) |
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.