@google-cloud/trace-agent
Advanced tools
Comparing version 2.1.3 to 2.2.0
@@ -1,9 +0,29 @@ | ||
# Change Log | ||
# Node.js Agent for Google Cloud Trace ChangeLog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## 2017-09-12, Version 2.2.0 (Beta), @matthewloring | ||
<a name="2.1.3"></a> | ||
## [2.1.3](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/compare/v2.1.2...v2.1.3) (2017-08-01) | ||
### Notable changes | ||
**features** | ||
* [[`0e15b6c95d`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/0e15b6c95d)] - **feat**: Async hooks based context tracking (#538) (Matthew Loring) [#538](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/538) | ||
* [[`debc49331c`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/debc49331c)] - **feat**: add public API for root span id (#542) (Ali Ijaz Sheikh) | ||
* [[`4496d3d6f0`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/4496d3d6f0)] - **feat**: Add GCLOUD_TRACE_CONFIG env config (#539) (Oleg Shalygin) | ||
## Commits | ||
* [[`6f9614a810`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/6f9614a810)] - **test**: restore Function#length property in wrapped mocha test functions when using continuation-local-storage with node 8 (#553) (Kelvin Jin) [#553](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/553) | ||
* [[`e744614e6a`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/e744614e6a)] - **chore**: delete performance scripts (#551) (Kelvin Jin) [#551](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/551) | ||
* [[`68ec8d5e5f`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/68ec8d5e5f)] - Trace API function for trace writer project ID (#548) (Dave Raffensperger) [#548](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/548) | ||
* [[`843e7280da`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/843e7280da)] - **docs**: rewrite gce guide (#549) (Kelvin Jin) [#549](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/549) | ||
* [[`715f8cfb84`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/715f8cfb84)] - **chore**: get rid of commitlint (#543) (Ali Ijaz Sheikh) | ||
* [[`471902a438`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/471902a438)] - **fix**: Account for auth spans in system test (#547) (Matthew Loring) [#547](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/547) | ||
* [[`0e15b6c95d`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/0e15b6c95d)] - **feat**: Async hooks based context tracking (#538) (Matthew Loring) [#538](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/538) | ||
* [[`debc49331c`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/debc49331c)] - **feat**: add public API for root span id (#542) (Ali Ijaz Sheikh) | ||
* [[`a1012058bf`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/a1012058bf)] - Avoid throwing on malformed version in package json (#546) (Matthew Loring) [#546](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/546) | ||
* [[`696cb8d6e4`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/696cb8d6e4)] - Fix http-e2e for node 8.4.0 (#541) (Matthew Loring) [#541](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/541) | ||
* [[`4496d3d6f0`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/commit/4496d3d6f0)] - **feat**: Add GCLOUD_TRACE_CONFIG env config (#539) (Oleg Shalygin) | ||
## 2017-08-01, Version 2.1.3 (Beta), @kjin | ||
### Bug Fixes | ||
@@ -14,6 +34,2 @@ | ||
# Node.js Agent for Google Cloud Trace ChangeLog | ||
## 2017-07-19, Version 2.1.2 (Beta), @kjin | ||
@@ -20,0 +36,0 @@ |
17
index.js
@@ -23,3 +23,6 @@ /** | ||
// patched before any user-land modules get loaded. | ||
require('continuation-local-storage'); | ||
if (require('semver').satisfies(process.version, '<8') || | ||
!process.env.GCLOUD_TRACE_NEW_CONTEXT) { | ||
require('continuation-local-storage'); | ||
} | ||
@@ -57,2 +60,3 @@ var path = require('path'); | ||
function initConfig(projectConfig) { | ||
var envConfig = { | ||
@@ -67,3 +71,12 @@ logLevel: process.env.GCLOUD_TRACE_LOGLEVEL, | ||
}; | ||
var config = extend(true, {}, require('./config.js'), projectConfig, envConfig); | ||
var envSetConfig = {}; | ||
if (process.env.hasOwnProperty('GCLOUD_TRACE_CONFIG')) { | ||
envSetConfig = require(path.resolve(process.env.GCLOUD_TRACE_CONFIG)); | ||
} | ||
// Configuration order of precedence: | ||
// Default < Environment Variable Set Configuration File < Project | ||
var config = extend(true, {}, require('./config.js'), envSetConfig, | ||
projectConfig, envConfig); | ||
// Enforce the upper limit for the label value size. | ||
@@ -70,0 +83,0 @@ if (config.maximumLabelValueSize > constants.TRACE_SERVICE_LABEL_VALUE_LIMIT) { |
{ | ||
"name": "@google-cloud/trace-agent", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"description": "Node.js Support for StackDriver Trace", | ||
@@ -12,5 +12,3 @@ "main": "index.js", | ||
"coverage": "./bin/run-test.sh -c", | ||
"bump": "./bin/run-bump.sh", | ||
"closure": "./node_modules/.bin/closure-npc", | ||
"commitmsg": "commitlint -e" | ||
"bump": "./bin/run-bump.sh" | ||
}, | ||
@@ -28,7 +26,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@commitlint/cli": "^3.0.3", | ||
"@commitlint/config-angular": "^3.0.3", | ||
"@google-cloud/datastore": "^1.0.2", | ||
"changelog-maker": "^2.2.2", | ||
"closure-npc": "*", | ||
"coveralls": "^2.11.8", | ||
@@ -39,3 +34,2 @@ "express": "^4.15.2", | ||
"got": "^5.7.1", | ||
"husky": "^0.14.3", | ||
"istanbul": "^0.4.2", | ||
@@ -42,0 +36,0 @@ "jshint": "^2.9.1", |
@@ -63,2 +63,8 @@ # Stackdriver Trace for Node.js | ||
Alternatively, you can provide configuration through a config file. This can be useful if you want to load our module using `--require` on the command line instead of editing your main script. You can start by copying the default config file and modifying it to suit your needs. The `GCLOUD_TRACE_CONFIG` environment variable should point to your configuration file. | ||
```bash | ||
export GCLOUD_TRACE_CONFIG=./path/to/your/trace/configuration.js | ||
``` | ||
## Running on Google Cloud Platform | ||
@@ -74,8 +80,6 @@ | ||
Your VM instances need to be created with the `https://www.googleapis.com/auth/trace.append` scope if created via the [gcloud](https://cloud.google.com/sdk) CLI or the Google Cloud Platform API, or with the 'Allow API access' checkbox selected if created via the [console][cloud-console] (see screenshot). | ||
For __Google Compute Engine instances__, you need to explicitly enable the `https://www.googleapis.com/auth/trace.append` access scope for each instance. When creating a new instance through the Google Cloud Platform Console, you can do this under __Identity and API access__: Use the Compute Engine default service account, select the __Set access for each API__ access scopes option, and ensure that the __Stackdriver Trace__ access is set to _Write Only_. | ||
![GCE API](doc/images/gce.png?raw=true) | ||
To enable to scope on existing GCE instances, you can follow the instructions for using a service account under [running elsewhere](#running-elsewhere). | ||
If you already have VMs that were created without API access and do not wish to recreate it, you can follow the instructions for using a service account under [running elsewhere](#running-elsewhere). | ||
### Google Container Engine | ||
@@ -82,0 +86,0 @@ |
@@ -19,5 +19,7 @@ /** | ||
var semver = require('semver'); | ||
var cls = semver.satisfies(process.version, '>=8') && | ||
process.env.GCLOUD_TRACE_NEW_CONTEXT ? | ||
require('./cls-ah.js') : require('continuation-local-storage'); | ||
var cls = require('continuation-local-storage'); | ||
/** @const {string} */ | ||
@@ -24,0 +26,0 @@ var TRACE_NAMESPACE = 'com.google.cloud.trace'; |
@@ -27,3 +27,6 @@ /** | ||
var TracingPolicy = require('./tracing-policy.js'); | ||
var semver = require('semver'); | ||
var ROOT_SPAN_STACK_OFFSET = semver.satisfies(process.version, '>=8') ? 0 : 2; | ||
/** | ||
@@ -37,4 +40,6 @@ * Phantom implementation of the trace api. When disabled, a TraceAgent instance | ||
runInRootSpan: function(opts, fn) { return fn(null); }, | ||
getCurrentContextId: function() { return null; }, | ||
createChildSpan: function(opts) { return null; }, | ||
getResponseTraceContext: function(context, traced) { return ''; }, | ||
getWriterProjectId : function() { return null; }, | ||
wrap: function(fn) { return fn; }, | ||
@@ -174,3 +179,3 @@ wrapEmitter: function(ee) {}, | ||
true, /* Is root span */ | ||
options.skipFrames ? options.skipFrames + 2 : 2); | ||
ROOT_SPAN_STACK_OFFSET + (options.skipFrames || 0)); | ||
rootContext.span.kind = 'RPC_SERVER'; | ||
@@ -183,2 +188,27 @@ cls.setRootContext(rootContext); | ||
/** | ||
* Returns a unique identifier for the currently active context. This can be | ||
* used to uniquely identify the current root span. If there is no current, | ||
* context, or if we have lost context, this will return null. The structure and | ||
* the length of the returned string should be treated opaquely - the only | ||
* guarantee is that the value would unique for every root span. | ||
* @returns {string} an id for the current context, or null if there is none | ||
*/ | ||
TraceAgent.prototype.getCurrentContextId = function() { | ||
const rootSpan = cls.getRootContext(); | ||
if (!rootSpan || rootSpan === nullSpan) { | ||
return null; | ||
} | ||
return rootSpan.trace.traceId; | ||
}; | ||
/** | ||
* Returns the projectId that was either configured or auto-discovered by the | ||
* TraceWriter. Note that the auto-discovery is done asynchronously, so this | ||
* may return falsey until the projectId auto-discovery completes. | ||
*/ | ||
TraceAgent.prototype.getWriterProjectId = function() { | ||
return this.config_.projectId; | ||
}; | ||
/** | ||
* Creates and returns a new ChildSpan object nested within the root span. If | ||
@@ -185,0 +215,0 @@ * there is no current RootSpan object, this function returns null. |
@@ -102,14 +102,16 @@ /** | ||
patchSet = {}; | ||
plugin.forEach(function(patch) { | ||
if (!patch.versions || semver.satisfies(version, patch.versions)) { | ||
var file = patch.file || ''; | ||
patchSet[file] = { | ||
file: file, | ||
patch: patch.patch, | ||
unpatch: patch.unpatch, | ||
intercept: patch.intercept | ||
}; | ||
checkPatch(patchSet[file]); | ||
} | ||
}); | ||
if (semver.valid(version)) { | ||
plugin.forEach(function(patch) { | ||
if (!patch.versions || semver.satisfies(version, patch.versions)) { | ||
var file = patch.file || ''; | ||
patchSet[file] = { | ||
file: file, | ||
patch: patch.patch, | ||
unpatch: patch.unpatch, | ||
intercept: patch.intercept | ||
}; | ||
checkPatch(patchSet[file]); | ||
} | ||
}); | ||
} | ||
if (Object.keys(patchSet).length === 0) { | ||
@@ -116,0 +118,0 @@ logger_.warn(moduleRoot + ': version ' + version + ' not supported ' + |
@@ -43,3 +43,7 @@ /* | ||
const uuid = require('uuid'); | ||
const semver = require('semver'); | ||
const usingAsyncHooks = semver.satisfies(process.version, '>=8') && | ||
process.env.GCLOUD_TRACE_NEW_CONTEXT; | ||
// TODO(ofrobots): this code should be moved to a better location. Perhaps | ||
@@ -132,4 +136,8 @@ // google-auto-auth or google-auth-library. | ||
const trace = traces[0]; | ||
console.log(trace); | ||
assert.equal(trace.spans.length, 2, 'should be 2 spans: parent, child'); | ||
if (usingAsyncHooks) { | ||
assert.equal(trace.spans.length, 3, 'should be 3 spans: parent, child, auth'); | ||
assert.equal(trace.spans[2].name, 'accounts.google.com'); | ||
} else { | ||
assert.equal(trace.spans.length, 2, 'should be 2 spans: parent, child'); | ||
} | ||
const parent = trace.spans[0]; | ||
@@ -136,0 +144,0 @@ const child = trace.spans[1]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
299019
16
47
3541
241
22
1