Socket
Socket
Sign inDemoInstall

@opentelemetry/tracing

Package Overview
Dependencies
Maintainers
4
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/tracing - npm Package Compare versions

Comparing version 0.19.1-alpha.39 to 0.19.1-alpha.41

build/esm/export/NoopSpanProcessor.d.ts

12

build/esm/BasicTracerProvider.d.ts

@@ -5,3 +5,11 @@ import { TracerProvider, TextMapPropagator } from '@opentelemetry/api';

import { SDKRegistrationConfig, TracerConfig } from './types';
import { SpanExporter } from './export/SpanExporter';
export declare type PROPAGATOR_FACTORY = () => TextMapPropagator;
export declare type EXPORTER_FACTORY = () => SpanExporter;
export declare enum ForceFlushState {
'resolved' = 0,
'timeout' = 1,
'error' = 2,
'unresolved' = 3
}
/**

@@ -12,2 +20,3 @@ * This class represents a basic tracer provider which platform libraries can extend

protected static readonly _registeredPropagators: Map<string, PROPAGATOR_FACTORY>;
protected static readonly _registeredExporters: Map<string, EXPORTER_FACTORY>;
private readonly _config;

@@ -34,6 +43,9 @@ private readonly _registeredSpanProcessors;

register(config?: SDKRegistrationConfig): void;
forceFlush(): Promise<void>;
shutdown(): Promise<void>;
protected _getPropagator(name: string): TextMapPropagator | undefined;
protected _getSpanExporter(name: string): SpanExporter | undefined;
protected _buildPropagatorFromEnv(): TextMapPropagator | undefined;
protected _buildExporterFromEnv(): SpanExporter | undefined;
}
//# sourceMappingURL=BasicTracerProvider.d.ts.map

89

build/esm/BasicTracerProvider.js

@@ -17,3 +17,3 @@ /*

import { trace, context, propagation, diag, } from '@opentelemetry/api';
import { CompositePropagator, HttpTraceContext, HttpBaggage, getEnv, } from '@opentelemetry/core';
import { CompositePropagator, HttpBaggagePropagator, HttpTraceContextPropagator, getEnv, } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';

@@ -23,4 +23,13 @@ import { Tracer } from '.';

import { MultiSpanProcessor } from './MultiSpanProcessor';
import { NoopSpanProcessor } from './NoopSpanProcessor';
import { NoopSpanProcessor } from './export/NoopSpanProcessor';
// eslint-disable-next-line @typescript-eslint/no-var-requires
var merge = require('lodash.merge');
import { BatchSpanProcessor } from './export/BatchSpanProcessor';
export var ForceFlushState;
(function (ForceFlushState) {
ForceFlushState[ForceFlushState["resolved"] = 0] = "resolved";
ForceFlushState[ForceFlushState["timeout"] = 1] = "timeout";
ForceFlushState[ForceFlushState["error"] = 2] = "error";
ForceFlushState[ForceFlushState["unresolved"] = 3] = "unresolved";
})(ForceFlushState || (ForceFlushState = {}));
/**

@@ -35,3 +44,2 @@ * This class represents a basic tracer provider which platform libraries can extend

this._tracers = new Map();
this.activeSpanProcessor = new NoopSpanProcessor();
var mergedConfig = merge({}, DEFAULT_CONFIG, config);

@@ -43,2 +51,10 @@ this.resource =

});
var defaultExporter = this._buildExporterFromEnv();
if (defaultExporter !== undefined) {
var batchProcessor = new BatchSpanProcessor(defaultExporter);
this.activeSpanProcessor = batchProcessor;
}
else {
this.activeSpanProcessor = new NoopSpanProcessor();
}
}

@@ -57,2 +73,11 @@ BasicTracerProvider.prototype.getTracer = function (name, version) {

BasicTracerProvider.prototype.addSpanProcessor = function (spanProcessor) {
if (this._registeredSpanProcessors.length === 0) {
// since we might have enabled by default a batchProcessor, we disable it
// before adding the new one
this.activeSpanProcessor
.shutdown()
.catch(function (err) {
return diag.error('Error while trying to shutdown current span processor', err);
});
}
this._registeredSpanProcessors.push(spanProcessor);

@@ -84,2 +109,41 @@ this.activeSpanProcessor = new MultiSpanProcessor(this._registeredSpanProcessors);

};
BasicTracerProvider.prototype.forceFlush = function () {
var timeout = this._config.forceFlushTimeoutMillis;
var promises = this._registeredSpanProcessors.map(function (spanProcessor) {
return new Promise(function (resolve) {
var state;
var timeoutInterval = setTimeout(function () {
resolve(new Error("Span processor did not completed within timeout period of " + timeout + " ms"));
state = ForceFlushState.timeout;
}, timeout);
spanProcessor
.forceFlush()
.then(function () {
clearTimeout(timeoutInterval);
if (state !== ForceFlushState.timeout) {
state = ForceFlushState.resolved;
resolve(state);
}
})
.catch(function (error) {
clearTimeout(timeoutInterval);
state = ForceFlushState.error;
resolve(error);
});
});
});
return new Promise(function (resolve, reject) {
Promise.all(promises)
.then(function (results) {
var errors = results.filter(function (result) { return result !== ForceFlushState.resolved; });
if (errors.length > 0) {
reject(errors);
}
else {
resolve();
}
})
.catch(function (error) { return reject([error]); });
});
};
BasicTracerProvider.prototype.shutdown = function () {

@@ -92,2 +156,6 @@ return this.activeSpanProcessor.shutdown();

};
BasicTracerProvider.prototype._getSpanExporter = function (name) {
var _a;
return (_a = BasicTracerProvider._registeredExporters.get(name)) === null || _a === void 0 ? void 0 : _a();
};
BasicTracerProvider.prototype._buildPropagatorFromEnv = function () {

@@ -122,6 +190,17 @@ var _this = this;

};
BasicTracerProvider.prototype._buildExporterFromEnv = function () {
var exporterName = getEnv().OTEL_TRACES_EXPORTER;
if (exporterName === 'none')
return;
var exporter = this._getSpanExporter(exporterName);
if (!exporter) {
diag.error("Exporter \"" + exporterName + "\" requested through environment variable is unavailable.");
}
return exporter;
};
BasicTracerProvider._registeredPropagators = new Map([
['tracecontext', function () { return new HttpTraceContext(); }],
['baggage', function () { return new HttpBaggage(); }],
['tracecontext', function () { return new HttpTraceContextPropagator(); }],
['baggage', function () { return new HttpBaggagePropagator(); }],
]);
BasicTracerProvider._registeredExporters = new Map();
return BasicTracerProvider;

@@ -128,0 +207,0 @@ }());

13

build/esm/config.d.ts
import { Sampler } from '@opentelemetry/api';
import { ENVIRONMENT } from '@opentelemetry/core/src/utils/environment';
import { ENVIRONMENT } from '@opentelemetry/core';
/**
* Default configuration. For fields with primitive values, any user-provided
* value will override the corresponding default value. For fields with
* non-primitive values (like `traceParams`), the user-provided value will be
* non-primitive values (like `spanLimits`), the user-provided value will be
* used to extend the default value.

@@ -11,6 +11,7 @@ */

sampler: Sampler;
traceParams: {
numberOfAttributesPerSpan: number;
numberOfLinksPerSpan: number;
numberOfEventsPerSpan: number;
forceFlushTimeoutMillis: number;
spanLimits: {
attributeCountLimit: number;
linkCountLimit: number;
eventCountLimit: number;
};

@@ -17,0 +18,0 @@ };

@@ -19,6 +19,7 @@ /*

var env = getEnv();
var FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn;
/**
* Default configuration. For fields with primitive values, any user-provided
* value will override the corresponding default value. For fields with
* non-primitive values (like `traceParams`), the user-provided value will be
* non-primitive values (like `spanLimits`), the user-provided value will be
* used to extend the default value.

@@ -28,9 +29,9 @@ */

sampler: buildSamplerFromEnv(env),
traceParams: {
numberOfAttributesPerSpan: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
numberOfLinksPerSpan: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
numberOfEventsPerSpan: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
forceFlushTimeoutMillis: 30000,
spanLimits: {
attributeCountLimit: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
linkCountLimit: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
eventCountLimit: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
},
};
var FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn;
/**

@@ -37,0 +38,0 @@ * Based on environment, builds a sampler, complies with specification.

@@ -16,4 +16,4 @@ /*

*/
import { context, suppressInstrumentation } from '@opentelemetry/api';
import { ExportResultCode, globalErrorHandler, unrefTimer, getEnv, } from '@opentelemetry/core';
import { context } from '@opentelemetry/api';
import { ExportResultCode, getEnv, globalErrorHandler, suppressTracing, unrefTimer, } from '@opentelemetry/core';
/**

@@ -124,3 +124,3 @@ * Implementation of the {@link SpanProcessor} that batches spans exported by

// prevent downstream exporter calls from generating spans
context.with(suppressInstrumentation(context.active()), function () {
context.with(suppressTracing(context.active()), function () {
// Reset the finished spans buffer here because the next invocations of the _flush method

@@ -127,0 +127,0 @@ // could pass the same finished spans to the exporter if the buffer is cleared

@@ -46,6 +46,6 @@ /*

return {
traceId: span.spanContext.traceId,
traceId: span.spanContext().traceId,
parentId: span.parentSpanId,
name: span.name,
id: span.spanContext.spanId,
id: span.spanContext().spanId,
kind: span.kind,

@@ -52,0 +52,0 @@ timestamp: hrTimeToMicroseconds(span.startTime),

@@ -1,8 +0,9 @@

import { SpanKind, SpanStatus, SpanAttributes, HrTime, Link, SpanContext, TimedEvent } from '@opentelemetry/api';
import { SpanKind, SpanStatus, SpanAttributes, HrTime, Link, SpanContext } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { TimedEvent } from '../TimedEvent';
export interface ReadableSpan {
readonly name: string;
readonly kind: SpanKind;
readonly spanContext: SpanContext;
readonly spanContext: () => SpanContext;
readonly parentSpanId?: string;

@@ -9,0 +10,0 @@ readonly startTime: HrTime;

import { Span } from '../Span';
import { SpanExporter } from './SpanExporter';
import { SpanProcessor } from '../SpanProcessor';
import { ReadableSpan } from './ReadableSpan';
import { SpanExporter } from './SpanExporter';
/**

@@ -6,0 +6,0 @@ * An implementation of the {@link SpanProcessor} that converts the {@link Span}

@@ -16,4 +16,4 @@ /*

*/
import { context, suppressInstrumentation } from '@opentelemetry/api';
import { ExportResultCode, globalErrorHandler } from '@opentelemetry/core';
import { context } from '@opentelemetry/api';
import { ExportResultCode, globalErrorHandler, suppressTracing, } from '@opentelemetry/core';
/**

@@ -43,3 +43,3 @@ * An implementation of the {@link SpanProcessor} that converts the {@link Span}

// prevent downstream exporter calls from generating spans
context.with(suppressInstrumentation(context.active()), function () {
context.with(suppressTracing(context.active()), function () {
_this._exporter.export([span], function (result) {

@@ -46,0 +46,0 @@ var _a;

@@ -9,5 +9,7 @@ export * from './Tracer';

export * from './export/SpanExporter';
export * from './export/NoopSpanProcessor';
export * from './Span';
export * from './SpanProcessor';
export * from './TimedEvent';
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -24,5 +24,7 @@ /*

export * from './export/SpanExporter';
export * from './export/NoopSpanProcessor';
export * from './Span';
export * from './SpanProcessor';
export * from './TimedEvent';
export * from './types';
//# sourceMappingURL=index.js.map

@@ -5,2 +5,3 @@ import * as api from '@opentelemetry/api';

import { ReadableSpan } from './export/ReadableSpan';
import { TimedEvent } from './TimedEvent';
import { Tracer } from './Tracer';

@@ -12,3 +13,3 @@ import { SpanAttributeValue, Context } from '@opentelemetry/api';

export declare class Span implements api.Span, ReadableSpan {
readonly spanContext: api.SpanContext;
private readonly _spanContext;
readonly kind: api.SpanKind;

@@ -18,3 +19,3 @@ readonly parentSpanId?: string;

readonly links: api.Link[];
readonly events: api.TimedEvent[];
readonly events: TimedEvent[];
readonly startTime: api.HrTime;

@@ -29,6 +30,6 @@ readonly resource: Resource;

private readonly _spanProcessor;
private readonly _traceParams;
private readonly _spanLimits;
/** Constructs a new Span instance. */
constructor(parentTracer: Tracer, context: Context, spanName: string, spanContext: api.SpanContext, kind: api.SpanKind, parentSpanId?: string, links?: api.Link[], startTime?: api.TimeInput);
context(): api.SpanContext;
spanContext(): api.SpanContext;
setAttribute(key: string, value?: SpanAttributeValue): this;

@@ -35,0 +36,0 @@ setAttributes(attributes: api.SpanAttributes): this;

@@ -38,3 +38,3 @@ /*

this.name = spanName;
this.spanContext = spanContext;
this._spanContext = spanContext;
this.parentSpanId = parentSpanId;

@@ -46,8 +46,8 @@ this.kind = kind;

this.instrumentationLibrary = parentTracer.instrumentationLibrary;
this._traceParams = parentTracer.getActiveTraceParams();
this._spanLimits = parentTracer.getSpanLimits();
this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this, context);
}
Span.prototype.context = function () {
return this.spanContext;
Span.prototype.spanContext = function () {
return this._spanContext;
};

@@ -66,3 +66,3 @@ Span.prototype.setAttribute = function (key, value) {

if (Object.keys(this.attributes).length >=
this._traceParams.numberOfAttributesPerSpan &&
this._spanLimits.attributeCountLimit &&
!Object.prototype.hasOwnProperty.call(this.attributes, key)) {

@@ -91,3 +91,3 @@ return this;

return this;
if (this.events.length >= this._traceParams.numberOfEventsPerSpan) {
if (this.events.length >= this._spanLimits.eventCountLimit) {
api.diag.warn('Dropping extra events.');

@@ -186,3 +186,3 @@ this.events.shift();

if (this._ended) {
api.diag.warn('Can not execute the operation on ended Span {traceId: %s, spanId: %s}', this.spanContext.traceId, this.spanContext.spanId);
api.diag.warn('Can not execute the operation on ended Span {traceId: %s, spanId: %s}', this._spanContext.traceId, this._spanContext.spanId);
}

@@ -189,0 +189,0 @@ return this._ended;

@@ -5,3 +5,3 @@ import * as api from '@opentelemetry/api';

import { BasicTracerProvider } from './BasicTracerProvider';
import { TraceParams, TracerConfig } from './types';
import { SpanLimits, TracerConfig } from './types';
/**

@@ -13,3 +13,3 @@ * This class represents a basic tracer.

private readonly _sampler;
private readonly _traceParams;
private readonly _spanLimits;
private readonly _idGenerator;

@@ -22,2 +22,3 @@ readonly resource: Resource;

constructor(instrumentationLibrary: InstrumentationLibrary, config: TracerConfig, _tracerProvider: BasicTracerProvider);
startActiveSpan<F extends (span: api.Span) => ReturnType<F>>(name: string, arg2: F | api.SpanOptions, arg3?: F | api.Context, arg4?: F): ReturnType<F> | undefined;
/**

@@ -28,6 +29,6 @@ * Starts a new Span or returns the default NoopSpan based on the sampling

startSpan(name: string, options?: api.SpanOptions, context?: api.Context): api.Span;
/** Returns the active {@link TraceParams}. */
getActiveTraceParams(): TraceParams;
/** Returns the active {@link SpanLimits}. */
getSpanLimits(): SpanLimits;
getActiveSpanProcessor(): import("./SpanProcessor").SpanProcessor;
}
//# sourceMappingURL=Tracer.d.ts.map

@@ -17,3 +17,3 @@ /*

import * as api from '@opentelemetry/api';
import { RandomIdGenerator, sanitizeAttributes, } from '@opentelemetry/core';
import { RandomIdGenerator, sanitizeAttributes, isTracingSuppressed, } from '@opentelemetry/core';
import { Span } from './Span';

@@ -32,3 +32,3 @@ import { mergeConfig } from './utility';

this._sampler = localConfig.sampler;
this._traceParams = localConfig.traceParams;
this._spanLimits = localConfig.spanLimits;
this._idGenerator = config.idGenerator || new RandomIdGenerator();

@@ -38,2 +38,29 @@ this.resource = _tracerProvider.resource;

}
Tracer.prototype.startActiveSpan = function (name, arg2, arg3, arg4) {
var fn, options, activeContext;
if (arguments.length === 2 && typeof arg2 === 'function') {
fn = arg2;
}
else if (arguments.length === 3 &&
typeof arg2 === 'object' &&
typeof arg3 === 'function') {
options = arg2;
fn = arg3;
}
else if (arguments.length === 4 &&
typeof arg2 === 'object' &&
typeof arg3 === 'object' &&
typeof arg4 === 'function') {
options = arg2;
activeContext = arg3;
fn = arg4;
}
var parentContext = activeContext !== null && activeContext !== void 0 ? activeContext : api.context.active();
var span = this.startSpan(name, options, parentContext);
var contextWithSpanSet = api.trace.setSpan(parentContext, span);
if (fn) {
return api.context.with(contextWithSpanSet, fn, undefined, span);
}
return;
};
/**

@@ -47,5 +74,5 @@ * Starts a new Span or returns the default NoopSpan based on the sampling

if (context === void 0) { context = api.context.active(); }
if (api.isInstrumentationSuppressed(context)) {
if (isTracingSuppressed(context)) {
api.diag.debug('Instrumentation suppressed, returning Noop Span');
return api.NOOP_TRACER.startSpan(name, options, context);
return api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
}

@@ -71,3 +98,5 @@ var parentContext = getParent(options, context);

// make sampling decision
var samplingResult = this._sampler.shouldSample(context, traceId, name, spanKind, attributes, links);
var samplingResult = this._sampler.shouldSample(options.root
? api.trace.setSpanContext(context, api.INVALID_SPAN_CONTEXT)
: context, traceId, name, spanKind, attributes, links);
var traceFlags = samplingResult.decision === api.SamplingDecision.RECORD_AND_SAMPLED

@@ -78,4 +107,4 @@ ? api.TraceFlags.SAMPLED

if (samplingResult.decision === api.SamplingDecision.NOT_RECORD) {
api.diag.debug('Recording is off, starting no recording span');
return api.NOOP_TRACER.startSpan(name, options, api.setSpanContext(context, spanContext));
api.diag.debug('Recording is off, propagating context in a non-recording span');
return api.trace.wrapSpanContext(spanContext);
}

@@ -87,5 +116,5 @@ var span = new Span(this, context, name, spanContext, spanKind, parentSpanId, links, options.startTime);

};
/** Returns the active {@link TraceParams}. */
Tracer.prototype.getActiveTraceParams = function () {
return this._traceParams;
/** Returns the active {@link SpanLimits}. */
Tracer.prototype.getSpanLimits = function () {
return this._spanLimits;
};

@@ -108,4 +137,4 @@ Tracer.prototype.getActiveSpanProcessor = function () {

return undefined;
return api.getSpanContext(context);
return api.trace.getSpanContext(context);
}
//# sourceMappingURL=Tracer.js.map

@@ -13,4 +13,4 @@ import { TextMapPropagator, Sampler } from '@opentelemetry/api';

sampler?: Sampler;
/** Trace Parameters */
traceParams?: TraceParams;
/** Span Limits */
spanLimits?: SpanLimits;
/** Resource associated with trace telemetry */

@@ -23,2 +23,7 @@ resource?: Resource;

idGenerator?: IdGenerator;
/**
* How long the forceFlush can run before it is cancelled.
* The default value is 30000ms
*/
forceFlushTimeoutMillis?: number;
}

@@ -37,9 +42,9 @@ /**

/** Global configuration of trace service */
export interface TraceParams {
/** numberOfAttributesPerSpan is number of attributes per span */
numberOfAttributesPerSpan?: number;
/** numberOfLinksPerSpan is number of links per span */
numberOfLinksPerSpan?: number;
/** numberOfEventsPerSpan is number of message events per span */
numberOfEventsPerSpan?: number;
export interface SpanLimits {
/** attributeCountLimit is number of attributes per span */
attributeCountLimit?: number;
/** linkCountLimit is number of links per span */
linkCountLimit?: number;
/** eventCountLimit is number of message events per span */
eventCountLimit?: number;
}

@@ -46,0 +51,0 @@ /** Interface configuration for a buffer. */

@@ -8,8 +8,9 @@ import { TracerConfig } from './types';

sampler: import("@opentelemetry/api").Sampler;
traceParams: {
numberOfAttributesPerSpan: number;
numberOfLinksPerSpan: number;
numberOfEventsPerSpan: number;
forceFlushTimeoutMillis: number;
spanLimits: {
attributeCountLimit: number;
linkCountLimit: number;
eventCountLimit: number;
};
} & Partial<TracerConfig> & TracerConfig;
//# sourceMappingURL=utility.d.ts.map

@@ -26,5 +26,5 @@ /*

var target = Object.assign({}, DEFAULT_CONFIG, perInstanceDefaults, userConfig);
target.traceParams = Object.assign({}, DEFAULT_CONFIG.traceParams, userConfig.traceParams || {});
target.spanLimits = Object.assign({}, DEFAULT_CONFIG.spanLimits, userConfig.spanLimits || {});
return target;
}
//# sourceMappingURL=utility.js.map

@@ -5,3 +5,11 @@ import { TracerProvider, TextMapPropagator } from '@opentelemetry/api';

import { SDKRegistrationConfig, TracerConfig } from './types';
import { SpanExporter } from './export/SpanExporter';
export declare type PROPAGATOR_FACTORY = () => TextMapPropagator;
export declare type EXPORTER_FACTORY = () => SpanExporter;
export declare enum ForceFlushState {
'resolved' = 0,
'timeout' = 1,
'error' = 2,
'unresolved' = 3
}
/**

@@ -12,2 +20,3 @@ * This class represents a basic tracer provider which platform libraries can extend

protected static readonly _registeredPropagators: Map<string, PROPAGATOR_FACTORY>;
protected static readonly _registeredExporters: Map<string, EXPORTER_FACTORY>;
private readonly _config;

@@ -34,6 +43,9 @@ private readonly _registeredSpanProcessors;

register(config?: SDKRegistrationConfig): void;
forceFlush(): Promise<void>;
shutdown(): Promise<void>;
protected _getPropagator(name: string): TextMapPropagator | undefined;
protected _getSpanExporter(name: string): SpanExporter | undefined;
protected _buildPropagatorFromEnv(): TextMapPropagator | undefined;
protected _buildExporterFromEnv(): SpanExporter | undefined;
}
//# sourceMappingURL=BasicTracerProvider.d.ts.map

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.BasicTracerProvider = void 0;
exports.BasicTracerProvider = exports.ForceFlushState = void 0;
const api_1 = require("@opentelemetry/api");

@@ -26,4 +26,13 @@ const core_1 = require("@opentelemetry/core");

const MultiSpanProcessor_1 = require("./MultiSpanProcessor");
const NoopSpanProcessor_1 = require("./NoopSpanProcessor");
const NoopSpanProcessor_1 = require("./export/NoopSpanProcessor");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const merge = require('lodash.merge');
const BatchSpanProcessor_1 = require("./export/BatchSpanProcessor");
var ForceFlushState;
(function (ForceFlushState) {
ForceFlushState[ForceFlushState["resolved"] = 0] = "resolved";
ForceFlushState[ForceFlushState["timeout"] = 1] = "timeout";
ForceFlushState[ForceFlushState["error"] = 2] = "error";
ForceFlushState[ForceFlushState["unresolved"] = 3] = "unresolved";
})(ForceFlushState = exports.ForceFlushState || (exports.ForceFlushState = {}));
/**

@@ -37,3 +46,2 @@ * This class represents a basic tracer provider which platform libraries can extend

this._tracers = new Map();
this.activeSpanProcessor = new NoopSpanProcessor_1.NoopSpanProcessor();
const mergedConfig = merge({}, config_1.DEFAULT_CONFIG, config);

@@ -45,2 +53,10 @@ this.resource =

});
const defaultExporter = this._buildExporterFromEnv();
if (defaultExporter !== undefined) {
const batchProcessor = new BatchSpanProcessor_1.BatchSpanProcessor(defaultExporter);
this.activeSpanProcessor = batchProcessor;
}
else {
this.activeSpanProcessor = new NoopSpanProcessor_1.NoopSpanProcessor();
}
}

@@ -59,2 +75,9 @@ getTracer(name, version) {

addSpanProcessor(spanProcessor) {
if (this._registeredSpanProcessors.length === 0) {
// since we might have enabled by default a batchProcessor, we disable it
// before adding the new one
this.activeSpanProcessor
.shutdown()
.catch(err => api_1.diag.error('Error while trying to shutdown current span processor', err));
}
this._registeredSpanProcessors.push(spanProcessor);

@@ -85,2 +108,41 @@ this.activeSpanProcessor = new MultiSpanProcessor_1.MultiSpanProcessor(this._registeredSpanProcessors);

}
forceFlush() {
const timeout = this._config.forceFlushTimeoutMillis;
const promises = this._registeredSpanProcessors.map((spanProcessor) => {
return new Promise(resolve => {
let state;
const timeoutInterval = setTimeout(() => {
resolve(new Error(`Span processor did not completed within timeout period of ${timeout} ms`));
state = ForceFlushState.timeout;
}, timeout);
spanProcessor
.forceFlush()
.then(() => {
clearTimeout(timeoutInterval);
if (state !== ForceFlushState.timeout) {
state = ForceFlushState.resolved;
resolve(state);
}
})
.catch(error => {
clearTimeout(timeoutInterval);
state = ForceFlushState.error;
resolve(error);
});
});
});
return new Promise((resolve, reject) => {
Promise.all(promises)
.then(results => {
const errors = results.filter(result => result !== ForceFlushState.resolved);
if (errors.length > 0) {
reject(errors);
}
else {
resolve();
}
})
.catch(error => reject([error]));
});
}
shutdown() {

@@ -93,2 +155,6 @@ return this.activeSpanProcessor.shutdown();

}
_getSpanExporter(name) {
var _a;
return (_a = BasicTracerProvider._registeredExporters.get(name)) === null || _a === void 0 ? void 0 : _a();
}
_buildPropagatorFromEnv() {

@@ -122,8 +188,19 @@ // per spec, propagators from env must be deduplicated

}
_buildExporterFromEnv() {
const exporterName = core_1.getEnv().OTEL_TRACES_EXPORTER;
if (exporterName === 'none')
return;
const exporter = this._getSpanExporter(exporterName);
if (!exporter) {
api_1.diag.error(`Exporter "${exporterName}" requested through environment variable is unavailable.`);
}
return exporter;
}
}
exports.BasicTracerProvider = BasicTracerProvider;
BasicTracerProvider._registeredPropagators = new Map([
['tracecontext', () => new core_1.HttpTraceContext()],
['baggage', () => new core_1.HttpBaggage()],
['tracecontext', () => new core_1.HttpTraceContextPropagator()],
['baggage', () => new core_1.HttpBaggagePropagator()],
]);
BasicTracerProvider._registeredExporters = new Map();
//# sourceMappingURL=BasicTracerProvider.js.map
import { Sampler } from '@opentelemetry/api';
import { ENVIRONMENT } from '@opentelemetry/core/src/utils/environment';
import { ENVIRONMENT } from '@opentelemetry/core';
/**
* Default configuration. For fields with primitive values, any user-provided
* value will override the corresponding default value. For fields with
* non-primitive values (like `traceParams`), the user-provided value will be
* non-primitive values (like `spanLimits`), the user-provided value will be
* used to extend the default value.

@@ -11,6 +11,7 @@ */

sampler: Sampler;
traceParams: {
numberOfAttributesPerSpan: number;
numberOfLinksPerSpan: number;
numberOfEventsPerSpan: number;
forceFlushTimeoutMillis: number;
spanLimits: {
attributeCountLimit: number;
linkCountLimit: number;
eventCountLimit: number;
};

@@ -17,0 +18,0 @@ };

@@ -22,6 +22,7 @@ "use strict";

const env = core_1.getEnv();
const FALLBACK_OTEL_TRACES_SAMPLER = core_1.TracesSamplerValues.AlwaysOn;
/**
* Default configuration. For fields with primitive values, any user-provided
* value will override the corresponding default value. For fields with
* non-primitive values (like `traceParams`), the user-provided value will be
* non-primitive values (like `spanLimits`), the user-provided value will be
* used to extend the default value.

@@ -31,9 +32,9 @@ */

sampler: buildSamplerFromEnv(env),
traceParams: {
numberOfAttributesPerSpan: core_1.getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
numberOfLinksPerSpan: core_1.getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
numberOfEventsPerSpan: core_1.getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
forceFlushTimeoutMillis: 30000,
spanLimits: {
attributeCountLimit: core_1.getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
linkCountLimit: core_1.getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
eventCountLimit: core_1.getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
},
};
const FALLBACK_OTEL_TRACES_SAMPLER = core_1.TracesSamplerValues.AlwaysOn;
/**

@@ -40,0 +41,0 @@ * Based on environment, builds a sampler, complies with specification.

@@ -123,3 +123,3 @@ "use strict";

// prevent downstream exporter calls from generating spans
api_1.context.with(api_1.suppressInstrumentation(api_1.context.active()), () => {
api_1.context.with(core_1.suppressTracing(api_1.context.active()), () => {
// Reset the finished spans buffer here because the next invocations of the _flush method

@@ -126,0 +126,0 @@ // could pass the same finished spans to the exporter if the buffer is cleared

@@ -47,6 +47,6 @@ "use strict";

return {
traceId: span.spanContext.traceId,
traceId: span.spanContext().traceId,
parentId: span.parentSpanId,
name: span.name,
id: span.spanContext.spanId,
id: span.spanContext().spanId,
kind: span.kind,

@@ -53,0 +53,0 @@ timestamp: core_1.hrTimeToMicroseconds(span.startTime),

@@ -1,8 +0,9 @@

import { SpanKind, SpanStatus, SpanAttributes, HrTime, Link, SpanContext, TimedEvent } from '@opentelemetry/api';
import { SpanKind, SpanStatus, SpanAttributes, HrTime, Link, SpanContext } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { TimedEvent } from '../TimedEvent';
export interface ReadableSpan {
readonly name: string;
readonly kind: SpanKind;
readonly spanContext: SpanContext;
readonly spanContext: () => SpanContext;
readonly parentSpanId?: string;

@@ -9,0 +10,0 @@ readonly startTime: HrTime;

import { Span } from '../Span';
import { SpanExporter } from './SpanExporter';
import { SpanProcessor } from '../SpanProcessor';
import { ReadableSpan } from './ReadableSpan';
import { SpanExporter } from './SpanExporter';
/**

@@ -6,0 +6,0 @@ * An implementation of the {@link SpanProcessor} that converts the {@link Span}

@@ -44,3 +44,3 @@ "use strict";

// prevent downstream exporter calls from generating spans
api_1.context.with(api_1.suppressInstrumentation(api_1.context.active()), () => {
api_1.context.with(core_1.suppressTracing(api_1.context.active()), () => {
this._exporter.export([span], result => {

@@ -47,0 +47,0 @@ var _a;

@@ -9,5 +9,7 @@ export * from './Tracer';

export * from './export/SpanExporter';
export * from './export/NoopSpanProcessor';
export * from './Span';
export * from './SpanProcessor';
export * from './TimedEvent';
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -36,5 +36,7 @@ "use strict";

__exportStar(require("./export/SpanExporter"), exports);
__exportStar(require("./export/NoopSpanProcessor"), exports);
__exportStar(require("./Span"), exports);
__exportStar(require("./SpanProcessor"), exports);
__exportStar(require("./TimedEvent"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -5,2 +5,3 @@ import * as api from '@opentelemetry/api';

import { ReadableSpan } from './export/ReadableSpan';
import { TimedEvent } from './TimedEvent';
import { Tracer } from './Tracer';

@@ -12,3 +13,3 @@ import { SpanAttributeValue, Context } from '@opentelemetry/api';

export declare class Span implements api.Span, ReadableSpan {
readonly spanContext: api.SpanContext;
private readonly _spanContext;
readonly kind: api.SpanKind;

@@ -18,3 +19,3 @@ readonly parentSpanId?: string;

readonly links: api.Link[];
readonly events: api.TimedEvent[];
readonly events: TimedEvent[];
readonly startTime: api.HrTime;

@@ -29,6 +30,6 @@ readonly resource: Resource;

private readonly _spanProcessor;
private readonly _traceParams;
private readonly _spanLimits;
/** Constructs a new Span instance. */
constructor(parentTracer: Tracer, context: Context, spanName: string, spanContext: api.SpanContext, kind: api.SpanKind, parentSpanId?: string, links?: api.Link[], startTime?: api.TimeInput);
context(): api.SpanContext;
spanContext(): api.SpanContext;
setAttribute(key: string, value?: SpanAttributeValue): this;

@@ -35,0 +36,0 @@ setAttributes(attributes: api.SpanAttributes): this;

@@ -39,3 +39,3 @@ "use strict";

this.name = spanName;
this.spanContext = spanContext;
this._spanContext = spanContext;
this.parentSpanId = parentSpanId;

@@ -47,8 +47,8 @@ this.kind = kind;

this.instrumentationLibrary = parentTracer.instrumentationLibrary;
this._traceParams = parentTracer.getActiveTraceParams();
this._spanLimits = parentTracer.getSpanLimits();
this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this, context);
}
context() {
return this.spanContext;
spanContext() {
return this._spanContext;
}

@@ -67,3 +67,3 @@ setAttribute(key, value) {

if (Object.keys(this.attributes).length >=
this._traceParams.numberOfAttributesPerSpan &&
this._spanLimits.attributeCountLimit &&
!Object.prototype.hasOwnProperty.call(this.attributes, key)) {

@@ -91,3 +91,3 @@ return this;

return this;
if (this.events.length >= this._traceParams.numberOfEventsPerSpan) {
if (this.events.length >= this._spanLimits.eventCountLimit) {
api.diag.warn('Dropping extra events.');

@@ -176,3 +176,3 @@ this.events.shift();

if (this._ended) {
api.diag.warn('Can not execute the operation on ended Span {traceId: %s, spanId: %s}', this.spanContext.traceId, this.spanContext.spanId);
api.diag.warn('Can not execute the operation on ended Span {traceId: %s, spanId: %s}', this._spanContext.traceId, this._spanContext.spanId);
}

@@ -179,0 +179,0 @@ return this._ended;

@@ -5,3 +5,3 @@ import * as api from '@opentelemetry/api';

import { BasicTracerProvider } from './BasicTracerProvider';
import { TraceParams, TracerConfig } from './types';
import { SpanLimits, TracerConfig } from './types';
/**

@@ -13,3 +13,3 @@ * This class represents a basic tracer.

private readonly _sampler;
private readonly _traceParams;
private readonly _spanLimits;
private readonly _idGenerator;

@@ -22,2 +22,3 @@ readonly resource: Resource;

constructor(instrumentationLibrary: InstrumentationLibrary, config: TracerConfig, _tracerProvider: BasicTracerProvider);
startActiveSpan<F extends (span: api.Span) => ReturnType<F>>(name: string, arg2: F | api.SpanOptions, arg3?: F | api.Context, arg4?: F): ReturnType<F> | undefined;
/**

@@ -28,6 +29,6 @@ * Starts a new Span or returns the default NoopSpan based on the sampling

startSpan(name: string, options?: api.SpanOptions, context?: api.Context): api.Span;
/** Returns the active {@link TraceParams}. */
getActiveTraceParams(): TraceParams;
/** Returns the active {@link SpanLimits}. */
getSpanLimits(): SpanLimits;
getActiveSpanProcessor(): import("./SpanProcessor").SpanProcessor;
}
//# sourceMappingURL=Tracer.d.ts.map

@@ -34,3 +34,3 @@ "use strict";

this._sampler = localConfig.sampler;
this._traceParams = localConfig.traceParams;
this._spanLimits = localConfig.spanLimits;
this._idGenerator = config.idGenerator || new core_1.RandomIdGenerator();

@@ -40,2 +40,29 @@ this.resource = _tracerProvider.resource;

}
startActiveSpan(name, arg2, arg3, arg4) {
let fn, options, activeContext;
if (arguments.length === 2 && typeof arg2 === 'function') {
fn = arg2;
}
else if (arguments.length === 3 &&
typeof arg2 === 'object' &&
typeof arg3 === 'function') {
options = arg2;
fn = arg3;
}
else if (arguments.length === 4 &&
typeof arg2 === 'object' &&
typeof arg3 === 'object' &&
typeof arg4 === 'function') {
options = arg2;
activeContext = arg3;
fn = arg4;
}
const parentContext = activeContext !== null && activeContext !== void 0 ? activeContext : api.context.active();
const span = this.startSpan(name, options, parentContext);
const contextWithSpanSet = api.trace.setSpan(parentContext, span);
if (fn) {
return api.context.with(contextWithSpanSet, fn, undefined, span);
}
return;
}
/**

@@ -47,5 +74,5 @@ * Starts a new Span or returns the default NoopSpan based on the sampling

var _a, _b;
if (api.isInstrumentationSuppressed(context)) {
if (core_1.isTracingSuppressed(context)) {
api.diag.debug('Instrumentation suppressed, returning Noop Span');
return api.NOOP_TRACER.startSpan(name, options, context);
return api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
}

@@ -71,3 +98,5 @@ const parentContext = getParent(options, context);

// make sampling decision
const samplingResult = this._sampler.shouldSample(context, traceId, name, spanKind, attributes, links);
const samplingResult = this._sampler.shouldSample(options.root
? api.trace.setSpanContext(context, api.INVALID_SPAN_CONTEXT)
: context, traceId, name, spanKind, attributes, links);
const traceFlags = samplingResult.decision === api.SamplingDecision.RECORD_AND_SAMPLED

@@ -78,4 +107,4 @@ ? api.TraceFlags.SAMPLED

if (samplingResult.decision === api.SamplingDecision.NOT_RECORD) {
api.diag.debug('Recording is off, starting no recording span');
return api.NOOP_TRACER.startSpan(name, options, api.setSpanContext(context, spanContext));
api.diag.debug('Recording is off, propagating context in a non-recording span');
return api.trace.wrapSpanContext(spanContext);
}

@@ -87,5 +116,5 @@ const span = new Span_1.Span(this, context, name, spanContext, spanKind, parentSpanId, links, options.startTime);

}
/** Returns the active {@link TraceParams}. */
getActiveTraceParams() {
return this._traceParams;
/** Returns the active {@link SpanLimits}. */
getSpanLimits() {
return this._spanLimits;
}

@@ -107,4 +136,4 @@ getActiveSpanProcessor() {

return undefined;
return api.getSpanContext(context);
return api.trace.getSpanContext(context);
}
//# sourceMappingURL=Tracer.js.map

@@ -13,4 +13,4 @@ import { TextMapPropagator, Sampler } from '@opentelemetry/api';

sampler?: Sampler;
/** Trace Parameters */
traceParams?: TraceParams;
/** Span Limits */
spanLimits?: SpanLimits;
/** Resource associated with trace telemetry */

@@ -23,2 +23,7 @@ resource?: Resource;

idGenerator?: IdGenerator;
/**
* How long the forceFlush can run before it is cancelled.
* The default value is 30000ms
*/
forceFlushTimeoutMillis?: number;
}

@@ -37,9 +42,9 @@ /**

/** Global configuration of trace service */
export interface TraceParams {
/** numberOfAttributesPerSpan is number of attributes per span */
numberOfAttributesPerSpan?: number;
/** numberOfLinksPerSpan is number of links per span */
numberOfLinksPerSpan?: number;
/** numberOfEventsPerSpan is number of message events per span */
numberOfEventsPerSpan?: number;
export interface SpanLimits {
/** attributeCountLimit is number of attributes per span */
attributeCountLimit?: number;
/** linkCountLimit is number of links per span */
linkCountLimit?: number;
/** eventCountLimit is number of message events per span */
eventCountLimit?: number;
}

@@ -46,0 +51,0 @@ /** Interface configuration for a buffer. */

@@ -8,8 +8,9 @@ import { TracerConfig } from './types';

sampler: import("@opentelemetry/api").Sampler;
traceParams: {
numberOfAttributesPerSpan: number;
numberOfLinksPerSpan: number;
numberOfEventsPerSpan: number;
forceFlushTimeoutMillis: number;
spanLimits: {
attributeCountLimit: number;
linkCountLimit: number;
eventCountLimit: number;
};
} & Partial<TracerConfig> & TracerConfig;
//# sourceMappingURL=utility.d.ts.map

@@ -29,3 +29,3 @@ "use strict";

const target = Object.assign({}, config_1.DEFAULT_CONFIG, perInstanceDefaults, userConfig);
target.traceParams = Object.assign({}, config_1.DEFAULT_CONFIG.traceParams, userConfig.traceParams || {});
target.spanLimits = Object.assign({}, config_1.DEFAULT_CONFIG.spanLimits, userConfig.spanLimits || {});
return target;

@@ -32,0 +32,0 @@ }

{
"name": "@opentelemetry/tracing",
"version": "0.19.1-alpha.39+23ba4bfd",
"version": "0.19.1-alpha.41+7fa4ff70",
"description": "OpenTelemetry Tracing",

@@ -56,10 +56,9 @@ "main": "build/src/index.js",

"devDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/api": "^0.20.0",
"@types/lodash.merge": "4.6.6",
"@types/mocha": "8.2.2",
"@types/node": "14.14.41",
"@types/node": "14.14.43",
"@types/sinon": "9.0.11",
"@types/webpack-env": "1.16.0",
"codecov": "3.8.1",
"gts": "3.1.0",
"istanbul-instrumenter-loader": "3.0.1",

@@ -71,3 +70,3 @@ "karma": "5.2.3",

"karma-spec-reporter": "0.0.32",
"karma-webpack": "5.0.0",
"karma-webpack": "4.0.2",
"mocha": "7.2.0",

@@ -77,3 +76,3 @@ "nyc": "15.1.0",

"sinon": "10.0.0",
"ts-loader": "8.1.0",
"ts-loader": "8.2.0",
"ts-mocha": "8.0.0",

@@ -85,11 +84,11 @@ "ts-node": "9.1.1",

"peerDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0"
"@opentelemetry/api": "^0.20.0"
},
"dependencies": {
"@opentelemetry/core": "^0.19.1-alpha.39+23ba4bfd",
"@opentelemetry/resources": "^0.19.1-alpha.39+23ba4bfd",
"@opentelemetry/semantic-conventions": "^0.19.1-alpha.39+23ba4bfd",
"@opentelemetry/core": "^0.19.0",
"@opentelemetry/resources": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0",
"lodash.merge": "^4.6.2"
},
"gitHead": "23ba4bfdc77c8bf594bf0c817320a31f59ca0bd4"
"gitHead": "7fa4ff70d1aad5875cb14c6bff99c838228447bb"
}

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

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

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

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

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

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

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