├── .gitignore ├── .env.sample ├── README.md ├── package.json ├── honeycomb-exporter.js ├── simple_tracer_example.js ├── simple_tracer.js ├── index.js ├── tracer_test.js ├── tracer.js └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | .dev.vars 4 | -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | HONEYCOMB_API_KEY=1234 2 | BASELIME_API_KEY=1234 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minimal Node.js OpenTelemetry Tracer 2 | 3 | Repo to go with the blog post: https://jeremymorrell.dev/blog/minimal-js-tracing/ 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimal-tracing", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node --env-file .env index.js", 8 | "test": "node tracer_test.js", 9 | "test:watch": "node --watch tracer_test.js" 10 | }, 11 | "type": "module", 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "@hono/node-server": "^1.12.0", 17 | "hono": "^4.5.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /honeycomb-exporter.js: -------------------------------------------------------------------------------- 1 | import { Tracing } from "./tracer.js"; 2 | 3 | function spanToHoneycombJSON(span) { 4 | return { 5 | ...Object.fromEntries(Tracing.globalAttributes), 6 | ...Object.fromEntries(span.attributes), 7 | name: span.name, 8 | trace_id: span.traceID, 9 | span_id: span.spanID, 10 | parent_span_id: span.parentSpanID, 11 | start_time: span.startTime, 12 | duration_ms: span.durationMs, 13 | }; 14 | } 15 | 16 | function honeycombExporter(apiKey) { 17 | return function (span) { 18 | fetch(`https://api.honeycomb.io/1/events/${Tracing.name}`, { 19 | method: "POST", 20 | headers: { 21 | "Content-Type": "application/json", 22 | "X-Honeycomb-Team": apiKey, 23 | "X-Honeycomb-Event-Time": span.startTime, 24 | }, 25 | body: JSON.stringify(spanToHoneycombJSON(span)), 26 | }); 27 | }; 28 | } 29 | 30 | export default honeycombExporter; 31 | -------------------------------------------------------------------------------- /simple_tracer_example.js: -------------------------------------------------------------------------------- 1 | import crypto from "node:crypto"; 2 | import { AsyncLocalStorage } from "node:async_hooks"; 3 | 4 | class Span { 5 | constructor(name, context = {}, attributes = new Map()) { 6 | this.startTime = new Date().getTime(); 7 | this.startTimestampMs = performance.now(); 8 | this.traceID = context.traceID ?? crypto.randomBytes(16).toString("hex"); 9 | this.parentSpanID = context.spanID ?? undefined; 10 | this.name = name; 11 | this.attributes = attributes; 12 | this.spanID = crypto.randomBytes(8).toString("hex"); 13 | } 14 | 15 | getContext() { 16 | return { traceID: this.traceID, spanID: this.spanID, span: this }; 17 | } 18 | 19 | setAttributes(keyValues) { 20 | for (let [key, value] of Object.entries(keyValues)) { 21 | this.attributes.set(key, value); 22 | } 23 | } 24 | 25 | end() { 26 | this.durationMs = performance.now() - this.startTimestampMs; 27 | } 28 | } 29 | 30 | let asyncLocalStorage = new AsyncLocalStorage(); 31 | let exporter = (span) => console.log(span); 32 | asyncLocalStorage.enterWith({ traceID: undefined, spanID: undefined }); 33 | 34 | async function startSpan(name, lambda) { 35 | let ctx = asyncLocalStorage.getStore(); 36 | let span = new Span(name, ctx, new Map()); 37 | await asyncLocalStorage.run(span.getContext(), lambda, span); 38 | span.end(); 39 | exporter(span); 40 | } 41 | 42 | startSpan("parent", async (span) => { 43 | span.setAttributes({ outerSpan: true }); 44 | startSpan("child", async (span2) => { 45 | span2.setAttributes({ outerSpan: false }); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /simple_tracer.js: -------------------------------------------------------------------------------- 1 | import { AsyncLocalStorage } from "node:async_hooks"; 2 | import crypto from "node:crypto"; 3 | 4 | class Tracing { 5 | static asyncLocalStorage = new AsyncLocalStorage(); 6 | 7 | static exporter = (span) => console.log(span); 8 | 9 | static getCurrentSpan = () => Tracing.asyncLocalStorage.getStore().span; 10 | 11 | static getContext = () => Tracing.asyncLocalStorage.getStore(); 12 | 13 | static async setContext(ctx, cb, ...args) { 14 | await Tracing.asyncLocalStorage.run(ctx, cb, ...args); 15 | } 16 | 17 | static async startSpan(name, lambda) { 18 | let ctx = Tracing.asyncLocalStorage.getStore(); 19 | let span = new Span(name, ctx, new Map()); 20 | await Tracing.setContext(span.getContext(), lambda, span); 21 | span.end(); 22 | Tracing.exporter(span); 23 | } 24 | } 25 | 26 | const EMPTY_CONTEXT = {}; 27 | Tracing.asyncLocalStorage.enterWith(EMPTY_CONTEXT); 28 | 29 | class Span { 30 | constructor(name, context = {}, attributes = new Map()) { 31 | this.startTime = new Date().getTime(); 32 | this.startTimestampMs = performance.now(); 33 | this.traceID = context.traceID ?? crypto.randomBytes(16).toString("hex"); 34 | this.parentSpanID = context.spanID ?? undefined; 35 | this.name = name; 36 | this.attributes = attributes; 37 | this.spanID = crypto.randomBytes(8).toString("hex"); 38 | } 39 | 40 | getContext() { 41 | return { traceID: this.traceID, spanID: this.spanID, span: this }; 42 | } 43 | 44 | setAttributes(keyValues) { 45 | for (let [key, value] of Object.entries(keyValues)) { 46 | this.attributes.set(key, value); 47 | } 48 | } 49 | 50 | end() { 51 | this.elapsedMs = performance.now() - this.startTimestampMs; 52 | } 53 | } 54 | 55 | export { Tracing }; 56 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { serve } from "@hono/node-server"; 2 | import { Hono } from "hono"; 3 | import { Tracing, honoMiddleware, patchFetch, otlpExporter } from "./tracer.js"; 4 | import honeycombExporter from "./honeycomb-exporter.js"; 5 | 6 | Tracing.name = "test-app"; 7 | Tracing.globalAttributes = new Map([["service.name", "test-app"]]); 8 | 9 | // Export using Honeycomb's events API 10 | // Tracing.exporter = honeycombExporter(process.env.HONEYCOMB_API_KEY); 11 | 12 | // OTLP export to Honeycomb 13 | Tracing.exporter = otlpExporter("https://api.honeycomb.io/v1/traces", { 14 | "X-Honeycomb-Team": process.env.HONEYCOMB_API_KEY, 15 | }); 16 | 17 | // export to Baselime 18 | // Tracing.exporter = otlpExporter("https://otel.baselime.io/v1/traces", { 19 | // "x-api-key": process.env.BASELIME_API_KEY, 20 | // "X-baselime-dataset": "blogpost", 21 | // }); 22 | 23 | // Export to local tool, otel-desktop-viewer or otel-tui 24 | // Tracing.exporter = otlpExporter("http://localhost:4318/v1/traces", {}); 25 | 26 | let app = new Hono(); 27 | 28 | // add the auto-instrumentation, in a production library 29 | // this would happen behind-the-scenes 30 | let patchedFetch = patchFetch(fetch); 31 | app.use(honoMiddleware); 32 | 33 | app.get("/user/:id", async (c) => { 34 | // pretend to call another service 35 | let user_response = await patchedFetch( 36 | `${new URL(c.req.url).origin}/user_info/${c.req.param("id")}` 37 | ); 38 | 39 | let user = await user_response.json(); 40 | 41 | let span = Tracing.getCurrentSpan(); 42 | span.setAttributes({ 43 | "user.id": user.id, 44 | "user.name": user.name, 45 | "user.org": user.org, 46 | "user.team": user.team, 47 | }); 48 | 49 | return c.text(`Hello ${user.name}!`); 50 | }); 51 | 52 | app.get("/user_info/:id", async (c) => { 53 | // pretend to pull this from a db 54 | await Tracing.startSpan("db query", async (span) => { 55 | span.setAttributes({ 56 | "db.query": "SELECT * FROM table LIMIT 1", 57 | }); 58 | await new Promise((resolve) => setTimeout(resolve, 10)); 59 | }); 60 | 61 | return c.json({ 62 | id: c.req.param("id"), 63 | name: "username", 64 | org: "org name", 65 | team: "team name", 66 | }); 67 | }); 68 | 69 | serve({ 70 | fetch: app.fetch, 71 | port: process.env.PORT || 3000, 72 | }); 73 | -------------------------------------------------------------------------------- /tracer_test.js: -------------------------------------------------------------------------------- 1 | import { suite, test, before, after, beforeEach, afterEach } from "node:test"; 2 | import assert from "node:assert"; 3 | 4 | import { Tracing, Span } from "./tracer.js"; 5 | 6 | function sleep(ms) { 7 | return new Promise((resolve) => setTimeout(resolve, ms)); 8 | } 9 | 10 | suite("Span", () => { 11 | test("new span", () => { 12 | let span = new Span("test"); 13 | span.setAttributes({ 14 | foo: "bar", 15 | baz: "potato", 16 | }); 17 | assert.ok(span.startTime); 18 | 19 | span.end(); 20 | 21 | assert(span.name == "test"); 22 | assert(span.attributes.get("foo") == "bar"); 23 | assert(span.attributes.get("baz") == "potato"); 24 | assert.ok(span.stopTime); 25 | }); 26 | 27 | test("inherit span context", () => { 28 | let ctx = { 29 | traceID: "12345", 30 | spanID: "45678", 31 | }; 32 | let span = new Span("test", ctx); 33 | 34 | assert.equal(span.traceID, "12345"); 35 | assert.equal(span.parentSpanID, "45678"); 36 | }); 37 | }); 38 | 39 | suite("Tracing", async () => { 40 | let prevExporter; 41 | let spans = []; 42 | 43 | before(() => { 44 | prevExporter = Tracing.exporter; 45 | }); 46 | 47 | after(() => { 48 | Tracing.exporter = prevExporter; 49 | }); 50 | 51 | beforeEach(() => { 52 | Tracing.exporter = (span) => { 53 | spans.push(span); 54 | }; 55 | }); 56 | 57 | afterEach(() => { 58 | // clear the array, but keep the reference 59 | spans.splice(0, spans.length); 60 | }); 61 | 62 | test("start span", () => { 63 | Tracing.startSpan("parent", (span) => { 64 | assert.equal(span, Tracing.getCurrentSpan()); 65 | assert.equal("parent", Tracing.getCurrentSpan().name); 66 | }); 67 | 68 | assert.equal(undefined, Tracing.getCurrentSpan()); 69 | }); 70 | 71 | test("start span nested", () => { 72 | Tracing.startSpan("parent", (span) => { 73 | assert.equal(span, Tracing.getCurrentSpan()); 74 | 75 | Tracing.startSpan("child", (span2) => { 76 | assert.equal(span2, Tracing.getCurrentSpan()); 77 | assert.equal(span2.parentSpanID, span.spanID); 78 | }); 79 | 80 | assert.equal(span, Tracing.getCurrentSpan()); 81 | }); 82 | 83 | assert.equal(undefined, Tracing.getCurrentSpan()); 84 | }); 85 | 86 | test("spans captured", () => { 87 | // Because we must also support async use cases, this triggers an 88 | // await internal to startSpan, which yields to the event loop. 89 | // Exporting spans then becomes async even in the synchronous use-case, 90 | // so we must also yield to the event loop before we can make this 91 | // assertion. 92 | // 93 | // In practice, this difference can be ignored since we only care 94 | // that spans are emitted soon after execution 95 | let promise = Tracing.startSpan("parent", (span) => { 96 | Tracing.startSpan("child", (span2) => {}); 97 | }); 98 | 99 | Promise.resolve(promise).then(() => { 100 | assert.equal(2, spans.length); 101 | // the child is the first span to close, so it should be first 102 | assert.equal("child", spans[0].name); 103 | assert.equal("parent", spans[1].name); 104 | }); 105 | }); 106 | }); 107 | 108 | suite("async tracing", () => { 109 | let prevExporter; 110 | let spans = []; 111 | 112 | before(() => { 113 | prevExporter = Tracing.exporter; 114 | }); 115 | 116 | after(() => { 117 | Tracing.exporter = prevExporter; 118 | }); 119 | 120 | beforeEach(() => { 121 | Tracing.exporter = (span) => { 122 | spans.push(span); 123 | }; 124 | }); 125 | 126 | afterEach(() => { 127 | // clear the array, but keep the reference 128 | spans.splice(0, spans.length); 129 | }); 130 | 131 | test("async spans captured", async () => { 132 | await Tracing.startSpan("parent", async (span) => { 133 | await sleep(10); 134 | await Tracing.startSpan("child", async (span2) => { 135 | await sleep(10); 136 | }); 137 | await sleep(10); 138 | }); 139 | 140 | assert.equal(2, spans.length); 141 | // the child is the first span to close, so it should be first 142 | assert.equal("child", spans[0].name); 143 | assert.equal("parent", spans[1].name); 144 | }); 145 | }); 146 | -------------------------------------------------------------------------------- /tracer.js: -------------------------------------------------------------------------------- 1 | import { AsyncLocalStorage } from "node:async_hooks"; 2 | import crypto from "node:crypto"; 3 | 4 | class Tracing { 5 | static asyncLocalStorage = new AsyncLocalStorage(); 6 | 7 | static globalAttributes = new Map(); 8 | 9 | static name = ""; 10 | 11 | static exporter = (span) => {}; 12 | 13 | static getCurrentSpan = () => Tracing.asyncLocalStorage.getStore().span; 14 | 15 | static getContext = () => Tracing.asyncLocalStorage.getStore(); 16 | 17 | static async setContext(ctx, cb, ...args) { 18 | await Tracing.asyncLocalStorage.run(ctx, cb, ...args); 19 | } 20 | 21 | static async startSpan(name, lambda) { 22 | let ctx = Tracing.asyncLocalStorage.getStore(); 23 | let span = new Span(name, ctx, new Map([["service.name", Tracing.name]])); 24 | await Tracing.setContext(span.getContext(), lambda, span); 25 | span.end(); 26 | Tracing.exporter(span); 27 | } 28 | } 29 | 30 | const EMPTY_CONTEXT = {}; 31 | Tracing.asyncLocalStorage.enterWith(EMPTY_CONTEXT); 32 | 33 | class Span { 34 | constructor(name, context = {}, attributes = new Map()) { 35 | this.startTime = new Date().getTime(); 36 | this.startTimestampMs = performance.now(); 37 | this.traceID = context.traceID ?? crypto.randomBytes(16).toString("hex"); 38 | this.parentSpanID = context.spanID ?? undefined; 39 | this.name = name; 40 | this.attributes = attributes; 41 | this.spanID = crypto.randomBytes(8).toString("hex"); 42 | } 43 | 44 | getContext() { 45 | return { traceID: this.traceID, spanID: this.spanID, span: this }; 46 | } 47 | 48 | setAttributes(keyValues) { 49 | for (let [key, value] of Object.entries(keyValues)) { 50 | this.attributes.set(key, value); 51 | } 52 | } 53 | 54 | end() { 55 | this.durationMs = performance.now() - this.startTimestampMs; 56 | } 57 | } 58 | 59 | let getTraceParent = (ctx) => `00-${ctx.traceID}-${ctx.spanID}-01`; 60 | 61 | let parseTraceParent = (header) => ({ 62 | traceID: header.split("-")[1], 63 | spanID: header.split("-")[2], 64 | }); 65 | 66 | async function honoMiddleware(c, next) { 67 | let context = EMPTY_CONTEXT; 68 | if (c.req.header("traceparent")) { 69 | context = parseTraceParent(c.req.header("traceparent")); 70 | } 71 | 72 | await Tracing.setContext(context, async () => { 73 | await Tracing.startSpan(`${c.req.method} ${c.req.path}`, async (span) => { 74 | span.setAttributes({ 75 | "http.request.method": c.req.method, 76 | "http.request.path": c.req.path, 77 | }); 78 | 79 | await next(); 80 | 81 | span.setAttributes({ 82 | "http.response.status_code": c.res.status, 83 | }); 84 | }); 85 | }); 86 | } 87 | 88 | function patchFetch(originalFetch) { 89 | return async function patchedFetch(resource, options = {}) { 90 | let ctx = Tracing.getContext(); 91 | 92 | if (!options.headers) { 93 | options.headers = {}; 94 | } 95 | options.headers["traceparent"] = getTraceParent(ctx); 96 | 97 | let resp; 98 | await Tracing.startSpan("fetch", async (span) => { 99 | span.setAttributes({ "http.url": resource }); 100 | resp = await originalFetch(resource, options); 101 | span.setAttributes({ "http.response.status_code": resp.status }); 102 | }); 103 | return resp; 104 | }; 105 | } 106 | 107 | function toAnyValue(val) { 108 | if (val instanceof Uint8Array) return { bytesValue: value }; 109 | if (Array.isArray(val)) 110 | return { arrayValue: { values: val.map(toAnyValue) } }; 111 | let t = typeof val; 112 | if (t === "string") return { stringValue: val }; 113 | if (t === "number") return { doubleValue: val }; 114 | if (t === "boolean") return { boolValue: val }; 115 | if (t === "object" && val != null) 116 | return { 117 | kvlistValue: { 118 | values: Object.entries(val).map(([k, v]) => toKeyValue(k, v)), 119 | }, 120 | }; 121 | return {}; 122 | } 123 | 124 | function toKeyValue(key, val) { 125 | return { key, value: toAnyValue(val) }; 126 | } 127 | 128 | function toAttributes(attributes) { 129 | return Object.keys(attributes).map((key) => toKeyValue(key, attributes[key])); 130 | } 131 | 132 | function spanToOTLP(span) { 133 | return { 134 | resourceSpans: [ 135 | { 136 | resource: { 137 | attributes: toAttributes( 138 | Object.fromEntries(Tracing.globalAttributes) 139 | ), 140 | }, 141 | scopeSpans: [ 142 | { 143 | scope: { 144 | name: "minimal-tracer", 145 | version: "0.0.1", 146 | attributes: [], 147 | }, 148 | spans: [ 149 | { 150 | traceId: span.traceID, 151 | spanId: span.spanID, 152 | parentSpanId: span.parentSpanID, 153 | name: span.name, 154 | startTimeUnixNano: span.startTime * Math.pow(10, 6), 155 | endTimeUnixNano: 156 | (span.startTime + span.durationMs) * Math.pow(10, 6), 157 | kind: 2, 158 | attributes: toAttributes(Object.fromEntries(span.attributes)), 159 | }, 160 | ], 161 | }, 162 | ], 163 | }, 164 | ], 165 | }; 166 | } 167 | 168 | function otlpExporter(url, headers) { 169 | return function (span) { 170 | fetch(url, { 171 | method: "POST", 172 | headers: { 173 | ...headers, 174 | "Content-Type": "application/json", 175 | }, 176 | body: JSON.stringify(spanToOTLP(span)), 177 | }); 178 | }; 179 | } 180 | 181 | export { Tracing, Span, honoMiddleware, patchFetch, otlpExporter }; 182 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Jeremy Morrell 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------