Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 5cea6d9

Browse files
committed
Almost done
1 parent 2d85539 commit 5cea6d9

File tree

11 files changed

+360
-128
lines changed

11 files changed

+360
-128
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
target/
2+
tmp/
3+
src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/resources/properties/newrelic.properties
4+
internal/
5+
26

README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,66 @@
11
[![New Relic Experimental header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Experimental.png)](https://opensource.newrelic.com/oss-category/#new-relic-experimental)
2-
32
![GitHub forks](https://img.shields.io/github/forks/newrelic-experimental/newrelic-experimental-FIT-template?style=social)
43
![GitHub stars](https://img.shields.io/github/stars/newrelic-experimental/newrelic-experimental-FIT-template?style=social)
54
![GitHub watchers](https://img.shields.io/github/watchers/newrelic-experimental/newrelic-experimental-FIT-template?style=social)
6-
75
![GitHub all releases](https://img.shields.io/github/downloads/newrelic-experimental/newrelic-experimental-FIT-template/total)
86
![GitHub release (latest by date)](https://img.shields.io/github/v/release/newrelic-experimental/newrelic-experimental-FIT-template)
97
![GitHub last commit](https://img.shields.io/github/last-commit/newrelic-experimental/newrelic-experimental-FIT-template)
108
![GitHub Release Date](https://img.shields.io/github/release-date/newrelic-experimental/newrelic-experimental-FIT-template)
11-
129
![GitHub issues](https://img.shields.io/github/issues/newrelic-experimental/newrelic-experimental-FIT-template)
1310
![GitHub issues closed](https://img.shields.io/github/issues-closed/newrelic-experimental/newrelic-experimental-FIT-template)
1411
![GitHub pull requests](https://img.shields.io/github/issues-pr/newrelic-experimental/newrelic-experimental-FIT-template)
1512
![GitHub pull requests closed](https://img.shields.io/github/issues-pr-closed/newrelic-experimental/newrelic-experimental-FIT-template)
1613

1714
# Apigee Distributed Tracing
15+
This repository includes Apigee [Javascript Resources](src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/resources/jsc) for
16+
- Creating or propagating [W3C Trace Context](https://www.w3.org/TR/trace-context/) through [Apigee Flows](https://cloud.google.com/apigee/docs/api-platform/fundamentals/what-are-flows) and on to the Apigee Target
17+
- Reporting Flow Request/Response pairs as Spans to [New Relic's Trace API](https://docs.newrelic.com/docs/distributed-tracing/trace-api/introduction-trace-api/)
18+
19+
The repository also includes [sample policies](src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies) to demonstrate how the pieces work together.
20+
21+
**The documentation requires fluency with Apigee.**
1822

19-
## TO DO
20-
- Who writes the `tracecontext` to the Pub/Sub message?
21-
- What is the format?
22-
- Does NR have a standard for `tracestate`?
2323
## Installation
24+
1. Copy the JavaScript resources into the `resources/jsc` folder
25+
2. Copy `newrelic-sample.properties` file to `resources/properties/newrelic.properties`
26+
3. Create a Request/Response Policy pair for each Flow step measured. At a minimum one pair is required to ensure that a Trace Context is present for a Target.
27+
- [Sample Request Policy](src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Trace-Context-Request.xml)
28+
- [Sample Response Policy](src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Trace-Context-Response.xml)
29+
2430
## Configuration
31+
All Resource and Policy files include complete in-file documentation, see them for details
32+
33+
### Javascript Resources
34+
Nothing required
35+
36+
### Properties file
37+
- Edit the `newrelic.properties` file and add your New Relic License Key.
38+
39+
### Proxy policies
40+
- **Proxy policies must be paired, one in a Request Flow and one in a Response Flow**
2541
- [Flow execution sequence](https://docs.apigee.com/api-platform/fundamentals/what-are-flows#designingflowexecutionsequence)
2642
- Start/End timestamps: [Apigee Flow Variables](https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference)
27-
### Proxy policies
28-
- Proxy policies must be paired, one in a Request Flow and one in a Response Flow
29-
- Request Policies use `<ResourceURL>jsc://Trace-Context-Request.js</ResourceURL>`
30-
-
31-
## Development
3243

44+
## Development
3345
### Helpful links
46+
- [W3C Trace Context](https://www.w3.org/TR/trace-context/)
3447
- [Apigee development with VSCode](https://cloud.google.com/apigee/docs/api-platform/local-development/vscode/get-started)
3548
- [Apigee JavaScript object model](https://cloud.google.com/apigee/docs/api-platform/reference/javascript-object-model)
36-
37-
## Testing
49+
- [Rhino features by release](https://mozilla.github.io/rhino/compat/engines.html) ([Apigee uses Rhino 1.7..7.1](https://cloud.google.com/apigee/docs/api-platform/reference/policies/javascript-policy#:~:text=Apigee%20supports%20JavaScript%20that%20runs,7.1.), it's fairly limited.)
50+
- [New Relic Trace API Payload](https://docs.newrelic.com/docs/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api/#new-relic-guidelines)
3851

3952
## Support
40-
4153
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.
4254

4355
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.
4456

4557
## Contributing
46-
4758
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].
4859

49-
**A note about vulnerabilities**
50-
60+
## A note about vulnerabilities
5161
As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
5262

5363
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
5464

5565
## License
56-
5766
Apigee Distributed Tracing is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.

src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Target-Trace-Context-Request.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Target-Trace-Context-Request">
33
<DisplayName>Target-Trace-Context-Request</DisplayName>
44
<Properties>
5-
<!-- The odds of a Trace being sampled, 0-100. 0 = tracing off, 100 = trace everything. -->
5+
<!-- OPTIONAL
6+
The odds of a Trace being sampled, 0-100. 0 = tracing off, 100 = trace everything.
7+
Default: 100 -->
68
<Property name="SampleOddsPercentage">100</Property>
7-
<!-- The name of the Request/Response pair. Must be unique within a Proxy. -->
8-
<Property name="RequestResponsePairName">Target-Trace-Context-Flow</Property>
9-
<!-- 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()'-->
9+
10+
<!-- REQUIRED
11+
The name of the Request/Response pair. Must be unique within a Proxy.
12+
Default: no default value -->
13+
<Property name="RequestResponsePairName">Target-Trace-Context-Flow</Property>
14+
15+
<!-- OPTIONAL
16+
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.
17+
Default:`Date.now()'-->
1018
<Property name="TraceStartTimestamp"></Property>
19+
20+
<!-- OPTIONAL
21+
A comma separated list of key=value pairs propagated in the tracestate header.
22+
https://www.w3.org/TR/trace-context/#tracestate-header -->
23+
<Property name="AdditionalTracestateValues"></Property>
24+
1125
</Properties>
1226
<IncludeURL>jsc://Utils.js</IncludeURL>
1327
<ResourceURL>jsc://Trace-Context-Request.js</ResourceURL>

src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Target-Trace-Context-Response.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@
22
<Javascript async="false" continueOnError="true" enabled="true" timeLimit="5000" name="Target-Trace-Context-Response">
33
<DisplayName>Target-Trace-Context-Response</DisplayName>
44
<Properties>
5-
<!-- The name of the Request/Response pair. Must be unique within a Proxy. -->
5+
<!-- REQUIRED
6+
The name of the Request/Response pair. Must be unique within a Proxy.
7+
Default: no default value
8+
-->
69
<Property name="RequestResponsePairName">Target-Trace-Context-Flow</Property>
7-
<!-- Custom attributes to include with the NR Span object. A comma separated list of key:value pairs -->
10+
11+
<!-- OPTIONAL
12+
Custom attributes to include with the New Relic Span object. MUST be a valid JSON object.
13+
https://docs.newrelic.com/docs/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api/#new-relic-guidelines
14+
Default: { 'duration.ms': endTime - parentStartTime, 'name': properties.RequestResponsePairName, 'service.name': 'Apigee' }
15+
-->
816
<Property name="AdditionalSpanAttributes"></Property>
9-
<!-- 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()'-->
17+
18+
<!-- OPTIONAL
19+
Custom attributes to include with the New Relic Trace object, common to all Spans. MUST be a valid JSON object.
20+
https://docs.newrelic.com/docs/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api/#new-relic-guidelines
21+
Default: no default value
22+
-->
23+
<Property name="CommonAttributes"></Property>
24+
25+
<!-- OPTIONAL
26+
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.
27+
Default: `Date.now()'
28+
-->
1029
<Property name="TraceEndTimestamp"></Property>
30+
1131
</Properties>
1232
<IncludeURL>jsc://Utils.js</IncludeURL>
1333
<ResourceURL>jsc://Trace-Context-Response.js</ResourceURL>

src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Trace-Context-Request.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Trace-Context-Request">
33
<DisplayName>Trace-Context-Request</DisplayName>
44
<Properties>
5-
<!-- The odds of a Trace being sampled, 0-100. 0 = tracing off, 100 = trace everything. -->
5+
<!-- OPTIONAL
6+
The odds of a Trace being sampled, 0-100. 0 = tracing off, 100 = trace everything.
7+
Default: 100 -->
68
<Property name="SampleOddsPercentage">100</Property>
7-
<!-- The name of the Request/Response pair. Must be unique within a Proxy. -->
9+
10+
<!-- REQUIRED
11+
The name of the Request/Response pair. Must be unique within a Proxy.
12+
Default: no default value -->
813
<Property name="RequestResponsePairName">Proxy-Trace-Context-Flow</Property>
9-
<!-- 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()'-->
14+
15+
<!-- OPTIONAL
16+
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.
17+
Default:`Date.now()'-->
1018
<Property name="TraceStartTimestamp"></Property>
19+
20+
<!-- OPTIONAL
21+
A comma separated list of key=value pairs propagated in the tracestate header.
22+
https://www.w3.org/TR/trace-context/#tracestate-header -->
23+
<Property name="AdditionalTracestateValues"></Property>
1124
</Properties>
1225
<IncludeURL>jsc://Utils.js</IncludeURL>
1326
<ResourceURL>jsc://Trace-Context-Request.js</ResourceURL>

src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/policies/Trace-Context-Response.xml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22
<Javascript async="false" continueOnError="true" enabled="true" timeLimit="5000" name="Trace-Context-Response">
33
<DisplayName>Trace-Context-Response</DisplayName>
44
<Properties>
5-
<!-- The name of the Request/Response pair. Must be unique within a Proxy. -->
5+
<!-- REQUIRED
6+
The name of the Request/Response pair. Must be unique within a Proxy.
7+
Default: no default value
8+
-->
69
<Property name="RequestResponsePairName">Proxy-Trace-Context-Flow</Property>
7-
<!-- Custom attributes to include with the NR Span object. A comma separated list of key:value pairs -->
10+
11+
<!-- OPTIONAL
12+
Custom attributes to include with the New Relic Span object. MUST be a valid JSON object.
13+
https://docs.newrelic.com/docs/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api/#new-relic-guidelines
14+
Default: { 'duration.ms': endTime - parentStartTime, 'name': properties.RequestResponsePairName, 'service.name': 'Apigee' }
15+
IMPORTANT NOTE: properties, flow variables, and context variables are not evaluated and will appear as string literals in the Span.
16+
-->
817
<Property name="AdditionalSpanAttributes"></Property>
9-
<!-- 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()'-->
18+
19+
<!-- OPTIONAL
20+
Custom attributes to include with the New Relic Trace object, common to all Spans. MUST be a valid JSON object.
21+
https://docs.newrelic.com/docs/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api/#new-relic-guidelines
22+
Default: no default value
23+
IMPORTANT NOTE: properties, flow variables, and context variables are not evaluated and will appear as string literals in the Span.
24+
-->
25+
<Property name="CommonAttributes"></Property>
26+
27+
<!-- OPTIONAL
28+
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.
29+
Default: `Date.now()'
30+
-->
1031
<Property name="TraceEndTimestamp"></Property>
32+
1133
</Properties>
1234
<IncludeURL>jsc://Utils.js</IncludeURL>
1335
<ResourceURL>jsc://Trace-Context-Response.js</ResourceURL>

src/main/apigee/apiproxies/W3C-Trace-Context/apiproxy/resources/jsc/Add-Trace-Context-To-Pub-Sub-Message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict"
1+
'use strict'
22
// Get the PubSub message
33
// Add the Trace Context
44
// TODO What is the format of adding the tracecontext to the JSON payload?

0 commit comments

Comments
 (0)