Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opencensus/web-core

Package Overview
Dependencies
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opencensus/web-core - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

build/src/common/sampling-util.d.ts

3

build/src/index.d.ts

@@ -20,3 +20,4 @@ /**

export { Tracing } from './trace/model/tracing';
export * from './trace/model/util';
export { isSampled, makeRandomSamplingDecision } from './common/sampling-util';
export { WindowWithOcwGlobals } from './trace/model/types';
export * from './trace/model/attribute-keys';

@@ -23,0 +24,0 @@ export { VERSION } from './version';

@@ -21,3 +21,3 @@ /**

export { Tracing } from './trace/model/tracing';
export * from './trace/model/util';
export { isSampled, makeRandomSamplingDecision } from './common/sampling-util';
export * from './trace/model/attribute-keys';

@@ -32,4 +32,4 @@ export { VERSION } from './version';

import { Tracing } from './trace/model/tracing';
var tracing = new Tracing();
var tracing = Tracing.instance;
export { tracing };
//# sourceMappingURL=index.js.map

@@ -76,1 +76,5 @@ /**

export declare const ATTRIBUTE_LONG_TASK_ATTRIBUTION: string;
/**
* Attribute for spans to be related back to the initial load trace.
*/
export declare const ATTRIBUTE_INITIAL_LOAD_TRACE_ID = "initial_load_trace_id";

@@ -85,2 +85,6 @@ /**

export var ATTRIBUTE_LONG_TASK_ATTRIBUTION = LONG_TASK_PREFIX + "attribution";
/**
* Attribute for spans to be related back to the initial load trace.
*/
export var ATTRIBUTE_INITIAL_LOAD_TRACE_ID = 'initial_load_trace_id';
//# sourceMappingURL=attribute-keys.js.map

@@ -126,3 +126,3 @@ /**

TracerBase.prototype.setCurrentRootSpan = function (root) {
// no-op, this is only required in case of tracer with cls.
// no-op, this is only required in case of tracer with Zones.
};

@@ -129,0 +129,0 @@ return TracerBase;

@@ -21,9 +21,24 @@ /**

export declare class Tracer extends TracerBase implements webTypes.Tracer {
/** Get and set the currentRootSpan of the tracer. */
private static singletonInstance;
/** Gets the tracer instance. */
static readonly instance: Tracer;
private currentRootSpanNoZone;
/**
* Gets the current root span associated to Zone.current.
* If the current zone does not have a root span (e.g. root zone) or
* `Zone` is not present return the value store in the unique root span.
*/
/**
* Sets the current root span to the current Zone.
* If the current zone does not have a 'data' property (e.g. root zone)
* or `Zone` is not present, just assign the root span to a variable.
*/
currentRootSpan: Span;
/**
* Start a new RootSpan to currentRootSpan. Currently opencensus-web only
* supports a single root span at a time, so this just sets `currentRootSpan`
* to a new root span based on the given options and invokes the passed
* function. Currently no sampling decisions are propagated or made here.
* Creates a new Zone (in case `Zone` global variable is present) and start
* a new RootSpan to `currentRootSpan` associating the new RootSpan to the
* new Zone. Thus, there might be several root spans at the same time.
* If `Zone` is not present, just create the root span and store it in the current
* root span.
* Currently no sampling decisions are propagated or made here.
* @param options Options for tracer instance

@@ -51,2 +66,3 @@ * @param fn Callback function

wrapEmitter(emitter: webTypes.NodeJsEventEmitter): void;
isZonePresent(): boolean;
}

@@ -31,2 +31,3 @@ /**

import { TracerBase } from './tracer-base';
import { randomTraceId } from '../../common/id-util';
/** Tracer manages the current root span and trace header propagation. */

@@ -37,11 +38,50 @@ var Tracer = /** @class */ (function (_super) {

var _this = _super !== null && _super.apply(this, arguments) || this;
/** Get and set the currentRootSpan of the tracer. */
_this.currentRootSpan = new RootSpan(_this);
// Variable to store current root span in case the Zone global variable is not present.
// For that case we only need to store only one current root span.
_this.currentRootSpanNoZone = new RootSpan(_this);
return _this;
}
Object.defineProperty(Tracer, "instance", {
/** Gets the tracer instance. */
get: function () {
return this.singletonInstance || (this.singletonInstance = new this());
},
enumerable: true,
configurable: true
});
Object.defineProperty(Tracer.prototype, "currentRootSpan", {
/**
* Gets the current root span associated to Zone.current.
* If the current zone does not have a root span (e.g. root zone) or
* `Zone` is not present return the value store in the unique root span.
*/
get: function () {
if (this.isZonePresent() && Zone.current.get('data')) {
return Zone.current.get('data').rootSpan;
}
return this.currentRootSpanNoZone;
},
/**
* Sets the current root span to the current Zone.
* If the current zone does not have a 'data' property (e.g. root zone)
* or `Zone` is not present, just assign the root span to a variable.
*/
set: function (root) {
if (this.isZonePresent() && Zone.current.get('data')) {
Zone.current.get('data')['rootSpan'] = root;
}
else {
this.currentRootSpanNoZone = root;
}
},
enumerable: true,
configurable: true
});
/**
* Start a new RootSpan to currentRootSpan. Currently opencensus-web only
* supports a single root span at a time, so this just sets `currentRootSpan`
* to a new root span based on the given options and invokes the passed
* function. Currently no sampling decisions are propagated or made here.
* Creates a new Zone (in case `Zone` global variable is present) and start
* a new RootSpan to `currentRootSpan` associating the new RootSpan to the
* new Zone. Thus, there might be several root spans at the same time.
* If `Zone` is not present, just create the root span and store it in the current
* root span.
* Currently no sampling decisions are propagated or made here.
* @param options Options for tracer instance

@@ -53,3 +93,28 @@ * @param fn Callback function

var _this = this;
if (this.isZonePresent()) {
var traceId = randomTraceId();
if (options.spanContext && options.spanContext.traceId) {
traceId = options.spanContext.traceId;
}
// Create the new zone.
var zoneSpec = {
name: traceId,
properties: {
data: {
isTracingZone: true,
traceId: traceId,
},
},
};
var newZone = Zone.current.fork(zoneSpec);
return newZone.run(function () {
_super.prototype.startRootSpan.call(_this, options, function (root) {
// Set the currentRootSpan to the new created root span.
_this.currentRootSpan = root;
return fn(root);
});
});
}
return _super.prototype.startRootSpan.call(this, options, function (root) {
// Set the currentRootSpan to the new created root span.
_this.currentRootSpan = root;

@@ -82,2 +147,5 @@ return fn(root);

Tracer.prototype.wrapEmitter = function (emitter) { };
Tracer.prototype.isZonePresent = function () {
return !!window.Zone;
};
return Tracer;

@@ -84,0 +152,0 @@ }(TracerBase));

@@ -28,2 +28,6 @@ /**

active: boolean;
/** Singleton instance */
private static singletonInstance;
/** Gets the tracing instance. */
static readonly instance: Tracing;
/** Sets tracer and exporter config. */

@@ -30,0 +34,0 @@ start(config?: webTypes.Config): webTypes.Tracing;

@@ -23,3 +23,3 @@ /**

/** Object responsible for managing a trace. */
this.tracer = new Tracer();
this.tracer = Tracer.instance;
/** Service to send collected traces to. */

@@ -30,2 +30,10 @@ this.exporter = NOOP_EXPORTER;

}
Object.defineProperty(Tracing, "instance", {
/** Gets the tracing instance. */
get: function () {
return this.singletonInstance || (this.singletonInstance = new this());
},
enumerable: true,
configurable: true
});
/** Sets tracer and exporter config. */

@@ -32,0 +40,0 @@ Tracing.prototype.start = function (config) {

{
"name": "@opencensus/web-core",
"version": "0.0.3",
"version": "0.0.4",
"description": "OpenCensus Web is a toolkit for collecting application performance and behavior data from client side web browser apps.",

@@ -53,3 +53,3 @@ "main": "build/src/index.js",

"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage-istanbul-reporter": "^2.0.4",

@@ -63,8 +63,10 @@ "karma-jasmine": "^2.0.1",

"webpack": "^4.18.0",
"webpack-cli": "^3.1.0"
"webpack-cli": "^3.1.0",
"zone.js": "^0.10.1"
},
"dependencies": {
"@opencensus/web-types": "^0.0.3"
"@opencensus/web-types": "^0.0.4",
"@types/node": "^12.6.9"
},
"sideEffects": false
}

@@ -6,3 +6,3 @@ # OpenCensus Web Core (Trace Model)

This package combines contains the core trace model used by OpenCensus Web. This
This package contains the core trace model used by OpenCensus Web. This
trace model is based on the same TypeScript interfaces that

@@ -17,4 +17,6 @@ [OpenCensus Node](https://github.com/census-instrumentation/opencensus-node)

Currently the primary intended usage of OpenCensus Web is to collect
spans from the resource timing waterfall of an initial page load. See the
[OpenCensus Web readme][oc-web-readme-url] for details.
spans from the resource timing waterfall of an initial page load
and trace on-page user interactions with a series of features like automatic tracing
for *clicks* and *route transitions*, *custom spans*, and browser [Performance API][performance-api] data.
See the [OpenCensus Web readme][oc-web-readme-url] for details.

@@ -40,5 +42,3 @@ In the future we would like to make it easy to generate custom spans that will

[license-url]: https://github.com/census-instrumentation/opencensus-web/blob/master/packages/opencensus-web-core/LICENSE
[long-tasks-url]: https://w3c.github.io/longtasks/
[resource-timing-buffer-url]: https://www.w3.org/TR/resource-timing-2/#dom-performance-setresourcetimingbuffersize
[resource-timing-url]: https://www.w3.org/TR/resource-timing-2/
[opencensus-service-url]: https://github.com/census-instrumentation/opencensus-service
[performance-api]: (https://developer.mozilla.org/en-US/docs/Web/API/Performance)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc