Socket
Socket
Sign inDemoInstall

@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.2 to 0.0.3

build/src/trace/model/tracer-base.d.ts

6

build/src/exporters/noop_exporter.d.ts

@@ -18,5 +18,5 @@ /**

export declare class NoopExporter implements webTypes.Exporter {
publish(roots: webTypes.RootSpan[]): Promise<number | string | void>;
onStartSpan(root: webTypes.RootSpan): void;
onEndSpan(root: webTypes.RootSpan): void;
publish(roots: webTypes.Span[]): Promise<number | string | void>;
onStartSpan(root: webTypes.Span): void;
onEndSpan(root: webTypes.Span): void;
}

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

export { VERSION } from './version';
export { Annotation, Attributes, BufferConfig, CanonicalCode, Config, Exporter, ExporterConfig, HeaderGetter, HeaderSetter, Link, LinkType, Logger, MessageEvent, MessageEventType, Propagation, SpanContext, SpanEventListener, SpanKind, Status, TracerConfig, TraceState } from '@opencensus/web-types';
export { Annotation, Attributes, BufferConfig, CanonicalCode, Config, Exporter, ExporterConfig, HeaderGetter, HeaderSetter, Link, LinkType, Logger, MessageEvent, MessageEventType, Propagation, SpanContext, SpanEventListener, SpanKind, Status, TracerConfig, TraceState, } from '@opencensus/web-types';
export * from './common/time-util';

@@ -26,0 +26,0 @@ export * from './common/url-util';

@@ -25,3 +25,3 @@ /**

// Re-export types this uses from @opencensus/web-types.
export { CanonicalCode, LinkType, MessageEventType, SpanKind } from '@opencensus/web-types';
export { CanonicalCode, LinkType, MessageEventType, SpanKind, } from '@opencensus/web-types';
export * from './common/time-util';

@@ -28,0 +28,0 @@ export * from './common/url-util';

@@ -19,23 +19,12 @@ /**

/** Simple mock root span for use in use tests. */
export declare class RootSpan extends Span implements webTypes.RootSpan {
export declare class RootSpan extends Span {
/** Trace associated with this root span. */
private readonly tracer;
/** A list of child spans. */
spans: Span[];
constructor(
/** Trace associated with this root span. */
tracer: webTypes.Tracer,
tracer: webTypes.TracerBase,
/** A trace options object to build the root span. */
context?: webTypes.TraceOptions);
/**
* Starts a new child span in the root span.
* @param nameOrOptions Span name string or object with `name` and `kind`
* @param kind Span kind if not using options object.
*/
startChildSpan(nameOrOptions?: string | {
name: string;
kind: webTypes.SpanKind;
}, kind?: webTypes.SpanKind): Span;
start(): void;
end(): void;
}

@@ -42,4 +42,2 @@ /**

_this.tracer = tracer;
/** A list of child spans. */
_this.spans = [];
if (context) {

@@ -60,22 +58,2 @@ _this.name = context.name;

}
/**
* Starts a new child span in the root span.
* @param nameOrOptions Span name string or object with `name` and `kind`
* @param kind Span kind if not using options object.
*/
RootSpan.prototype.startChildSpan = function (nameOrOptions, kind) {
var child = new Span();
child.traceId = this.traceId;
child.traceState = this.traceState;
var spanName = typeof nameOrOptions === 'object' ? nameOrOptions.name : nameOrOptions;
var spanKind = typeof nameOrOptions === 'object' ? nameOrOptions.kind : kind;
if (spanName)
child.name = spanName;
if (spanKind)
child.kind = spanKind;
child.start();
child.parentSpanId = this.id;
this.spans.push(child);
return child;
};
RootSpan.prototype.start = function () {

@@ -82,0 +60,0 @@ _super.prototype.start.call(this);

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

startPerfTime: number;
/** A list of child spans. */
spans: Span[];
/** A number of children. */
private numberOfChildrenLocal;
/**

@@ -83,2 +87,4 @@ * Number of dropped attributes. This is always zero because OpenCensus web

endPerfTime: number;
/** Gets the number of child span created for this span. */
readonly numberOfChildren: number;
/** End time of the span as a Date. */

@@ -92,8 +98,16 @@ readonly endTime: Date;

readonly spanContext: webTypes.SpanContext;
/** Recursively gets the descendant spans. */
allDescendants(): webTypes.Span[];
/**
* Starts a new child span.
* @param [options] A SpanOptions object to start a child span.
*/
startChildSpan(options?: webTypes.SpanOptions): Span;
/**
* Adds an attribute to the span.
* @param key Describes the value added.
* @param value What value to set for the attribute.
* @param value What value to set for the attribute. If the value is a typeof object
* it has to be JSON.stringify-able, cannot contain circular dependencies.
*/
addAttribute(key: string, value: string | number | boolean): void;
addAttribute(key: string, value: string | number | boolean | object): void;
/**

@@ -122,3 +136,3 @@ * Adds an annotation to the span.

*/
addMessageEvent(type: webTypes.MessageEventType, id: string, timestamp?: number): void;
addMessageEvent(type: webTypes.MessageEventType, id: number, timestamp?: number, uncompressedSize?: number, compressedSize?: number): void;
/**

@@ -125,0 +139,0 @@ * Sets a status to the span.

@@ -58,2 +58,4 @@ /**

this.startPerfTime = 0;
/** A list of child spans. */
this.spans = [];
/**

@@ -83,2 +85,3 @@ * Number of dropped attributes. This is always zero because OpenCensus web

this.endPerfTime = 0;
this.numberOfChildrenLocal = 0;
}

@@ -101,2 +104,10 @@ Object.defineProperty(Span.prototype, "isRootSpan", {

});
Object.defineProperty(Span.prototype, "numberOfChildren", {
/** Gets the number of child span created for this span. */
get: function () {
return this.numberOfChildrenLocal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Span.prototype, "endTime", {

@@ -139,9 +150,38 @@ /** End time of the span as a Date. */

});
/** Recursively gets the descendant spans. */
Span.prototype.allDescendants = function () {
return this.spans.reduce(function (acc, cur) {
acc.push(cur);
var desc = cur.allDescendants();
acc = acc.concat(desc);
return acc;
}, []);
};
/**
* Starts a new child span.
* @param [options] A SpanOptions object to start a child span.
*/
Span.prototype.startChildSpan = function (options) {
this.numberOfChildrenLocal++;
var child = new Span();
child.traceId = this.traceId;
child.traceState = this.traceState;
if (options && options.name)
child.name = options.name;
if (options && options.kind)
child.kind = options.kind;
child.start();
child.parentSpanId = this.id;
this.spans.push(child);
return child;
};
/**
* Adds an attribute to the span.
* @param key Describes the value added.
* @param value What value to set for the attribute.
* @param value What value to set for the attribute. If the value is a typeof object
* it has to be JSON.stringify-able, cannot contain circular dependencies.
*/
Span.prototype.addAttribute = function (key, value) {
this.attributes[key] = value;
var serializedValue = typeof value === 'object' ? JSON.stringify(value) : value;
this.attributes[key] = serializedValue;
};

@@ -178,5 +218,11 @@ /**

*/
Span.prototype.addMessageEvent = function (type, id, timestamp) {
Span.prototype.addMessageEvent = function (type, id, timestamp, uncompressedSize, compressedSize) {
if (timestamp === void 0) { timestamp = performance.now(); }
this.messageEvents.push({ type: type, id: id, timestamp: timestamp });
this.messageEvents.push({
type: type,
id: id,
timestamp: timestamp,
uncompressedSize: uncompressedSize,
compressedSize: compressedSize,
});
};

@@ -197,3 +243,5 @@ /**

Span.prototype.end = function () {
this.endPerfTime = performance.now();
if (this.endPerfTime === 0) {
this.endPerfTime = performance.now();
}
};

@@ -200,0 +248,0 @@ /** Forces the span to end. Same as `end` for opencensus-web. */

@@ -17,41 +17,9 @@ /**

import * as webTypes from '@opencensus/web-types';
import { NoHeadersPropagation } from '../propagation/no_headers_propagation';
import { AlwaysSampler } from '../sampler/sampler';
import { RootSpan } from './root-span';
import { Span } from './span';
import { TracerBase } from './tracer-base';
/** Tracer manages the current root span and trace header propagation. */
export declare class Tracer implements webTypes.Tracer {
export declare class Tracer extends TracerBase implements webTypes.Tracer {
/** Get and set the currentRootSpan of the tracer. */
currentRootSpan: RootSpan;
currentRootSpan: Span;
/**
* A sampler used to make trace sample decisions. In the case of
* opencensus-web, ultimate sampling decisions will likely be made by the
* server or agent/collector. So this defaults to sampling every trace.
*/
sampler: AlwaysSampler;
/** An object to log information to. Logs to the JS console by default. */
logger: webTypes.Logger;
/** Trace context header propagation behavior. */
propagation: NoHeadersPropagation;
/** Event listeners for spans managed by the tracer. */
eventListeners: webTypes.SpanEventListener[];
/**
* Active status from tracer instance - this is always true for
* opencensus-web for code simplicity purposes.
*/
active: boolean;
/**
* Trace parameter configuration. Not used by OpenCensus Web, but
* kept for interface compatibility with @opencensus/web-types.
*/
readonly activeTraceParams: {};
/**
* Starts the tracer. This makes the tracer active and sets `logger` and
* `propagation` based on the given config. The `samplingRate` property of
* `config` is currently ignored.
*/
start(config: webTypes.TracerConfig): Tracer;
/** Stops the tracer. This is a no-op with opencensus-web. */
stop(): Tracer;
/**
* Start a new RootSpan to currentRootSpan. Currently opencensus-web only

@@ -65,17 +33,12 @@ * supports a single root span at a time, so this just sets `currentRootSpan`

*/
startRootSpan<T>(options: webTypes.TraceOptions, fn: (root: RootSpan) => T): T;
/** Notifies listeners of the span start. */
onStartSpan(root: webTypes.RootSpan): void;
/** Notifies listeners of the span end. */
onEndSpan(root: webTypes.RootSpan): void;
registerSpanEventListener(listener: webTypes.SpanEventListener): void;
unregisterSpanEventListener(listener: webTypes.SpanEventListener): void;
startRootSpan<T>(options: webTypes.TraceOptions, fn: (root: Span) => T): T;
/** Clears the current root span. */
clearCurrentTrace(): void;
/**
* Start a new Span instance to the currentRootSpan
* @param name Span name
* @param name Span name or SpanOptions object.
* @param kind Span kind
* @returns The new Span instance started
*/
startChildSpan(name?: string, kind?: webTypes.SpanKind): Span;
startChildSpan(options?: webTypes.SpanOptions): Span;
/**

@@ -82,0 +45,0 @@ * Binds the trace context to the given function - but because opencensus-web

@@ -16,49 +16,27 @@ /**

*/
import { NoHeadersPropagation } from '../propagation/no_headers_propagation';
import { AlwaysSampler } from '../sampler/sampler';
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { RootSpan } from './root-span';
var NO_HEADERS_PROPAGATION = new NoHeadersPropagation();
import { TracerBase } from './tracer-base';
/** Tracer manages the current root span and trace header propagation. */
var Tracer = /** @class */ (function () {
var Tracer = /** @class */ (function (_super) {
__extends(Tracer, _super);
function Tracer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/** Get and set the currentRootSpan of the tracer. */
this.currentRootSpan = new RootSpan(this);
/**
* A sampler used to make trace sample decisions. In the case of
* opencensus-web, ultimate sampling decisions will likely be made by the
* server or agent/collector. So this defaults to sampling every trace.
*/
this.sampler = new AlwaysSampler();
/** An object to log information to. Logs to the JS console by default. */
this.logger = console;
/** Trace context header propagation behavior. */
this.propagation = NO_HEADERS_PROPAGATION;
/** Event listeners for spans managed by the tracer. */
this.eventListeners = [];
/**
* Active status from tracer instance - this is always true for
* opencensus-web for code simplicity purposes.
*/
this.active = true;
/**
* Trace parameter configuration. Not used by OpenCensus Web, but
* kept for interface compatibility with @opencensus/web-types.
*/
this.activeTraceParams = {};
_this.currentRootSpan = new RootSpan(_this);
return _this;
}
/**
* Starts the tracer. This makes the tracer active and sets `logger` and
* `propagation` based on the given config. The `samplingRate` property of
* `config` is currently ignored.
*/
Tracer.prototype.start = function (config) {
this.logger = config.logger || console;
this.propagation = config.propagation || NO_HEADERS_PROPAGATION;
return this;
};
/** Stops the tracer. This is a no-op with opencensus-web. */
Tracer.prototype.stop = function () {
return this;
};
/**
* Start a new RootSpan to currentRootSpan. Currently opencensus-web only

@@ -73,26 +51,9 @@ * supports a single root span at a time, so this just sets `currentRootSpan`

Tracer.prototype.startRootSpan = function (options, fn) {
this.currentRootSpan = new RootSpan(this, options);
this.currentRootSpan.start();
return fn(this.currentRootSpan);
var _this = this;
return _super.prototype.startRootSpan.call(this, options, function (root) {
_this.currentRootSpan = root;
return fn(root);
});
};
/** Notifies listeners of the span start. */
Tracer.prototype.onStartSpan = function (root) {
for (var _i = 0, _a = this.eventListeners; _i < _a.length; _i++) {
var listener = _a[_i];
listener.onStartSpan(root);
}
};
/** Notifies listeners of the span end. */
Tracer.prototype.onEndSpan = function (root) {
for (var _i = 0, _a = this.eventListeners; _i < _a.length; _i++) {
var listener = _a[_i];
listener.onEndSpan(root);
}
};
Tracer.prototype.registerSpanEventListener = function (listener) {
this.eventListeners.push(listener);
};
Tracer.prototype.unregisterSpanEventListener = function (listener) {
this.eventListeners = this.eventListeners.filter(function (l) { return l !== listener; });
};
/** Clears the current root span. */
Tracer.prototype.clearCurrentTrace = function () {

@@ -103,8 +64,8 @@ this.currentRootSpan = new RootSpan(this);

* Start a new Span instance to the currentRootSpan
* @param name Span name
* @param name Span name or SpanOptions object.
* @param kind Span kind
* @returns The new Span instance started
*/
Tracer.prototype.startChildSpan = function (name, kind) {
return this.currentRootSpan.startChildSpan(name, kind);
Tracer.prototype.startChildSpan = function (options) {
return _super.prototype.startChildSpan.call(this, Object.assign({ childOf: this.currentRootSpan }, options));
};

@@ -122,4 +83,4 @@ /**

return Tracer;
}());
}(TracerBase));
export { Tracer };
//# sourceMappingURL=tracer.js.map
{
"name": "@opencensus/web-core",
"version": "0.0.2",
"version": "0.0.3",
"description": "OpenCensus Web is a toolkit for collecting application performance and behavior data from client side web browser apps.",

@@ -48,5 +48,6 @@ "main": "build/src/index.js",

"codecov": "^3.3.0",
"gts": "^0.9.0",
"gts": "^1.0.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine": "^3.3.1",
"js-yaml": ">=3.13.1",
"karma": "^4.0.0",

@@ -59,3 +60,3 @@ "karma-chrome-launcher": "^2.2.0",

"rimraf": "^2.6.2",
"ts-loader": "^5.1.0",
"ts-loader": "^6.0.0",
"typescript": "^3.1.6",

@@ -66,5 +67,5 @@ "webpack": "^4.18.0",

"dependencies": {
"@opencensus/web-types": "^0.0.2"
"@opencensus/web-types": "^0.0.3"
},
"sideEffects": false
}
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