-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Georg Pirklbauer <[email protected]>
- Loading branch information
Showing
16 changed files
with
548 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,6 @@ | |
}, | ||
{ | ||
"path": "../opentelemetry-exporter-trace-otlp-http" | ||
}, | ||
{ | ||
"path": "../opentelemetry-sdk-metrics-base" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
}, | ||
{ | ||
"path": "../opentelemetry-exporter-trace-otlp-http" | ||
}, | ||
{ | ||
"path": "../opentelemetry-sdk-metrics-base" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,6 @@ | |
"references": [ | ||
{ | ||
"path": "../opentelemetry-api-metrics" | ||
}, | ||
{ | ||
"path": "../opentelemetry-sdk-metrics-base" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
experimental/packages/opentelemetry-sdk-metrics-base/src/Aggregation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Measurement } from './Measurement'; | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#aggregation | ||
|
||
export interface Aggregator { | ||
aggregate(measurement: Measurement): void; | ||
} | ||
|
||
// TODO define actual aggregator classes |
70 changes: 70 additions & 0 deletions
70
experimental/packages/opentelemetry-sdk-metrics-base/src/Instruments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as api from '@opentelemetry/api'; | ||
import * as metrics from '@opentelemetry/api-metrics'; | ||
import { Meter } from './Meter'; | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument | ||
|
||
export enum InstrumentType { | ||
COUNTER = 'COUNTER', | ||
HISTOGRAM = 'HISTOGRAM', | ||
UP_DOWN_COUNTER = 'UP_DOWN_COUNTER', | ||
OBSERVABLE_COUNTER = 'OBSERVABLE_COUNTER', | ||
OBSERVABLE_GAUGE = 'OBSERVABLE_GAUGE', | ||
OBSERVABLE_UP_DOWN_COUNTER = 'OBSERVABLE_UP_DOWN_COUNTER', | ||
} | ||
|
||
export class SyncInstrument { | ||
constructor(private _meter: Meter, private _name: string) { } | ||
|
||
getName(): string { | ||
return this._name; | ||
} | ||
|
||
|
||
aggregate(value: number, attributes: metrics.Attributes = {}, ctx: api.Context = api.context.active()) { | ||
this._meter.aggregate(this, { | ||
value, | ||
attributes, | ||
context: ctx, | ||
}); | ||
} | ||
} | ||
|
||
export class UpDownCounter extends SyncInstrument implements metrics.Counter { | ||
add(value: number, attributes?: metrics.Attributes, ctx?: api.Context): void { | ||
this.aggregate(value, attributes, ctx); | ||
} | ||
} | ||
|
||
export class Counter extends SyncInstrument implements metrics.Counter { | ||
add(value: number, attributes?: metrics.Attributes, ctx?: api.Context): void { | ||
if (value < 0) { | ||
api.diag.warn(`negative value provided to counter ${this.getName()}: ${value}`); | ||
return; | ||
} | ||
|
||
this.aggregate(value, attributes, ctx); | ||
} | ||
} | ||
|
||
export class Histogram extends SyncInstrument implements metrics.Histogram { | ||
record(value: number, attributes?: metrics.Attributes, ctx?: api.Context): void { | ||
this.aggregate(value, attributes, ctx); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
experimental/packages/opentelemetry-sdk-metrics-base/src/Measurement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as api from '@opentelemetry/api' | ||
import { Attributes } from '@opentelemetry/api-metrics' | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#measurement | ||
|
||
export type Measurement = { | ||
value: number; | ||
// TODO use common attributes | ||
attributes: Attributes | ||
context?: api.Context; | ||
} |
65 changes: 65 additions & 0 deletions
65
experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as metrics from '@opentelemetry/api-metrics'; | ||
import { InstrumentationLibrary } from '@opentelemetry/core'; | ||
import { Counter, Histogram, UpDownCounter } from './Instruments'; | ||
import { Measurement } from './Measurement'; | ||
import { MeterProvider } from './MeterProvider'; | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#meter | ||
|
||
export class Meter implements metrics.Meter { | ||
// instrumentation library required by spec to be on meter | ||
// spec requires provider config changes to apply to previously created meters, achieved by holding a reference to the provider | ||
constructor(private _provider: MeterProvider, private _instrumentationLibrary: InstrumentationLibrary, private _schemaUrl?: string) { } | ||
|
||
/** this exists just to prevent ts errors from unused variables and may be removed */ | ||
getSchemaUrl(): string | undefined { | ||
return this._schemaUrl; | ||
} | ||
|
||
/** this exists just to prevent ts errors from unused variables and may be removed */ | ||
getInstrumentationLibrary(): InstrumentationLibrary { | ||
return this._instrumentationLibrary; | ||
} | ||
|
||
createHistogram(_name: string, _options?: metrics.MetricOptions): Histogram { | ||
return new Histogram(this, _name); | ||
} | ||
|
||
createCounter(_name: string, _options?: metrics.MetricOptions): metrics.Counter { | ||
return new Counter(this, _name); | ||
} | ||
|
||
createUpDownCounter(_name: string, _options?: metrics.MetricOptions): metrics.UpDownCounter { | ||
return new UpDownCounter(this, _name); | ||
} | ||
|
||
createObservableGauge(_name: string, _options?: metrics.MetricOptions, _callback?: (observableResult: metrics.ObservableResult) => void): metrics.ObservableBase { | ||
throw new Error('Method not implemented.'); | ||
} | ||
createObservableCounter(_name: string, _options?: metrics.MetricOptions, _callback?: (observableResult: metrics.ObservableResult) => void): metrics.ObservableBase { | ||
throw new Error('Method not implemented.'); | ||
} | ||
createObservableUpDownCounter(_name: string, _options?: metrics.MetricOptions, _callback?: (observableResult: metrics.ObservableResult) => void): metrics.ObservableBase { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
public aggregate(metric: unknown, measurement: Measurement) { | ||
this._provider.aggregate(this, metric, measurement); | ||
} | ||
} |
Oops, something went wrong.