### Install aiohttp Package Source: https://github.com/w3c/trace-context/blob/main/test/README.md Install the aiohttp package using pip. ```bash > pip install aiohttp ``` -------------------------------- ### Start Local Server Source: https://github.com/w3c/trace-context/blob/main/CONTRIBUTING.md Run this command to start a local server for viewing the report and avoid cross-site file loading issues. ```python python -m SimpleHTTPServer ``` -------------------------------- ### Example tracestate Header Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md An example of a `tracestate` header, which includes parent information in a potentially vendor-specific format. ```http tracestate: congo=t61rcWkgMzE ``` -------------------------------- ### Combined Tracestate Example Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Illustrates how multiple tracestate entries for the same vendor should be consolidated to the most recent position. ```text congo=congosSecondPosition,rojo=rojosFirstPosition ``` -------------------------------- ### Test Script Output Example Source: https://github.com/w3c/trace-context/blob/main/test/README.md Example output from the test script, showing test case results including failures. ```text harness listening on http://127.0.0.1:7777 test_multiple_requests (__main__.AdvancedTest) ... ok test_both_traceparent_and_tracestate_missing (__main__.TraceContextTest) ... ok test_traceparent_header_name (__main__.TraceContextTest) ... ok test_traceparent_header_name_valid_casing (__main__.TraceContextTest) ... ok test_traceparent_included_tracestate_missing (__main__.TraceContextTest) ... ok test_traceparent_trace_flags_illegal_characters (__main__.TraceContextTest) ... FAIL ====================================================================== FAIL: test_traceparent_trace_flags_illegal_characters (__main__.TraceContextTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "test.py", line 130, in test_traceparent_trace_flags_illegal_characters self.assertNotEqual(trace_id, '12345678901234567890123456789012') AssertionError: '12345678901234567890123456789012' == '12345678901234567890123456789012' ---------------------------------------------------------------------- Ran 6 tests in 0.381s FAILED (failures=1) ``` -------------------------------- ### Simple Tracestate List Example Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md An example of a tracestate header field value containing two list members. ```text vendorname1=opaqueValue1,vendorname2=opaqueValue2 ``` -------------------------------- ### Example traceparent Header Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md An example of a `traceparent` header, representing the incoming request in a tracing system. ```http traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 ``` -------------------------------- ### Restarted Trace Example Source: https://github.com/w3c/trace-context/blob/main/spec/30-processing-model.md Demonstrates a request with an existing traceparent and a response indicating a restarted trace with a new trace ID. ```http traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-d75597dee50b0cac-01 ``` ```http traceresponse: 00-1baad25c36c11c1e7fbd6d122bd85db6-cab70b47728a8a99-01 ``` -------------------------------- ### Example Server Timing Header with Trace Context Metric Source: https://github.com/w3c/trace-context/blob/main/spec/21-http_response_header_format.md Demonstrates how a trace context metric is represented in the Server Timing HTTP response header. ```http server-timing: trace;desc=00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 ``` -------------------------------- ### Check Python Version Source: https://github.com/w3c/trace-context/blob/main/test/README.md Verify that Python version 3.6.0 or higher is installed. ```bash > python --version Python 3.7.0 ``` -------------------------------- ### Deferred Sampling Example Source: https://github.com/w3c/trace-context/blob/main/spec/30-processing-model.md Illustrates a request where the initial sampling decision is not to sample, and a response with a traceresponse header that updates the sampling decision. ```http traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-d75597dee50b0cac-00 ``` ```http traceresponse: 00-4bf92f3577b34da6a3ce929d0e0e4736-828c5d0d435ba505-01 ``` -------------------------------- ### Multiple Tracing Systems tracestate Header Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md An example of a tracestate HTTP header with multiple tracing system entries, demonstrating different formatting. ```http tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE ``` -------------------------------- ### Single Tracing System tracestate Header Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md An example of a tracestate HTTP header with a single tracing system entry. ```http tracestate: rojo=00f067aa0ba902b7 ``` -------------------------------- ### Debug Mode Output Source: https://github.com/w3c/trace-context/blob/main/test/README.md Example output when HARNESS_DEBUG is enabled, showing detailed request and callback information exchanged between the harness and the test service. ```text > python test.py http://127.0.0.1:5000/test AdvancedTest harness listening on http://127.0.0.1:7777 test_multiple_requests (__main__.AdvancedTest) ... Harness trying to send the following request to your service http://127.0.0.1:5000/test POST http://127.0.0.1:5000/test HTTP/1.1 traceparent: 00-12345678901234567890123456789012-1234567890123456-01 [{'arguments': [], 'url': 'http://127.0.0.1:7777/callback/608bf55129ae4e4eafef75909cc47c49.0'}, {'arguments': [], 'url': 'http://127.0.0.1:7777/callback/608bf55129ae4e4eafef75909cc47c49.1'}, {'arguments': [], 'url': 'http://127.0.0.1:7777/callback/608bf55129ae4e4eafef75909cc47c49.2'}] Your service http://127.0.0.1:5000/test responded with HTTP status 200 Your service http://127.0.0.1:5000/test made the following callback to harness Host: 127.0.0.1:7777 User-Agent: python-requests/2.19.1 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 2 traceparent: 00-12345678901234567890123456789012-1e3438eafec64bdf-01 ``` -------------------------------- ### Valid traceparent Header (Sampled) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Example of a valid traceparent header where the caller has sampled the request for tracing. This format includes version, trace ID, parent ID, and sampled flags. ```text Value = 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01 base16(version) = 00 base16(trace-id) = 4bf92f3577b34da6a3ce929d0e0e4736 base16(parent-id) = 00f067aa0ba902b7 base16(trace-flags) = 01 // sampled ``` -------------------------------- ### Valid traceparent Header (Not Sampled) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Example of a valid traceparent header where the caller has not sampled the request. The trace-flags component indicates that the request should not be traced. ```text Value = 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00 base16(version) = 00 base16(trace-id) = 4bf92f3577b34da6a3ce929d0e0e4736 base16(parent-id) = 00f067aa0ba902b7 base16(trace-flags) = 00 // not sampled ``` -------------------------------- ### Test Script Usage and Environment Variables Source: https://github.com/w3c/trace-context/blob/main/test/README.md Shows the command-line usage for the test script, including how to specify test patterns and a list of available environment variables to control harness behavior. ```text Usage: python test.py [patterns] Environment Variables: HARNESS_DEBUG when set, debug mode will be enabled (default to disabled) HARNESS_HOST the public host/address of the test harness (default 127.0.0.1) HARNESS_PORT the public port of the test harness (default 7777) HARNESS_TIMEOUT the timeout (in seconds) used for each test case (default 5) HARNESS_BIND_HOST the host/address which the test harness binds to (default to HARNESS_HOST) HARNESS_BIND_PORT the port which the test harness binds to (default to HARNESS_PORT) SERVICE_ENDPOINT your test service endpoint (no default value) STRICT_LEVEL the level of test strictness (default 2) SPEC_LEVEL the minimum version of the Trace Context specification being tested (default 2) Example: # Run all tests python test.py http://127.0.0.1:5000/test # Run one test python test.py http://127.0.0.1:5000/test TraceContextTest.test_both_traceparent_and_tracestate_missing # Run one test suite python test.py http://127.0.0.1:5000/test AdvancedTest # Run two test suites python test.py http://127.0.0.1:5000/test AdvancedTest TraceContext2Test # Combinations of the above python test.py http://127.0.0.1:5000/test AdvancedTest TraceContextTest.test_both_traceparent_and_tracestate_missing python test.py http://127.0.0.1:5000/test AdvancedTest TraceContextTest.test_both_traceparent_and_tracestate_missing TraceContext2Test.test_propagates_random_flag python test.py http://127.0.0.1:5000/test AdvancedTest TraceContext2Test TraceContextTest.test_both_traceparent_and_tracestate_missing Available Test Suites: TraceContextTest Trace Context Level 1 support AdvancedTest Advanced Trace Context Level 1 support TraceContext2Test Trace Context Level 2 support ``` -------------------------------- ### Preview Report Source: https://github.com/w3c/trace-context/blob/main/CONTRIBUTING.md Use this URL format to preview the report from your branch or fork. Replace placeholders with your specific details. ```html http://htmlpreview.github.io/?https://github.com//trace-context/blob//report-trace-context.html ``` -------------------------------- ### Run Project Self-Tests Source: https://github.com/w3c/trace-context/blob/main/test/README.md Execute the self-test suite from the 'test' folder. This verifies the project's functionality and adherence to standards. ```bash > python self_test.py harness listening on http://127.0.0.1:7777 test_multiple_requests (test.AdvancedTest) ... ok test_both_traceparent_and_tracestate_missing (test.TraceContextTest) ... ok test_traceparent_duplicated (test.TraceContextTest) ... ok test_traceparent_header_name (test.TraceContextTest) ... ok test_traceparent_header_name_valid_casing (test.TraceContextTest) ... ok test_traceparent_included_tracestate_missing (test.TraceContextTest) ... ok test_traceparent_parent_id_all_zero (test.TraceContextTest) ... ok test_traceparent_parent_id_illegal_characters (test.TraceContextTest) ... ok test_traceparent_parent_id_too_long (test.TraceContextTest) ... ok test_traceparent_parent_id_too_short (test.TraceContextTest) ... ok test_traceparent_trace_flags_illegal_characters (test.TraceContextTest) ... ok test_traceparent_trace_flags_too_long (test.TraceContextTest) ... ok test_traceparent_trace_flags_too_short (test.TraceContextTest) ... ok test_traceparent_trace_id_all_zero (test.TraceContextTest) ... ok test_traceparent_trace_id_illegal_characters (test.TraceContextTest) ... ok test_traceparent_trace_id_too_long (test.TraceContextTest) ... ok test_traceparent_trace_id_too_short (test.TraceContextTest) ... ok test_traceparent_version_0x00 (test.TraceContextTest) ... ok test_traceparent_version_0xcc (test.TraceContextTest) ... ok test_traceparent_version_0xff (test.TraceContextTest) ... ok test_traceparent_version_illegal_characters (test.TraceContextTest) ... ok test_traceparent_version_too_long (test.TraceContextTest) ... ok test_traceparent_version_too_short (test.TraceContextTest) ... ok test_tracestate_all_allowed_characters (test.TraceContextTest) ... ok test_tracestate_duplicated_keys (test.TraceContextTest) ... ok test_tracestate_empty_header (test.TraceContextTest) ... ok test_tracestate_header_name (test.TraceContextTest) ... ok test_tracestate_header_name_valid_casing (test.TraceContextTest) ... ok test_tracestate_included_traceparent_included (test.TraceContextTest) ... ok test_tracestate_included_traceparent_missing (test.TraceContextTest) ... ok test_tracestate_key_illegal_characters (test.TraceContextTest) ... ok test_tracestate_key_illegal_vendor_format (test.TraceContextTest) ... ok test_tracestate_key_length_limit (test.TraceContextTest) ... ok test_tracestate_member_count_limit (test.TraceContextTest) ... ok test_tracestate_multiple_headers_different_keys (test.TraceContextTest) ... ok test_tracestate_ows_handling (test.TraceContextTest) ... ok test_tracestate_trailing_ows (test.TraceContextTest) ... ok test_ctor (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_ctor_default (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_ctor_with_variadic_arguments (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_from_string (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_repr (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_set_parent_id (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_set_trace_id (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_parent_id_limit (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_str (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_trace_flags_limit (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_trace_id_limit (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_version_limit (tracecontext.test_traceparent.BaseTraceparentTest) ... ok test_ctor (tracecontext.test_traceparent.TraceparentTest) ... ok test_ctor_default (tracecontext.test_traceparent.TraceparentTest) ... ok test_from_string (tracecontext.test_traceparent.TraceparentTest) ... ok test_repr (tracecontext.test_traceparent.TraceparentTest) ... ok test_set_parent_id (tracecontext.test_traceparent.TraceparentTest) ... ok test_set_trace_id (tracecontext.test_traceparent.TraceparentTest) ... ok test_set_version (tracecontext.test_traceparent.TraceparentTest) ... ok test_str (tracecontext.test_traceparent.TraceparentTest) ... ok test_all_allowed_chars (tracecontext.test_tracestate.TestTracestate) ... ok test_cctor (tracecontext.test_tracestate.TestTracestate) ... ok test_ctor_kwargs (tracecontext.test_tracestate.TestTracestate) ... ok test_ctor_no_arg (tracecontext.test_tracestate.TestTracestate) ... ok test_ctor_with_dict (tracecontext.test_tracestate.TestTracestate) ... ok test_ctor_with_string (tracecontext.test_tracestate.TestTracestate) ... ok test_delimiter (tracecontext.test_tracestate.TestTracestate) ... ok test_getitem (tracecontext.test_tracestate.TestTracestate) ... ok test_method_from_string (tracecontext.test_tracestate.TestTracestate) ... ok ``` -------------------------------- ### Run Test Script Source: https://github.com/w3c/trace-context/blob/main/test/README.md Execute the test script against your test service endpoint. This is the primary way to run the test suite. ```bash > python test.py http://127.0.0.1:5000/test ``` -------------------------------- ### Run Tests with Python unittest Module Source: https://github.com/w3c/trace-context/blob/main/test/README.md Alternative method to run tests using Python's built-in unittest module. This allows for more granular control over test execution. ```bash > python -m unittest ``` ```bash > python -m unittest -v ``` ```bash > python -m unittest test.TraceContextTest.test_traceparent_header_name ``` -------------------------------- ### Sample HTTP POST Request from Test Harness Source: https://github.com/w3c/trace-context/blob/main/test/README.md This is a sample HTTP POST request body format that the test harness will send to your test service endpoint. It contains a JSON array of objects, each with a 'url' and 'arguments' property. ```http POST /test HTTP/1.1 Accept: application/json Accept-Encoding: gzip, deflate Host: 127.0.0.1:5000 User-Agent: Python/3.7 aiohttp/3.3.2 Content-Length: 118 Content-Type: application/json [ {"url": url1, "arguments": [ {"url": url2, "arguments": []} ]}, {"url": url3, "arguments": []} ] ``` -------------------------------- ### Test Execution Summary Source: https://github.com/w3c/trace-context/blob/main/test/README.md This snippet shows the output of a test run, indicating the number of tests executed and the total time taken. It confirms that all tests passed successfully. ```text test_method_is_valid (tracecontext.test_tracestate.TestTracestate) ... ok test_method_repr (tracecontext.test_tracestate.TestTracestate) ... ok test_pop (tracecontext.test_tracestate.TestTracestate) ... ok test_setitem (tracecontext.test_tracestate.TestTracestate) ... ok ---------------------------------------------------------------------- Ran 70 tests in 1.358s OK ``` -------------------------------- ### Subsequent Server Request Headers (Congo Vendor) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Headers processed by a server using the Congo system, which carries over previous tracestate and adds its own entry. ```http traceparent: 00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01 tracestate: congo=ucfJifl5GOE,rojo=00f067aa0ba902b7 ``` -------------------------------- ### Traceparent Version Format (ABNF) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the ABNF for the `version` field within the `traceparent` header, specifying it as two lowercase hexadecimal characters. ```abnf version = 2HEXDIGLC ; this document assumes version 00. Version ff is forbidden ``` -------------------------------- ### Client Request Headers (Congo Vendor) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Headers added by a client traced in the Congo system to an outbound HTTP request. ```http traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 tracestate: congo=t61rcWkgMzE ``` -------------------------------- ### Server Response Headers (Rojo Vendor) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Headers added by a server traced in the Rojo system, carrying over received tracestate and adding its own entry. ```http traceparent: 00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01 tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE ``` -------------------------------- ### Add Contributor Source: https://github.com/w3c/trace-context/blob/main/CONTRIBUTING.md Use this command to add a GitHub username as a contributor in a pull request comment. ```bash +@github_username ``` -------------------------------- ### Interpreting Trace Flags in Java Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md This Java code snippet demonstrates how to correctly interpret the trace-flags bit-field by checking individual flag bits. It shows how to determine if a trace has been sampled or if the trace-id was randomly generated. ```java static final byte FLAG_SAMPLED = 1; // 00000001 static final byte FLAG_RANDOM = 2; // 00000010 ... boolean sampled = (traceFlags & FLAG_SAMPLED) == FLAG_SAMPLED; boolean random = (traceFlags & FLAG_RANDOM) == FLAG_RANDOM; ``` -------------------------------- ### Traceparent Version-Format Definition (ABNF) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the ABNF for the `version-format` component of the `traceparent` header for version 00, including trace ID, parent ID, and trace flags. ```abnf version-format = trace-id "-" parent-id "-" trace-flags trace-id = 32HEXDIGLC ; 16 bytes array identifier. All zeroes forbidden parent-id = 16HEXDIGLC ; 8 bytes array identifier. All zeroes forbidden trace-flags = 2HEXDIGLC ; 8 bit flags. ``` -------------------------------- ### Traceparent Header Format (ABNF) Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the Augmented Backus-Naur Form (ABNF) for the `traceparent` header value, specifying its components. ```abnf HEXDIGLC = DIGIT / "a" / "b" / "c" / "d" / "e" / "f" ; lowercase hex character value = version "-" version-format ``` -------------------------------- ### Tracestate Key ABNF Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the ABNF for a tracestate key, specifying allowed characters and length constraints. ```abnf key = ( lcalpha / DIGIT ) 0*255 ( keychar ) keychar = lcalpha / DIGIT / "_" / "-"/ "*" / "/" / "@" lcalpha = %x61-7A ; a-z ``` -------------------------------- ### ABNF for Trace Context Metric Description Source: https://github.com/w3c/trace-context/blob/main/spec/21-http_response_header_format.md Defines the Augmented Backus-Naur Form (ABNF) for the trace context metric's value, including version, trace ID, child ID, and trace flags. ```abnf HEXDIGLC = DIGIT / "a" / "b" / "c" / "d" / "e" / "f" ; lowercase hex character value = version "-" version-format version = 2HEXDIGLC ; this document assumes version 00. Version ff is forbidden version-format = trace-id "-" child-id "-" trace-flags trace-id = 32HEXDIGLC ; 16 bytes array identifier. All zeroes forbidden child-id = 16HEXDIGLC ; 8 bytes array identifier. All zeroes forbidden trace-flags = 2HEXDIGLC ; 8 bit flags. ``` -------------------------------- ### Tracestate List ABNF Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the Augmented Backus-Naur Form (ABNF) for a tracestate list, which consists of list members separated by commas. ```abnf list = list-member 0*31( OWS "," OWS list-member ) list-member = (key "=" value) / OWS ``` -------------------------------- ### Tracestate Value ABNF Source: https://github.com/w3c/trace-context/blob/main/spec/20-http_request_header_format.md Defines the ABNF for a tracestate value, specifying allowed characters and length constraints. ```abnf value = 0*255(chr) nblk-chr nblk-chr = %x21-2B / %x2D-3C / %x3E-7E chr = %x20 / nblk-chr ``` -------------------------------- ### Remove Contributor Source: https://github.com/w3c/trace-context/blob/main/CONTRIBUTING.md Use this command to remove a GitHub username from the contributor list in a pull request comment. ```bash -@github_username ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.