-
Notifications
You must be signed in to change notification settings - Fork 773
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
Add a temp project with Metric API (which will come eventually from runtime) #2033
Merged
cijothomas
merged 10 commits into
open-telemetry:metrics
from
cijothomas:cijothomas/metricapitemp
May 4, 2021
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd163d4
Add a temp project with Metric API (which will come eventually from r…
cijothomas a46f82b
markdown
cijothomas ccb5fa3
for temp project dont treat warning as error
cijothomas 8495a5b
readme fix
cijothomas 1fb3841
spacing issues
cijothomas a4203e2
format fixes
cijothomas d1c45af
readme fix attempt
cijothomas f1f8450
more space issues
cijothomas 047e795
format fixes
cijothomas a11d91e
dont pack
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,39 @@ | ||
// <copyright file="MeterProviderBuilder.cs" company="OpenTelemetry Authors"> | ||
// 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 | ||
// | ||
// http://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. | ||
// </copyright> | ||
using System; | ||
|
||
namespace OpenTelemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// MeterProviderBuilder base class. | ||
/// </summary> | ||
public abstract class MeterProviderBuilder | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MeterProviderBuilder"/> class. | ||
/// </summary> | ||
protected MeterProviderBuilder() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Adds given meter source names to the list of subscribed sources. | ||
/// </summary> | ||
/// <param name="names">Meter source names.</param> | ||
/// <returns>Returns <see cref="MeterProviderBuilder"/> for chaining.</returns> | ||
public abstract MeterProviderBuilder AddSource(params string[] names); | ||
} | ||
} |
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,30 @@ | ||
// <copyright file="MeterProviderBuilderSdk.cs" company="OpenTelemetry Authors"> | ||
// 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 | ||
// | ||
// http://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. | ||
// </copyright> | ||
|
||
namespace OpenTelemetry.Metrics | ||
{ | ||
public class MeterProviderBuilderSdk : MeterProviderBuilder | ||
{ | ||
protected MeterProviderBuilderSdk() | ||
{ | ||
} | ||
|
||
public override MeterProviderBuilder AddSource(params string[] names) | ||
{ | ||
return this; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// <copyright file="ActivityExtensions.cs" company="OpenTelemetry Authors"> | ||
// 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 | ||
// | ||
// http://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. | ||
// </copyright> | ||
|
||
#nullable enable | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
public class Counter<T> : MeterInstrument<T> | ||
where T : unmanaged | ||
{ | ||
internal Counter(Meter meter, string name, string? description, string? unit) : | ||
base(meter, name, description, unit) | ||
{ | ||
Publish(); | ||
} | ||
|
||
public void Add(T measurement) => RecordMeasurement(measurement); | ||
public void Add(T measurement, | ||
(string LabelName, object LabelValue) label1) => RecordMeasurement(measurement, label1); | ||
public void Add(T measurement, | ||
(string LabelName, object LabelValue) label1, | ||
(string LabelName, object LabelValue) label2) => RecordMeasurement(measurement, label1, label2); | ||
public void Add(T measurement, | ||
(string LabelName, object LabelValue) label1, | ||
(string LabelName, object LabelValue) label2, | ||
(string LabelName, object LabelValue) label3) => RecordMeasurement(measurement, label1, label2, label3); | ||
public void Add(T measurement, params (string LabelName, object LabelValue)[] labels) => RecordMeasurement(measurement, labels); | ||
} | ||
} |
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,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
public class CounterFunc<T> : ObservableMeterInstrument<T> where T : unmanaged | ||
{ | ||
// This is either a Func<T> or an Func<IEnumerable<Measurement<T>>> | ||
object _observeValueFunc; | ||
|
||
public CounterFunc(Meter meter, string name, Func<T> observeValue, string? description, string? unit) : | ||
base(meter, name, description, unit) | ||
{ | ||
_observeValueFunc = observeValue; | ||
Publish(); | ||
} | ||
|
||
public CounterFunc(Meter meter, string name, Func<IEnumerable<Measurement<T>>> observeValues, string? description, string? unit) : | ||
base(meter, name, description, unit) | ||
{ | ||
_observeValueFunc = observeValues; | ||
Publish(); | ||
} | ||
|
||
protected override IEnumerable<Measurement<T>> Observe() | ||
{ | ||
if (_observeValueFunc is Func<T>) | ||
{ | ||
T value = ((Func<T>)_observeValueFunc)(); | ||
return new Measurement<T>[] { new Measurement<T>(value) }; | ||
} | ||
else | ||
{ | ||
return ((Func<IEnumerable<Measurement<T>>>)_observeValueFunc)(); | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
public class Distribution<T> : MeterInstrument<T> where T : unmanaged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many places not updated to the latest API spec:
|
||
{ | ||
internal Distribution(Meter meter, string name, string? description, string? unit) | ||
: base(meter, name, description, unit) | ||
{ | ||
Publish(); | ||
} | ||
|
||
public void Record(T measurement) => RecordMeasurement(measurement); | ||
public void Record(T measurement, | ||
(string LabelName, object LabelValue) label1) => RecordMeasurement(measurement, label1); | ||
public void Record(T measurement, | ||
(string LabelName, object LabelValue) label1, | ||
(string LabelName, object LabelValue) label2) => RecordMeasurement(measurement, label1, label2); | ||
public void Record(T measurement, | ||
(string LabelName, object LabelValue) label1, | ||
(string LabelName, object LabelValue) label2, | ||
(string LabelName, object LabelValue) label3) => RecordMeasurement(measurement, label1, label2, label3); | ||
public void Record(T measurement, params (string LabelName, object LabelValue)[] labels) => RecordMeasurement(measurement, labels); | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
public class Gauge<T> : MeterInstrument<T> where T : unmanaged | ||
{ | ||
internal Gauge(Meter meter, string name, string? description, string? unit) : | ||
base(meter, name, description, unit) | ||
{ | ||
Publish(); | ||
} | ||
|
||
public void Set(T val) | ||
{ | ||
RecordMeasurement(val); | ||
} | ||
|
||
public void Set(T val, params (string LabelName, object LabelValue)[] labels) | ||
{ | ||
RecordMeasurement(val, labels); | ||
} | ||
} | ||
} |
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,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
|
||
namespace System.Diagnostics.Metrics | ||
{ | ||
public class Meter : IDisposable | ||
{ | ||
List<MeterInstrument>? _instruments = new List<MeterInstrument>(); | ||
|
||
public Meter(string name) : this(name, "") { } | ||
|
||
public Meter(string name, string version) | ||
{ | ||
Name = name; | ||
Version = version; | ||
lock (MeterInstrumentCollection.Lock) | ||
{ | ||
MeterInstrumentCollection.Instance.AddMeter(this); | ||
} | ||
} | ||
|
||
public Counter<T> CreateCounter<T>(string name, string? description = null, string? unit = null) where T : unmanaged | ||
{ | ||
return new Counter<T>(this, name, description, unit); | ||
} | ||
|
||
public CounterFunc<T> CreateCounterFunc<T>(string name, Func<T> observeValue, string? description = null, string? unit = null) where T : unmanaged | ||
{ | ||
return new CounterFunc<T>(this, name, observeValue, description, unit); | ||
} | ||
|
||
public CounterFunc<T> CreateCounterFunc<T>(string name, Func<IEnumerable<Measurement<T>>> observeValues, string? description = null, string? unit = null) where T : unmanaged | ||
{ | ||
return new CounterFunc<T>(this, name, observeValues, description, unit); | ||
} | ||
|
||
public Gauge<T> CreateGauge<T>(string name, string? description = null, string? unit = null) where T : unmanaged | ||
{ | ||
return new Gauge<T>(this, name, description, unit); | ||
} | ||
|
||
public Distribution<T> CreateDistribution<T>(string name, string? description = null, string? unit = null) where T : unmanaged | ||
{ | ||
return new Distribution<T>(this, name, description, unit); | ||
} | ||
|
||
public string Name { get; } | ||
public string Version { get; } | ||
|
||
|
||
internal void PublishInstrument(MeterInstrument instrument) | ||
{ | ||
lock (MeterInstrumentCollection.Lock) | ||
{ | ||
if (_instruments != null) // if not disposed | ||
{ | ||
_instruments.Add(instrument); | ||
MeterInstrumentCollection.Instance.PublishInstrument(instrument); | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
lock (MeterInstrumentCollection.Lock) | ||
{ | ||
MeterInstrumentCollection.Instance.RemoveMeter(this); | ||
_instruments = null; | ||
} | ||
} | ||
|
||
internal IEnumerable<MeterInstrument> Instruments => | ||
#if NET452 | ||
(IEnumerable<MeterInstrument>?)_instruments ?? new MeterInstrument[0]; | ||
#else | ||
(IEnumerable<MeterInstrument>?)_instruments ?? Array.Empty<MeterInstrument>(); | ||
#endif | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is called
ObservableCounter
(or do you intend to change it later)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes will be change to match https://github.com/dotnet/designs/pull/211/files. This PR is to get started with a temp proj file.