Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: replace SpanAttributes, MetricsAttributes and ResourceAttributes with Attributes #4928

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :boom: Breaking Change

* refactor!: replace `SpanAttributes`, `MetricsAttributes` and `ResourceAttributes` with `Attributes` [#4928](https://github.com/open-telemetry/opentelemetry-js/pull/4928)
* fix(otlp-exporter-base)!: decrease default concurrency limit to 30 [#4211](https://github.com/open-telemetry/opentelemetry-js/pull/4211) @pichlermarc
* fixes a memory leak on prolonged collector unavailability
* this change is marked as breaking as it changes defaults
Expand Down
3 changes: 0 additions & 3 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export {
UpDownCounter,
BatchObservableCallback,
MetricAdvice,
MetricAttributes,
MetricAttributeValue,
ObservableCallback,
} from './metrics/Metric';
export {
Expand All @@ -74,7 +72,6 @@ export {
export type { PropagationAPI } from './api/propagation';

// Trace APIs
export { SpanAttributes, SpanAttributeValue } from './trace/attributes';
export { Link } from './trace/link';
export { ProxyTracer, TracerDelegator } from './trace/ProxyTracer';
export { ProxyTracerProvider } from './trace/ProxyTracerProvider';
Expand Down
28 changes: 10 additions & 18 deletions api/src/metrics/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import { Attributes } from '../common/Attributes';
import {
BatchObservableCallback,
Counter,
Gauge,
Histogram,
MetricAttributes,
MetricOptions,
Observable,
ObservableCounter,
Expand Down Expand Up @@ -51,7 +51,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createGauge<AttributesTypes extends MetricAttributes = MetricAttributes>(
createGauge<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): Gauge<AttributesTypes>;
Expand All @@ -61,7 +61,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createHistogram<AttributesTypes extends MetricAttributes = MetricAttributes>(
createHistogram<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): Histogram<AttributesTypes>;
Expand All @@ -73,7 +73,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(
createCounter<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): Counter<AttributesTypes>;
Expand All @@ -95,9 +95,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createUpDownCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
>(
createUpDownCounter<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): UpDownCounter<AttributesTypes>;
Expand All @@ -110,9 +108,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createObservableGauge<
AttributesTypes extends MetricAttributes = MetricAttributes,
>(
createObservableGauge<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): ObservableGauge<AttributesTypes>;
Expand All @@ -125,9 +121,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createObservableCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
>(
createObservableCounter<AttributesTypes extends Attributes = Attributes>(
name: string,
options?: MetricOptions
): ObservableCounter<AttributesTypes>;
Expand All @@ -141,7 +135,7 @@ export interface Meter {
* @param [options] the metric options.
*/
createObservableUpDownCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
>(
name: string,
options?: MetricOptions
Expand All @@ -161,9 +155,7 @@ export interface Meter {
* @param callback the batch observable callback
* @param observables the observables associated with this batch observable callback
*/
addBatchObservableCallback<
AttributesTypes extends MetricAttributes = MetricAttributes,
>(
addBatchObservableCallback<AttributesTypes extends Attributes = Attributes>(
callback: BatchObservableCallback<AttributesTypes>,
observables: Observable<AttributesTypes>[]
): void;
Expand All @@ -178,7 +170,7 @@ export interface Meter {
* @param observables the observables associated with this batch observable callback
*/
removeBatchObservableCallback<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
>(
callback: BatchObservableCallback<AttributesTypes>,
observables: Observable<AttributesTypes>[]
Expand Down
46 changes: 13 additions & 33 deletions api/src/metrics/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Attributes, AttributeValue } from '../common/Attributes';
import { Attributes } from '../common/Attributes';
import { Context } from '../context/types';
import { BatchObservableResult, ObservableResult } from './ObservableResult';

Expand Down Expand Up @@ -80,57 +80,41 @@ export enum ValueType {
* <li> count the number of 5xx errors. </li>
* <ol>
*/
export interface Counter<
AttributesTypes extends MetricAttributes = MetricAttributes,
> {
export interface Counter<AttributesTypes extends Attributes = Attributes> {
/**
* Increment value of counter by the input. Inputs must not be negative.
*/
add(value: number, attributes?: AttributesTypes, context?: Context): void;
}

export interface UpDownCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> {
/**
* Increment value of counter by the input. Inputs may be negative.
*/
add(value: number, attributes?: AttributesTypes, context?: Context): void;
}

export interface Gauge<
AttributesTypes extends MetricAttributes = MetricAttributes,
> {
export interface Gauge<AttributesTypes extends Attributes = Attributes> {
/**
* Records a measurement.
*/
record(value: number, attributes?: AttributesTypes, context?: Context): void;
}

export interface Histogram<
AttributesTypes extends MetricAttributes = MetricAttributes,
> {
export interface Histogram<AttributesTypes extends Attributes = Attributes> {
/**
* Records a measurement. Value of the measurement must not be negative.
*/
record(value: number, attributes?: AttributesTypes, context?: Context): void;
}

/**
* @deprecated please use {@link Attributes}
*/
export type MetricAttributes = Attributes;

/**
* @deprecated please use {@link AttributeValue}
*/
export type MetricAttributeValue = AttributeValue;

/**
* The observable callback for Observable instruments.
*/
export type ObservableCallback<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> = (
observableResult: ObservableResult<AttributesTypes>
) => void | Promise<void>;
Expand All @@ -139,14 +123,12 @@ export type ObservableCallback<
* The observable callback for a batch of Observable instruments.
*/
export type BatchObservableCallback<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> = (
observableResult: BatchObservableResult<AttributesTypes>
) => void | Promise<void>;

export interface Observable<
AttributesTypes extends MetricAttributes = MetricAttributes,
> {
export interface Observable<AttributesTypes extends Attributes = Attributes> {
/**
* Sets up a function that will be called whenever a metric collection is initiated.
*
Expand All @@ -160,12 +142,10 @@ export interface Observable<
removeCallback(callback: ObservableCallback<AttributesTypes>): void;
}

export type ObservableCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
> = Observable<AttributesTypes>;
export type ObservableCounter<AttributesTypes extends Attributes = Attributes> =
Observable<AttributesTypes>;
export type ObservableUpDownCounter<
AttributesTypes extends MetricAttributes = MetricAttributes,
> = Observable<AttributesTypes>;
export type ObservableGauge<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> = Observable<AttributesTypes>;
export type ObservableGauge<AttributesTypes extends Attributes = Attributes> =
Observable<AttributesTypes>;
10 changes: 5 additions & 5 deletions api/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import { Attributes } from '../common/Attributes';
import { Meter } from './Meter';
import {
BatchObservableCallback,
Counter,
Gauge,
Histogram,
MetricAttributes,
MetricOptions,
Observable,
ObservableCallback,
Expand Down Expand Up @@ -112,22 +112,22 @@
export class NoopMetric {}

export class NoopCounterMetric extends NoopMetric implements Counter {
add(_value: number, _attributes: MetricAttributes): void {}
add(_value: number, _attributes: Attributes): void {}
}

export class NoopUpDownCounterMetric
extends NoopMetric
implements UpDownCounter
{
add(_value: number, _attributes: MetricAttributes): void {}
add(_value: number, _attributes: Attributes): void {}
}

export class NoopGaugeMetric extends NoopMetric implements Gauge {
record(_value: number, _attributes: MetricAttributes): void {}
record(_value: number, _attributes: Attributes): void {}

Check warning on line 126 in api/src/metrics/NoopMeter.ts

View check run for this annotation

Codecov / codecov/patch

api/src/metrics/NoopMeter.ts#L126

Added line #L126 was not covered by tests
}

export class NoopHistogramMetric extends NoopMetric implements Histogram {
record(_value: number, _attributes: MetricAttributes): void {}
record(_value: number, _attributes: Attributes): void {}
}

export class NoopObservableMetric {
Expand Down
7 changes: 4 additions & 3 deletions api/src/metrics/ObservableResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import { MetricAttributes, Observable } from './Metric';
import { Attributes } from '../common/Attributes';
import { Observable } from './Metric';

/**
* Interface that is being used in callback function for Observable Metric.
*/
export interface ObservableResult<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> {
/**
* Observe a measurement of the value associated with the given attributes.
Expand All @@ -41,7 +42,7 @@ export interface ObservableResult<
* Interface that is being used in batch observable callback function.
*/
export interface BatchObservableResult<
AttributesTypes extends MetricAttributes = MetricAttributes,
AttributesTypes extends Attributes = Attributes,
> {
/**
* Observe a measurement of the value associated with the given attributes.
Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/NonRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Exception } from '../common/Exception';
import { TimeInput } from '../common/Time';
import { SpanAttributes } from './attributes';
import { Attributes } from '../common/Attributes';
import { INVALID_SPAN_CONTEXT } from './invalid-span-constants';
import { Span } from './span';
import { SpanContext } from './span_context';
Expand Down Expand Up @@ -44,12 +44,12 @@ export class NonRecordingSpan implements Span {
}

// By default does nothing
setAttributes(_attributes: SpanAttributes): this {
setAttributes(_attributes: Attributes): this {
return this;
}

// By default does nothing
addEvent(_name: string, _attributes?: SpanAttributes): this {
addEvent(_name: string, _attributes?: Attributes): this {
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/Sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Context } from '../context/types';
import { SpanAttributes } from './attributes';
import { Attributes } from '../common/Attributes';
import { Link } from './link';
import { SamplingResult } from './SamplingResult';
import { SpanKind } from './span_kind';
Expand All @@ -36,7 +36,7 @@ export interface Sampler {
* span to be created starts a new trace.
* @param spanName of the span to be created.
* @param spanKind of the span to be created.
* @param attributes Initial set of SpanAttributes for the Span being constructed.
* @param attributes Initial set of Attributes for the Span being constructed.
* @param links Collection of links that will be associated with the Span to
* be created. Typically useful for batch operations.
* @returns a {@link SamplingResult}.
Expand All @@ -46,7 +46,7 @@ export interface Sampler {
traceId: string,
spanName: string,
spanKind: SpanKind,
attributes: SpanAttributes,
attributes: Attributes,
links: Link[]
): SamplingResult;

Expand Down
4 changes: 2 additions & 2 deletions api/src/trace/SamplingResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { SpanAttributes } from './attributes';
import { Attributes } from '../common/Attributes';
import { TraceState } from './trace_state';

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface SamplingResult {
* Caller may call {@link Sampler}.shouldSample any number of times and
* can safely cache the returned value.
*/
attributes?: Readonly<SpanAttributes>;
attributes?: Readonly<Attributes>;
/**
* A {@link TraceState} that will be associated with the {@link Span} through
* the new {@link SpanContext}. Samplers SHOULD return the TraceState from
Expand Down
4 changes: 2 additions & 2 deletions api/src/trace/SpanOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { TimeInput } from '../common/Time';
import { SpanAttributes } from './attributes';
import { Attributes } from '../common/Attributes';
import { Link } from './link';
import { SpanKind } from './span_kind';

Expand All @@ -30,7 +30,7 @@ export interface SpanOptions {
kind?: SpanKind;

/** A span's attributes */
attributes?: SpanAttributes;
attributes?: Attributes;

/** {@link Link}s span to other spans */
links?: Link[];
Expand Down
Loading