You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
# [Project Name][build badges go here when available]
19
-
20
-
>[Brief description - what is the project and value does it provide? How often should users expect to get releases? How is versioning set up? Where does this project want to go?]
17
+
# Apigee Distributed Tracing
21
18
22
19
## Installation
23
20
24
-
> [Include a step-by-step procedure on how to get your code installed. Be sure to include any third-party dependencies that need to be installed separately]
25
-
26
-
## Getting Started
27
-
28
-
>[Simple steps to start working with the software similar to a "Hello World"]
29
-
30
-
## Usage
31
-
32
-
>[**Optional** - Include more thorough instructions on how to use the software. This section might not be needed if the Getting Started section is enough. Remove this section if it's not needed.]
21
+
## Development
33
22
34
-
##Building
35
-
36
-
>[**Optional** - Include this section if users will need to follow specific instructions to build the software from source. Be sure to include any third party build dependencies that need to be installed separately. Remove this section if it's not needed.]
23
+
### Helpful links
24
+
-[Apigee development with VSCode](https://cloud.google.com/apigee/docs/api-platform/local-development/vscode/get-started)
>[**Optional** - Include instructions on how to run tests if we include tests with the codebase. Remove this section if it's not needed.]
41
-
42
29
## Support
43
30
44
31
New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Issues and contributions should be reported to the project here on GitHub.
45
32
46
-
>[Choose 1 of the 2 options below for Support details, and remove the other one.]
47
-
48
-
>[Option 1 - no specific thread in Community]
49
-
>We encourage you to bring your experiences and questions to the [Explorers Hub](https://discuss.newrelic.com) where our community members collaborate on solutions and new ideas.
50
-
51
-
>[Option 2 - thread in Community]
52
-
>New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub.
53
-
>You can find this project's topic/threads here: [URL for Community thread]
33
+
We encourage you to bring your experiences and questions to the [Explorers Hub](https://discuss.newrelic.com) where our community members collaborate on solutions and new ideas.
54
34
55
35
## Contributing
56
36
57
-
We encourage your contributions to improve [Project Name]! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
37
+
We encourage your contributions to improve Apigee Distributed Tracing! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
58
38
59
39
**A note about vulnerabilities**
60
40
@@ -64,6 +44,4 @@ If you believe you have found a security vulnerability in this project or any of
64
44
65
45
## License
66
46
67
-
[Project Name] is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
68
-
69
-
>[If applicable: [Project Name] also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.]
47
+
Apigee Distributed Tracing is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
<!-- How to determine the start time for this Trace. Any Flow Variable (https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference) ending in '.timestamp' is valid. Default is `Date.now()'-->
<!-- How to determine the end time for this Trace. Any Flow Variable (https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference) ending in '.timestamp' is valid. Default is `Date.now()'-->
// In W3C speak "Parent ID" is only the "Parent's ID" as received in an incoming traceparent header. Once we create a "Span" we become the "Parent ID"- what
39
+
// most would term "the Span ID". `requestParentID` is therefore the incoming Span's ID. This code sticks with W3C terminology for consistency.
requestParentID="";// New Relic's Trace API expects a null parent.id attribute if this is the root span
48
+
tracestate='';
49
+
}
50
+
51
+
// 4.2 No traceparent Received
52
+
// If no traceparent header is received:
53
+
if(traceparent==null){
54
+
// Create an initial traceparent and tracestate
55
+
// The vendor checks an incoming request for a traceparent and a tracestate header.
56
+
// Because the traceparent header is not received, the vendor creates a new trace-id and parent-id that represents the current request.
57
+
// If a tracestate header is received without an accompanying traceparent header, it is invalid and MUST be discarded.
58
+
// The vendor SHOULD create a new tracestate header and add a new key/value pair.
59
+
// The vendor sets the traceparent and tracestate header for the outgoing request.
60
+
newTraceparent();
61
+
}
62
+
// 4.3 A traceparent is Received
63
+
// If a traceparent header is received:
64
+
else{
65
+
// The vendor checks an incoming request for a traceparent and a tracestate header.
66
+
// Because the traceparent header is present, the vendor tries to parse the version of the traceparent header.
67
+
// If the version cannot be parsed, the vendor creates a new traceparent header and deletes tracestate.
68
+
// If the version number is higher than supported by the tracer, the vendor uses the format defined in this specification (00) to parse trace-id and parent-id.
69
+
// The vendor will only parse the trace-flags values supported by this version of this specification and ignore all other values.
70
+
// If parsing fails, the vendor creates a new traceparent header and deletes the tracestate. Vendors will set all unparsed / unknown trace-flags to 0 on outgoing requests.
// If the vendor supports the version number, it validates trace-id and parent-id. If either trace-id, parent-id or trace-flags are invalid, the vendor creates a new traceparent header and deletes tracestate.
76
+
varvalues=traceparent.split('-');
77
+
requestVersionFormat=values[0];
78
+
traceId=values[1];
79
+
parentID=values[2];
80
+
traceFlags=values[2];
81
+
if(/[1-9a-f]/.test(traceID)){
82
+
if(/[1-9a-f]/.test(parentID)){
83
+
if(/[0-9a-f]/.test(traceFlags)){
84
+
// All good, generate our ParentID
85
+
// The vendor MUST modify the traceparent header:
86
+
// Update parent-id: The value of property parent-id MUST be set to a value representing the ID of the current operation.
87
+
// Update sampled: The value of sampled reflects the caller's recording behavior. The value of the sampled flag of trace-flags MAY be set to 1 if the trace data is likely to be recorded or to 0 otherwise. Setting the flag is no guarantee that the trace will be recorded but increases the likeliness of end-to-end recorded traces.
88
+
requestParentID=parentID;
89
+
parentID=generateValidID(8);
90
+
traceFlags=generateSampled();
91
+
}else{
92
+
print('Error: invalid traceFlags: '+traceFlags);
93
+
newTraceparent();
94
+
}
95
+
}else{
96
+
print('Error: invalid parentID: '+parentID);
97
+
newTraceparent();
98
+
}
99
+
}else{
100
+
print('Error: invalid traceID: '+traceID);
101
+
newTraceparent();
102
+
}
103
+
104
+
// The vendor MAY validate the tracestate header. If the tracestate header cannot be parsed the vendor MAY discard the entire header. Invalid tracestate entries MAY also be discarded.
105
+
varstates=tracestate.split(',');
106
+
if(states.length>32){
107
+
print("Warning: tracestate has too many values: "+states.length);
108
+
}
109
+
}
110
+
}
111
+
112
+
// TODO Does NR have any standard fields for tracestate?
113
+
// TODO
114
+
// The vendor MAY modify the tracestate header:
115
+
// Update a key value: The value of any key can be updated. Modified keys MUST be moved to the beginning (left) of the list.
116
+
// Add a new key/value pair: The new key-value pair MUST be added to the beginning (left) of the list.
117
+
// Delete a key/value pair: Any key/value pair MAY be deleted. Vendors SHOULD NOT delete keys that weren't generated by themselves. Deletion of any key/value pair MAY break correlation in other systems.
118
+
119
+
// The vendor sets the traceparent and tracestate header for the outgoing request.
0 commit comments