diff --git a/hack/bundle-opentelemetry.ts b/hack/bundle-opentelemetry.ts
index 0e453dc..ddb7773 100755
--- a/hack/bundle-opentelemetry.ts
+++ b/hack/bundle-opentelemetry.ts
@@ -1,4 +1,4 @@
-#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write=. --allow-env --allow-sys --allow-ffi
+#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write=. --allow-env
// pass --refresh-yarn to force rerunning yarn on the opentelemetry packages
diff --git a/hack/opentelemetry-js b/hack/opentelemetry-js
index f8e187b..48fb158 160000
--- a/hack/opentelemetry-js
+++ b/hack/opentelemetry-js
@@ -1 +1 @@
-Subproject commit f8e187b473274cc2011e7385992f07d319d667dc
+Subproject commit 48fb15862e801b742059a3e39dbcc8ef4c10b2e2
diff --git a/opentelemetry/api.js b/opentelemetry/api.js
index 5b36666..5ec2c9d 100644
--- a/opentelemetry/api.js
+++ b/opentelemetry/api.js
@@ -17,7 +17,7 @@
const _globalThis = typeof globalThis === 'object' ? globalThis : global;
-const VERSION = "1.6.0";
+const VERSION = "1.4.1";
const re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
function _makeCompatibilityCheck(ownVersion) {
diff --git a/opentelemetry/core.d.ts b/opentelemetry/core.d.ts
index bab5908..2841512 100644
--- a/opentelemetry/core.d.ts
+++ b/opentelemetry/core.d.ts
@@ -201,7 +201,7 @@ declare enum ExportResultCode {
FAILED = 1
}
-declare const VERSION = "1.17.1";
+declare const VERSION = "1.15.2";
declare type ParsedBaggageKeyValue = {
key: string;
diff --git a/opentelemetry/core.js b/opentelemetry/core.js
index b8d18aa..d43decf 100644
--- a/opentelemetry/core.js
+++ b/opentelemetry/core.js
@@ -523,7 +523,7 @@ function getIdGenerator(bytes) {
const otperformance = performance;
-const VERSION$1 = "1.17.1";
+const VERSION$1 = "1.15.2";
const SDK_INFO = {
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
diff --git a/opentelemetry/otlp-transformer.d.ts b/opentelemetry/otlp-transformer.d.ts
index dbcea63..8b410fb 100644
--- a/opentelemetry/otlp-transformer.d.ts
+++ b/opentelemetry/otlp-transformer.d.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { HrTime } from './api.d.ts';
import { ReadableSpan } from './sdk-trace-base.d.ts';
import { ResourceMetrics } from './sdk-metrics.d.ts';
import { ReadableLogRecord } from './sdk-logs.d.ts';
@@ -64,22 +63,6 @@ interface IKeyValueList {
/** KeyValueList values */
values: IKeyValue[];
}
-interface IFixed64 {
- low: number;
- high: number;
-}
-
-declare class UnsignedLong {
- low: number;
- high: number;
- constructor(low: number, high: number);
- static fromU32(value: number): UnsignedLong;
- multiply(value: UnsignedLong): UnsignedLong;
- add(value: UnsignedLong): UnsignedLong;
- static fromString(str: string): UnsignedLong;
-}
-
-declare function hrTimeToFixed64Nanos(hrTime: HrTime): IFixed64;
/** Properties of a Resource. */
interface IResource {
@@ -179,9 +162,9 @@ interface INumberDataPoint {
/** NumberDataPoint attributes */
attributes: IKeyValue[];
/** NumberDataPoint startTimeUnixNano */
- startTimeUnixNano?: IFixed64 | string;
+ startTimeUnixNano?: number;
/** NumberDataPoint timeUnixNano */
- timeUnixNano?: IFixed64 | string;
+ timeUnixNano?: number;
/** NumberDataPoint asDouble */
asDouble?: number | null;
/** NumberDataPoint asInt */
@@ -196,9 +179,9 @@ interface IHistogramDataPoint {
/** HistogramDataPoint attributes */
attributes?: IKeyValue[];
/** HistogramDataPoint startTimeUnixNano */
- startTimeUnixNano?: IFixed64 | string;
+ startTimeUnixNano?: number;
/** HistogramDataPoint timeUnixNano */
- timeUnixNano?: IFixed64 | string;
+ timeUnixNano?: number;
/** HistogramDataPoint count */
count?: number;
/** HistogramDataPoint sum */
@@ -221,9 +204,9 @@ interface IExponentialHistogramDataPoint {
/** ExponentialHistogramDataPoint attributes */
attributes?: IKeyValue[];
/** ExponentialHistogramDataPoint startTimeUnixNano */
- startTimeUnixNano?: IFixed64 | string;
+ startTimeUnixNano?: number;
/** ExponentialHistogramDataPoint timeUnixNano */
- timeUnixNano?: IFixed64 | string;
+ timeUnixNano?: number;
/** ExponentialHistogramDataPoint count */
count?: number;
/** ExponentialHistogramDataPoint sum */
@@ -409,9 +392,9 @@ interface ISpan {
/** Span kind */
kind: ESpanKind;
/** Span startTimeUnixNano */
- startTimeUnixNano: IFixed64;
+ startTimeUnixNano: number;
/** Span endTimeUnixNano */
- endTimeUnixNano: IFixed64;
+ endTimeUnixNano: number;
/** Span attributes */
attributes: IKeyValue[];
/** Span droppedAttributesCount */
@@ -476,7 +459,7 @@ declare enum EStatusCode {
/** Properties of an Event. */
interface IEvent {
/** Event timeUnixNano */
- timeUnixNano: IFixed64;
+ timeUnixNano: number;
/** Event name */
name: string;
/** Event attributes */
@@ -534,9 +517,9 @@ interface IScopeLogs {
/** Properties of a LogRecord. */
interface ILogRecord {
/** LogRecord timeUnixNano */
- timeUnixNano: IFixed64;
+ timeUnixNano: number;
/** LogRecord observedTimeUnixNano */
- observedTimeUnixNano: IFixed64;
+ observedTimeUnixNano: number;
/** LogRecord severityNumber */
severityNumber?: ESeverityNumber;
/** LogRecord severityText */
@@ -592,4 +575,4 @@ declare function createExportMetricsServiceRequest(resourceMetrics: ResourceMetr
declare function createExportLogsServiceRequest(logRecords: ReadableLogRecord[], useHex?: boolean): IExportLogsServiceRequest;
-export { EAggregationTemporality, ESeverityNumber, ESpanKind, EStatusCode, IAnyValue, IArrayValue, IBuckets, IEvent, IExemplar, IExponentialHistogram, IExponentialHistogramDataPoint, IExportLogsPartialSuccess, IExportLogsServiceRequest, IExportLogsServiceResponse, IExportMetricsPartialSuccess, IExportMetricsServiceRequest, IExportMetricsServiceResponse, IExportTracePartialSuccess, IExportTraceServiceRequest, IExportTraceServiceResponse, IFixed64, IGauge, IHistogram, IHistogramDataPoint, IInstrumentationScope, IKeyValue, IKeyValueList, ILink, ILogRecord, IMetric, INumberDataPoint, IResource, IResourceLogs, IResourceMetrics, IResourceSpans, IScopeLogs, IScopeMetrics, IScopeSpans, ISpan, IStatus, ISum, ISummary, ISummaryDataPoint, IValueAtQuantile, UnsignedLong, createExportLogsServiceRequest, createExportMetricsServiceRequest, createExportTraceServiceRequest, hrTimeToFixed64Nanos };
+export { EAggregationTemporality, ESeverityNumber, ESpanKind, EStatusCode, IAnyValue, IArrayValue, IBuckets, IEvent, IExemplar, IExponentialHistogram, IExponentialHistogramDataPoint, IExportLogsPartialSuccess, IExportLogsServiceRequest, IExportLogsServiceResponse, IExportMetricsPartialSuccess, IExportMetricsServiceRequest, IExportMetricsServiceResponse, IExportTracePartialSuccess, IExportTraceServiceRequest, IExportTraceServiceResponse, IGauge, IHistogram, IHistogramDataPoint, IInstrumentationScope, IKeyValue, IKeyValueList, ILink, ILogRecord, IMetric, INumberDataPoint, IResource, IResourceLogs, IResourceMetrics, IResourceSpans, IScopeLogs, IScopeMetrics, IScopeSpans, ISpan, IStatus, ISum, ISummary, ISummaryDataPoint, IValueAtQuantile, createExportLogsServiceRequest, createExportMetricsServiceRequest, createExportTraceServiceRequest };
diff --git a/opentelemetry/otlp-transformer.js b/opentelemetry/otlp-transformer.js
index b610c5a..092b785 100644
--- a/opentelemetry/otlp-transformer.js
+++ b/opentelemetry/otlp-transformer.js
@@ -16,105 +16,10 @@
///
import * as core from './core.js';
-import { hexToBase64 } from './core.js';
+import { hrTimeToNanoseconds, hexToBase64 } from './core.js';
import { ValueType } from './api.js';
import { DataPointType, AggregationTemporality } from './sdk-metrics.js';
-const TWO_PWR_32 = (1 << 16) * (1 << 16);
-class UnsignedLong {
- constructor(low, high) {
- this.low = low;
- this.high = high;
- }
- static fromU32(value) {
- return new UnsignedLong(value % TWO_PWR_32 | 0, 0);
- }
- multiply(value) {
- const a48 = this.high >>> 16;
- const a32 = this.high & 0xffff;
- const a16 = this.low >>> 16;
- const a00 = this.low & 0xffff;
- const b48 = value.high >>> 16;
- const b32 = value.high & 0xffff;
- const b16 = value.low >>> 16;
- const b00 = value.low & 0xffff;
- let c48 = 0;
- let c32 = 0;
- let c16 = 0;
- let c00 = 0;
- c00 += a00 * b00;
- c16 += c00 >>> 16;
- c00 &= 0xffff;
- c16 += a16 * b00;
- c32 += c16 >>> 16;
- c16 &= 0xffff;
- c16 += a00 * b16;
- c32 += c16 >>> 16;
- c16 &= 0xffff;
- c32 += a32 * b00;
- c48 += c32 >>> 16;
- c32 &= 0xffff;
- c32 += a16 * b16;
- c48 += c32 >>> 16;
- c32 &= 0xffff;
- c32 += a00 * b32;
- c48 += c32 >>> 16;
- c32 &= 0xffff;
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
- c48 &= 0xffff;
- return new UnsignedLong((c16 << 16) | c00, (c48 << 16) | c32);
- }
- add(value) {
- const a48 = this.high >>> 16;
- const a32 = this.high & 0xffff;
- const a16 = this.low >>> 16;
- const a00 = this.low & 0xffff;
- const b48 = value.high >>> 16;
- const b32 = value.high & 0xffff;
- const b16 = value.low >>> 16;
- const b00 = value.low & 0xffff;
- let c48 = 0;
- let c32 = 0;
- let c16 = 0;
- let c00 = 0;
- c00 += a00 + b00;
- c16 += c00 >>> 16;
- c00 &= 0xffff;
- c16 += a16 + b16;
- c32 += c16 >>> 16;
- c16 &= 0xffff;
- c32 += a32 + b32;
- c48 += c32 >>> 16;
- c32 &= 0xffff;
- c48 += a48 + b48;
- c48 &= 0xffff;
- return new UnsignedLong((c16 << 16) | c00, (c48 << 16) | c32);
- }
- static fromString(str) {
- let result = UnsignedLong.fromU32(0);
- for (let i = 0; i < str.length; i += 8) {
- const size = Math.min(8, str.length - i);
- const value = parseInt(str.substring(i, i + size));
- if (size < 8) {
- const power = UnsignedLong.fromU32(Math.pow(10, size));
- result = result.multiply(power).add(UnsignedLong.fromU32(value));
- }
- else {
- result = result.multiply(UnsignedLong.fromU32(100000000));
- result = result.add(UnsignedLong.fromU32(value));
- }
- }
- return result;
- }
-}
-
-const NANOSECONDS = UnsignedLong.fromU32(1000000000);
-function hrTimeToFixed64Nanos(hrTime) {
- return UnsignedLong.fromU32(hrTime[0])
- .multiply(NANOSECONDS)
- .add(UnsignedLong.fromU32(hrTime[1]));
-}
-
var ESpanKind;
(function (ESpanKind) {
ESpanKind[ESpanKind["SPAN_KIND_UNSPECIFIED"] = 0] = "SPAN_KIND_UNSPECIFIED";
@@ -173,8 +78,8 @@ function sdkSpanToOtlpSpan(span, useHex) {
traceState: ctx.traceState?.serialize(),
name: span.name,
kind: span.kind == null ? 0 : span.kind + 1,
- startTimeUnixNano: hrTimeToFixed64Nanos(span.startTime),
- endTimeUnixNano: hrTimeToFixed64Nanos(span.endTime),
+ startTimeUnixNano: hrTimeToNanoseconds(span.startTime),
+ endTimeUnixNano: hrTimeToNanoseconds(span.endTime),
attributes: toAttributes(span.attributes),
droppedAttributesCount: span.droppedAttributesCount,
events: span.events.map(toOtlpSpanEvent),
@@ -206,7 +111,7 @@ function toOtlpSpanEvent(timedEvent) {
? toAttributes(timedEvent.attributes)
: [],
name: timedEvent.name,
- timeUnixNano: hrTimeToFixed64Nanos(timedEvent.time),
+ timeUnixNano: hrTimeToNanoseconds(timedEvent.time),
droppedAttributesCount: timedEvent.droppedAttributesCount || 0,
};
}
@@ -329,8 +234,8 @@ function toMetric(metricData) {
function toSingularDataPoint(dataPoint, valueType) {
const out = {
attributes: toAttributes(dataPoint.attributes),
- startTimeUnixNano: hrTimeToFixed64Nanos(dataPoint.startTime),
- timeUnixNano: hrTimeToFixed64Nanos(dataPoint.endTime),
+ startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime),
+ timeUnixNano: hrTimeToNanoseconds(dataPoint.endTime),
};
switch (valueType) {
case ValueType.INT:
@@ -358,8 +263,8 @@ function toHistogramDataPoints(metricData) {
sum: histogram.sum,
min: histogram.min,
max: histogram.max,
- startTimeUnixNano: hrTimeToFixed64Nanos(dataPoint.startTime),
- timeUnixNano: hrTimeToFixed64Nanos(dataPoint.endTime),
+ startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime),
+ timeUnixNano: hrTimeToNanoseconds(dataPoint.endTime),
};
});
}
@@ -382,8 +287,8 @@ function toExponentialHistogramDataPoints(metricData) {
},
scale: histogram.scale,
zeroCount: histogram.zeroCount,
- startTimeUnixNano: hrTimeToFixed64Nanos(dataPoint.startTime),
- timeUnixNano: hrTimeToFixed64Nanos(dataPoint.endTime),
+ startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime),
+ timeUnixNano: hrTimeToNanoseconds(dataPoint.endTime),
};
});
}
@@ -446,8 +351,8 @@ function logRecordsToResourceLogs(logRecords, useHex) {
}
function toLogRecord(log, useHex) {
return {
- timeUnixNano: hrTimeToFixed64Nanos(log.hrTime),
- observedTimeUnixNano: hrTimeToFixed64Nanos(log.hrTimeObserved),
+ timeUnixNano: hrTimeToNanoseconds(log.hrTime),
+ observedTimeUnixNano: hrTimeToNanoseconds(log.hrTimeObserved),
severityNumber: toSeverityNumber(log.severityNumber),
severityText: log.severityText,
body: toAnyValue(log.body),
@@ -474,4 +379,4 @@ function toLogAttributes(attributes) {
return Object.keys(attributes).map(key => toKeyValue(key, attributes[key]));
}
-export { ESpanKind, UnsignedLong, createExportLogsServiceRequest, createExportMetricsServiceRequest, createExportTraceServiceRequest, hrTimeToFixed64Nanos };
+export { ESpanKind, createExportLogsServiceRequest, createExportMetricsServiceRequest, createExportTraceServiceRequest };
diff --git a/opentelemetry/sdk-logs.d.ts b/opentelemetry/sdk-logs.d.ts
index 10acadf..762bceb 100644
--- a/opentelemetry/sdk-logs.d.ts
+++ b/opentelemetry/sdk-logs.d.ts
@@ -16,7 +16,7 @@
import { IResource } from './resources.d.ts';
import * as logsAPI from './api-logs.d.ts';
-import { SeverityNumber, LogAttributes, Logger } from './api-logs.d.ts';
+import { SeverityNumber, LogAttributes } from './api-logs.d.ts';
import * as api from './api.d.ts';
import { HrTime, SpanContext, AttributeValue, Context } from './api.d.ts';
import { InstrumentationScope, ExportResult } from './core.d.ts';
@@ -32,6 +32,10 @@ interface LoggerProviderConfig {
/** Log Record Limits*/
logRecordLimits?: LogRecordLimits;
}
+interface LoggerConfig {
+ /** Log Record Limits*/
+ logRecordLimits?: LogRecordLimits;
+}
interface LogRecordLimits {
/** attributeValueLengthLimit is maximum allowed attribute value size */
attributeValueLengthLimit?: number;
@@ -71,14 +75,15 @@ interface ReadableLogRecord {
readonly attributes: LogAttributes;
}
-declare class LoggerProviderSharedState {
+declare class Logger implements logsAPI.Logger {
+ readonly instrumentationScope: InstrumentationScope;
+ private _loggerProvider;
readonly resource: IResource;
- readonly forceFlushTimeoutMillis: number;
- readonly logRecordLimits: Required;
- readonly loggers: Map;
- activeProcessor: LogRecordProcessor;
- readonly registeredLogRecordProcessors: LogRecordProcessor[];
- constructor(resource: IResource, forceFlushTimeoutMillis: number, logRecordLimits: Required);
+ private readonly _loggerConfig;
+ constructor(instrumentationScope: InstrumentationScope, config: LoggerConfig, _loggerProvider: LoggerProvider);
+ emit(logRecord: logsAPI.LogRecord): void;
+ getLogRecordLimits(): LogRecordLimits;
+ getActiveLogRecordProcessor(): LogRecordProcessor;
}
declare class LogRecord implements ReadableLogRecord {
@@ -99,18 +104,17 @@ declare class LogRecord implements ReadableLogRecord {
get severityNumber(): logsAPI.SeverityNumber | undefined;
set body(body: string | undefined);
get body(): string | undefined;
- constructor(_sharedState: LoggerProviderSharedState, instrumentationScope: InstrumentationScope, logRecord: logsAPI.LogRecord);
+ constructor(logger: Logger, logRecord: logsAPI.LogRecord);
setAttribute(key: string, value?: LogAttributes | AttributeValue): this;
setAttributes(attributes: LogAttributes): this;
setBody(body: string): this;
setSeverityNumber(severityNumber: logsAPI.SeverityNumber): this;
setSeverityText(severityText: string): this;
/**
- * @internal
* A LogRecordProcessor may freely modify logRecord for the duration of the OnEmit call.
* If logRecord is needed after OnEmit returns (i.e. for asynchronous processing) only reads are permitted.
*/
- _makeReadonly(): void;
+ makeReadonly(): void;
private _truncateToSize;
private _truncateToLimitUtil;
private _isLogRecordReadonly;
@@ -134,9 +138,26 @@ interface LogRecordProcessor {
shutdown(): Promise;
}
+/**
+ * Implementation of the {@link LogRecordProcessor} that simply forwards all
+ * received events to a list of {@link LogRecordProcessor}s.
+ */
+declare class MultiLogRecordProcessor implements LogRecordProcessor {
+ readonly processors: LogRecordProcessor[];
+ readonly forceFlushTimeoutMillis: number;
+ constructor(processors: LogRecordProcessor[], forceFlushTimeoutMillis: number);
+ forceFlush(): Promise;
+ onEmit(logRecord: LogRecord): void;
+ shutdown(): Promise;
+}
+
declare class LoggerProvider implements logsAPI.LoggerProvider {
+ readonly resource: IResource;
+ private readonly _loggers;
+ private _activeProcessor;
+ private readonly _registeredLogRecordProcessors;
+ private readonly _config;
private _shutdownOnce;
- private readonly _sharedState;
constructor(config?: LoggerProviderConfig);
/**
* Get a logger with the configuration of the LoggerProvider.
@@ -160,12 +181,14 @@ declare class LoggerProvider implements logsAPI.LoggerProvider {
* Returns a promise which is resolved when all flushes are complete.
*/
shutdown(): Promise;
+ getActiveLogRecordProcessor(): MultiLogRecordProcessor;
+ getActiveLoggers(): Map;
private _shutdown;
}
declare class NoopLogRecordProcessor implements LogRecordProcessor {
forceFlush(): Promise;
- onEmit(_logRecord: ReadableLogRecord, _context: Context): void;
+ onEmit(_logRecord: ReadableLogRecord): void;
shutdown(): Promise;
}
@@ -268,4 +291,4 @@ declare class BatchLogRecordProcessor extends BatchLogRecordProcessorBase callWithTimeout(processor.forceFlush(), timeout)));
}
- onEmit(logRecord, context) {
- this.processors.forEach(processors => processors.onEmit(logRecord, context));
+ onEmit(logRecord) {
+ this.processors.forEach(processors => processors.onEmit(logRecord));
}
async shutdown() {
await Promise.all(this.processors.map(processor => processor.shutdown()));
@@ -208,29 +224,26 @@ class NoopLogRecordProcessor {
forceFlush() {
return Promise.resolve();
}
- onEmit(_logRecord, _context) { }
+ onEmit(_logRecord) { }
shutdown() {
return Promise.resolve();
}
}
-class LoggerProviderSharedState {
- constructor(resource, forceFlushTimeoutMillis, logRecordLimits) {
- this.resource = resource;
- this.forceFlushTimeoutMillis = forceFlushTimeoutMillis;
- this.logRecordLimits = logRecordLimits;
- this.loggers = new Map();
- this.registeredLogRecordProcessors = [];
- this.activeProcessor = new NoopLogRecordProcessor();
- }
-}
-
const DEFAULT_LOGGER_NAME = 'unknown';
class LoggerProvider {
constructor(config = {}) {
- const { resource = Resource.default(), logRecordLimits, forceFlushTimeoutMillis, } = merge({}, loadDefaultConfig(), config);
- this._sharedState = new LoggerProviderSharedState(resource, forceFlushTimeoutMillis, reconfigureLimits(logRecordLimits));
+ this._loggers = new Map();
+ this._registeredLogRecordProcessors = [];
+ const { resource = Resource.empty(), logRecordLimits, forceFlushTimeoutMillis, } = merge({}, loadDefaultConfig(), reconfigureLimits(config));
+ this.resource = Resource.default().merge(resource);
+ this._config = {
+ logRecordLimits,
+ resource: this.resource,
+ forceFlushTimeoutMillis,
+ };
this._shutdownOnce = new BindOnceFuture(this._shutdown, this);
+ this._activeProcessor = new MultiLogRecordProcessor([new NoopLogRecordProcessor()], forceFlushTimeoutMillis);
}
getLogger(name, version, options) {
if (this._shutdownOnce.isCalled) {
@@ -242,26 +255,28 @@ class LoggerProvider {
}
const loggerName = name || DEFAULT_LOGGER_NAME;
const key = `${loggerName}@${version || ''}:${options?.schemaUrl || ''}`;
- if (!this._sharedState.loggers.has(key)) {
- this._sharedState.loggers.set(key, new Logger({ name: loggerName, version, schemaUrl: options?.schemaUrl }, this._sharedState));
+ if (!this._loggers.has(key)) {
+ this._loggers.set(key, new Logger({ name: loggerName, version, schemaUrl: options?.schemaUrl }, {
+ logRecordLimits: this._config.logRecordLimits,
+ }, this));
}
- return this._sharedState.loggers.get(key);
+ return this._loggers.get(key);
}
addLogRecordProcessor(processor) {
- if (this._sharedState.registeredLogRecordProcessors.length === 0) {
- this._sharedState.activeProcessor
+ if (this._registeredLogRecordProcessors.length === 0) {
+ this._activeProcessor
.shutdown()
.catch(err => diag.error('Error while trying to shutdown current log record processor', err));
}
- this._sharedState.registeredLogRecordProcessors.push(processor);
- this._sharedState.activeProcessor = new MultiLogRecordProcessor(this._sharedState.registeredLogRecordProcessors, this._sharedState.forceFlushTimeoutMillis);
+ this._registeredLogRecordProcessors.push(processor);
+ this._activeProcessor = new MultiLogRecordProcessor(this._registeredLogRecordProcessors, this._config.forceFlushTimeoutMillis);
}
forceFlush() {
if (this._shutdownOnce.isCalled) {
diag.warn('invalid attempt to force flush after LoggerProvider shutdown');
return this._shutdownOnce.promise;
}
- return this._sharedState.activeProcessor.forceFlush();
+ return this._activeProcessor.forceFlush();
}
shutdown() {
if (this._shutdownOnce.isCalled) {
@@ -270,8 +285,14 @@ class LoggerProvider {
}
return this._shutdownOnce.call();
}
+ getActiveLogRecordProcessor() {
+ return this._activeProcessor;
+ }
+ getActiveLoggers() {
+ return this._loggers;
+ }
_shutdown() {
- return this._sharedState.activeProcessor.shutdown();
+ return this._activeProcessor.shutdown();
}
}
@@ -470,4 +491,4 @@ class BatchLogRecordProcessor extends BatchLogRecordProcessorBase {
onShutdown() { }
}
-export { BatchLogRecordProcessor, ConsoleLogRecordExporter, InMemoryLogRecordExporter, LogRecord, LoggerProvider, NoopLogRecordProcessor, SimpleLogRecordProcessor };
+export { BatchLogRecordProcessor, ConsoleLogRecordExporter, InMemoryLogRecordExporter, LogRecord, Logger, LoggerProvider, NoopLogRecordProcessor, SimpleLogRecordProcessor };
diff --git a/opentelemetry/sdk-metrics.d.ts b/opentelemetry/sdk-metrics.d.ts
index fea90fa..768cea0 100644
--- a/opentelemetry/sdk-metrics.d.ts
+++ b/opentelemetry/sdk-metrics.d.ts
@@ -1082,13 +1082,6 @@ interface MetricReaderOptions {
* not configured, cumulative is used for all instruments.
*/
aggregationTemporalitySelector?: AggregationTemporalitySelector;
- /**
- * **Note, this option is experimental**. Additional MetricProducers to use as a source of
- * aggregated metric data in addition to the SDK's metric data. The resource returned by
- * these MetricProducers is ignored; the SDK's resource will be used instead.
- * @experimental
- */
- metricProducers?: MetricProducer[];
}
/**
* A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global
@@ -1096,19 +1089,13 @@ interface MetricReaderOptions {
*/
declare abstract class MetricReader {
private _shutdown;
- private _metricProducers;
- private _sdkMetricProducer?;
+ private _metricProducer?;
private readonly _aggregationTemporalitySelector;
private readonly _aggregationSelector;
constructor(options?: MetricReaderOptions);
/**
- * Set the {@link MetricProducer} used by this instance. **This should only be called by the
- * SDK and should be considered internal.**
- *
- * To add additional {@link MetricProducer}s to a {@link MetricReader}, pass them to the
- * constructor as {@link MetricReaderOptions.metricProducers}.
+ * Set the {@link MetricProducer} used by this instance.
*
- * @internal
* @param metricProducer
*/
setMetricProducer(metricProducer: MetricProducer): void;
@@ -1176,13 +1163,6 @@ declare type PeriodicExportingMetricReaderOptions = {
* Milliseconds for the async observable callback to timeout.
*/
exportTimeoutMillis?: number;
- /**
- * **Note, this option is experimental**. Additional MetricProducers to use as a source of
- * aggregated metric data in addition to the SDK's metric data. The resource returned by
- * these MetricProducers is ignored; the SDK's resource will be used instead.
- * @experimental
- */
- metricProducers?: MetricProducer[];
};
/**
* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
@@ -1281,4 +1261,4 @@ declare class MeterProvider implements MeterProvider$1 {
forceFlush(options?: ForceFlushOptions): Promise;
}
-export { Aggregation, AggregationSelector, AggregationTemporality, AggregationTemporalitySelector, CollectionResult, ConsoleMetricExporter, DataPoint, DataPointType, DefaultAggregation, DropAggregation, ExplicitBucketHistogramAggregation, ExponentialHistogram, ExponentialHistogramAggregation, ExponentialHistogramMetricData, GaugeMetricData, Histogram, HistogramAggregation, HistogramMetricData, InMemoryMetricExporter, InstrumentDescriptor, InstrumentType, LastValue, LastValueAggregation, MeterProvider, MeterProviderOptions, MetricCollectOptions, MetricData, MetricProducer, MetricReader, MetricReaderOptions, PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, PushMetricExporter, ResourceMetrics, ScopeMetrics, Sum, SumAggregation, SumMetricData, TimeoutError, View, ViewOptions };
+export { Aggregation, AggregationSelector, AggregationTemporality, AggregationTemporalitySelector, CollectionResult, ConsoleMetricExporter, DataPoint, DataPointType, DefaultAggregation, DropAggregation, ExplicitBucketHistogramAggregation, ExponentialHistogram, ExponentialHistogramAggregation, ExponentialHistogramMetricData, GaugeMetricData, Histogram, HistogramAggregation, HistogramMetricData, InMemoryMetricExporter, InstrumentDescriptor, InstrumentType, LastValue, LastValueAggregation, MeterProvider, MeterProviderOptions, MetricData, MetricReader, MetricReaderOptions, PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, PushMetricExporter, ResourceMetrics, ScopeMetrics, Sum, SumAggregation, SumMetricData, TimeoutError, View, ViewOptions };
diff --git a/opentelemetry/sdk-metrics.js b/opentelemetry/sdk-metrics.js
index cd6f0b0..cea7e15 100644
--- a/opentelemetry/sdk-metrics.js
+++ b/opentelemetry/sdk-metrics.js
@@ -16,7 +16,7 @@
///
import * as api from './api.js';
-import { diag, ValueType, context, createNoopMeter } from './api.js';
+import { ValueType, diag, context, createNoopMeter } from './api.js';
import { hrTimeToMicroseconds, millisToHrTime, globalErrorHandler, unrefTimer, internal, ExportResultCode } from './core.js';
import { Resource } from './resources.js';
@@ -126,9 +126,6 @@ function binarySearchLB(arr, value) {
}
return -1;
}
-function equalsCaseInsensitive(lhs, rhs) {
- return lhs.toLowerCase() === rhs.toLowerCase();
-}
var AggregatorKind;
(function (AggregatorKind) {
@@ -167,9 +164,6 @@ var InstrumentType;
InstrumentType["OBSERVABLE_UP_DOWN_COUNTER"] = "OBSERVABLE_UP_DOWN_COUNTER";
})(InstrumentType || (InstrumentType = {}));
function createInstrumentDescriptor(name, type, options) {
- if (!isValidName(name)) {
- diag.warn(`Invalid metric name: "${name}". The metric name should be a ASCII string with a length no greater than 255 characters.`);
- }
return {
name,
type,
@@ -188,15 +182,11 @@ function createInstrumentDescriptorWithView(view, instrument) {
};
}
function isDescriptorCompatibleWith(descriptor, otherDescriptor) {
- return (equalsCaseInsensitive(descriptor.name, otherDescriptor.name) &&
+ return (descriptor.name === otherDescriptor.name &&
descriptor.unit === otherDescriptor.unit &&
descriptor.type === otherDescriptor.type &&
descriptor.valueType === otherDescriptor.valueType);
}
-const NAME_REGEXP = /^[a-z][a-z0-9_.\-/]{0,254}$/i;
-function isValidName(name) {
- return name.match(NAME_REGEXP) != null;
-}
function createNewEmptyCheckpoint(boundaries) {
const counts = boundaries.map(() => 0);
@@ -1193,13 +1183,12 @@ class MetricReader {
this._aggregationTemporalitySelector =
options?.aggregationTemporalitySelector ??
DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR;
- this._metricProducers = options?.metricProducers ?? [];
}
setMetricProducer(metricProducer) {
- if (this._sdkMetricProducer) {
+ if (this._metricProducer) {
throw new Error('MetricReader can not be bound to a MeterProvider again.');
}
- this._sdkMetricProducer = metricProducer;
+ this._metricProducer = metricProducer;
this.onInitialized();
}
selectAggregation(instrumentType) {
@@ -1211,30 +1200,15 @@ class MetricReader {
onInitialized() {
}
async collect(options) {
- if (this._sdkMetricProducer === undefined) {
+ if (this._metricProducer === undefined) {
throw new Error('MetricReader is not bound to a MetricProducer');
}
if (this._shutdown) {
throw new Error('MetricReader is shutdown');
}
- const [sdkCollectionResults, ...additionalCollectionResults] = await Promise.all([
- this._sdkMetricProducer.collect({
- timeoutMillis: options?.timeoutMillis,
- }),
- ...this._metricProducers.map(producer => producer.collect({
- timeoutMillis: options?.timeoutMillis,
- })),
- ]);
- const errors = sdkCollectionResults.errors.concat(FlatMap(additionalCollectionResults, result => result.errors));
- const resource = sdkCollectionResults.resourceMetrics.resource;
- const scopeMetrics = sdkCollectionResults.resourceMetrics.scopeMetrics.concat(FlatMap(additionalCollectionResults, result => result.resourceMetrics.scopeMetrics));
- return {
- resourceMetrics: {
- resource,
- scopeMetrics,
- },
- errors,
- };
+ return this._metricProducer.collect({
+ timeoutMillis: options?.timeoutMillis,
+ });
}
async shutdown(options) {
if (this._shutdown) {
@@ -1267,7 +1241,6 @@ class PeriodicExportingMetricReader extends MetricReader {
super({
aggregationSelector: options.exporter.selectAggregation?.bind(options.exporter),
aggregationTemporalitySelector: options.exporter.selectAggregationTemporality?.bind(options.exporter),
- metricProducers: options.metricProducers,
});
if (options.exportIntervalMillis !== undefined &&
options.exportIntervalMillis <= 0) {
@@ -1655,16 +1628,13 @@ class DeltaMetricProcessor {
}
class TemporalMetricProcessor {
- constructor(_aggregator, collectorHandles) {
+ constructor(_aggregator) {
this._aggregator = _aggregator;
this._unreportedAccumulations = new Map();
this._reportHistory = new Map();
- collectorHandles.forEach(handle => {
- this._unreportedAccumulations.set(handle, []);
- });
}
- buildMetrics(collector, instrumentDescriptor, currentAccumulations, collectionTime) {
- this._stashAccumulations(currentAccumulations);
+ buildMetrics(collector, collectors, instrumentDescriptor, currentAccumulations, collectionTime) {
+ this._stashAccumulations(collectors, currentAccumulations);
const unreportedAccumulations = this._getMergedUnreportedAccumulations(collector);
let result = unreportedAccumulations;
let aggregationTemporality;
@@ -1687,23 +1657,18 @@ class TemporalMetricProcessor {
collectionTime,
aggregationTemporality,
});
- const accumulationRecords = AttributesMapToAccumulationRecords(result);
- if (accumulationRecords.length === 0) {
- return undefined;
- }
- return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, accumulationRecords,
+ return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
collectionTime);
}
- _stashAccumulations(currentAccumulation) {
- const registeredCollectors = this._unreportedAccumulations.keys();
- for (const collector of registeredCollectors) {
- let stash = this._unreportedAccumulations.get(collector);
+ _stashAccumulations(collectors, currentAccumulation) {
+ collectors.forEach(it => {
+ let stash = this._unreportedAccumulations.get(it);
if (stash === undefined) {
stash = [];
- this._unreportedAccumulations.set(collector, stash);
+ this._unreportedAccumulations.set(it, stash);
}
stash.push(currentAccumulation);
- }
+ });
}
_getMergedUnreportedAccumulations(collector) {
let result = new AttributeHashMap();
@@ -1748,11 +1713,11 @@ function AttributesMapToAccumulationRecords(map) {
}
class AsyncMetricStorage extends MetricStorage {
- constructor(_instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
+ constructor(_instrumentDescriptor, aggregator, _attributesProcessor) {
super(_instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
- this._temporalMetricStorage = new TemporalMetricProcessor(aggregator, collectorHandles);
+ this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
}
record(measurements, observationTime) {
const processed = new AttributeHashMap();
@@ -1761,9 +1726,9 @@ class AsyncMetricStorage extends MetricStorage {
});
this._deltaMetricStorage.batchCumulate(processed, observationTime);
}
- collect(collector, collectionTime) {
+ collect(collector, collectors, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
- return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
+ return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
}
}
@@ -2064,19 +2029,19 @@ class ObservableRegistry {
}
class SyncMetricStorage extends MetricStorage {
- constructor(instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
+ constructor(instrumentDescriptor, aggregator, _attributesProcessor) {
super(instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
- this._temporalMetricStorage = new TemporalMetricProcessor(aggregator, collectorHandles);
+ this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
}
record(value, attributes, context, recordTime) {
attributes = this._attributesProcessor.process(attributes, context);
this._deltaMetricStorage.record(value, attributes, context, recordTime);
}
- collect(collector, collectionTime) {
+ collect(collector, collectors, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
- return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
+ return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
}
}
@@ -2126,22 +2091,15 @@ class MeterSharedState {
}
async collect(collector, collectionTime, options) {
const errors = await this.observableRegistry.observe(collectionTime, options?.timeoutMillis);
- const storages = this.metricStorageRegistry.getStorages(collector);
- if (storages.length === 0) {
- return null;
- }
- const metricDataList = storages
+ const metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
.map(metricStorage => {
- return metricStorage.collect(collector, collectionTime);
+ return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, collectionTime);
})
.filter(isNotNullish);
- if (metricDataList.length === 0) {
- return { errors };
- }
return {
scopeMetrics: {
scope: this._instrumentationScope,
- metrics: metricDataList,
+ metrics: metricDataList.filter(isNotNullish),
},
errors,
};
@@ -2155,7 +2113,7 @@ class MeterSharedState {
return compatibleStorage;
}
const aggregator = view.aggregation.createAggregator(viewDescriptor);
- const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor, this._meterProviderSharedState.metricCollectors);
+ const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
this.metricStorageRegistry.register(viewStorage);
return viewStorage;
});
@@ -2167,7 +2125,7 @@ class MeterSharedState {
return compatibleStorage;
}
const aggregator = aggregation.createAggregator(descriptor);
- const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop(), [collector]);
+ const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop());
this.metricStorageRegistry.registerForCollector(collector, storage);
return storage;
});
@@ -2209,24 +2167,14 @@ class MetricCollector {
}
async collect(options) {
const collectionTime = millisToHrTime(Date.now());
- const scopeMetrics = [];
- const errors = [];
- const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(async (meterSharedState) => {
- const current = await meterSharedState.collect(this, collectionTime, options);
- if (current?.scopeMetrics != null) {
- scopeMetrics.push(current.scopeMetrics);
- }
- if (current?.errors != null) {
- errors.push(...current.errors);
- }
- });
- await Promise.all(meterCollectionPromises);
+ const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(meterSharedState => meterSharedState.collect(this, collectionTime, options));
+ const result = await Promise.all(meterCollectionPromises);
return {
resourceMetrics: {
resource: this._sharedState.resource,
- scopeMetrics: scopeMetrics,
+ scopeMetrics: result.map(it => it.scopeMetrics),
},
- errors: errors,
+ errors: FlatMap(result, it => it.errors),
};
}
async forceFlush(options) {
diff --git a/opentelemetry/sdk-trace-base.d.ts b/opentelemetry/sdk-trace-base.d.ts
index db388bc..20445aa 100644
--- a/opentelemetry/sdk-trace-base.d.ts
+++ b/opentelemetry/sdk-trace-base.d.ts
@@ -464,7 +464,6 @@ declare abstract class BatchSpanProcessorBase implements
private readonly _maxQueueSize;
private readonly _scheduledDelayMillis;
private readonly _exportTimeoutMillis;
- private _isExporting;
private _finishedSpans;
private _timer;
private _shutdownOnce;
diff --git a/opentelemetry/sdk-trace-base.js b/opentelemetry/sdk-trace-base.js
index 74be823..92c4509 100644
--- a/opentelemetry/sdk-trace-base.js
+++ b/opentelemetry/sdk-trace-base.js
@@ -427,7 +427,6 @@ function reconfigureLimits(userConfig) {
class BatchSpanProcessorBase {
constructor(_exporter, config) {
this._exporter = _exporter;
- this._isExporting = false;
this._finishedSpans = [];
this._droppedSpansCount = 0;
const env = getEnv();
@@ -550,29 +549,20 @@ class BatchSpanProcessorBase {
});
}
_maybeStartTimer() {
- if (this._isExporting)
+ if (this._timer !== undefined)
return;
- const flush = () => {
- this._isExporting = true;
+ this._timer = setTimeout(() => {
this._flushOneBatch()
.then(() => {
- this._isExporting = false;
if (this._finishedSpans.length > 0) {
this._clearTimer();
this._maybeStartTimer();
}
})
.catch(e => {
- this._isExporting = false;
globalErrorHandler(e);
});
- };
- if (this._finishedSpans.length >= this._maxExportBatchSize) {
- return flush();
- }
- if (this._timer !== undefined)
- return;
- this._timer = setTimeout(() => flush(), this._scheduledDelayMillis);
+ }, this._scheduledDelayMillis);
unrefTimer(this._timer);
}
_clearTimer() {