-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3344 from aws/muhamoth/DOTNET-7517-Observability-…
…Add-Observability-APIs-to-the-SDK Add Observability APIs to the SDK and add telemetry provider reference to AWSConfigs and ClientConfig
- Loading branch information
Showing
30 changed files
with
1,401 additions
and
0 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
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
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,93 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Amazon.Runtime.Telemetry | ||
{ | ||
/// <summary> | ||
/// Represents a collection of attributes used for telemetry purposes. | ||
/// Attributes are key-value pairs where the key is a string and the value is an object. | ||
/// These attributes provide additional information for spans and metrics in telemetry data. | ||
/// </summary> | ||
public class Attributes | ||
{ | ||
private readonly Dictionary<string, object> _attributes; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Attributes"/> class. | ||
/// </summary> | ||
public Attributes() | ||
{ | ||
_attributes = new Dictionary<string, object>(); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Attributes"/> class. | ||
/// If duplicate keys are present in the provided collection, the value of the last occurrence of the key will be used. | ||
/// </summary> | ||
/// <param name="attributes">An optional initial set of attributes to populate the collection. | ||
/// If duplicate keys are found, the last value will override previous ones.</param> | ||
public Attributes(IEnumerable<KeyValuePair<string, object>> attributes) | ||
{ | ||
_attributes = new Dictionary<string, object>(); | ||
|
||
foreach (var kvp in attributes) | ||
{ | ||
_attributes[kvp.Key] = kvp.Value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the value for the given attribute key. | ||
/// If the key already exists, the value is updated. | ||
/// </summary> | ||
/// <param name="key">The key of the attribute.</param> | ||
/// <param name="value">The value of the attribute.</param> | ||
public void Set(string key, object value) | ||
{ | ||
_attributes[key] = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value for the given attribute key. | ||
/// </summary> | ||
/// <param name="key">The attribute key.</param> | ||
/// <returns>The attribute value, or null if the key does not exist.</returns> | ||
public object Get(string key) | ||
{ | ||
_attributes.TryGetValue(key, out var value); | ||
return value; | ||
} | ||
|
||
/// <summary> | ||
/// Removes the attribute with the specified key. | ||
/// </summary> | ||
/// <param name="key">The attribute key.</param> | ||
/// <returns>True if the attribute was successfully removed; otherwise, false.</returns> | ||
public bool Remove(string key) | ||
{ | ||
return _attributes.Remove(key); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the collection of all the attributes. | ||
/// </summary> | ||
public IEnumerable<KeyValuePair<string, object>> AllAttributes | ||
{ | ||
get { return _attributes; } | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
sdk/src/Core/Amazon.Runtime/Telemetry/DefaultTelemetryProvider.cs
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,73 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
using Amazon.Runtime.Telemetry.Metrics; | ||
using Amazon.Runtime.Telemetry.Metrics.NoOp; | ||
using Amazon.Runtime.Telemetry.Tracing; | ||
using Amazon.Runtime.Telemetry.Tracing.NoOp; | ||
|
||
namespace Amazon.Runtime.Telemetry | ||
{ | ||
/// <summary> | ||
/// Default implementation of <see cref="TelemetryProvider"/> that uses no-op providers by default. | ||
/// </summary> | ||
public class DefaultTelemetryProvider : TelemetryProvider | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DefaultTelemetryProvider"/> class with no-op providers. | ||
/// This setup prevents any telemetry actions from being performed unless explicitly registered using the | ||
/// registration methods. | ||
/// </summary> | ||
public DefaultTelemetryProvider() | ||
{ | ||
TracerProvider = new NoOpTracerProvider(); | ||
MeterProvider = new NoOpMeterProvider(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="TracerProvider"/> used to create new tracers. | ||
/// This property is initialized with a no-op implementation by default. | ||
/// </summary> | ||
public override TracerProvider TracerProvider { get; protected set; } | ||
|
||
/// <summary> | ||
/// Gets the <see cref="MeterProvider"/> used to create new metrics. | ||
/// This property is initialized with a no-op implementation by default. | ||
/// </summary> | ||
public override MeterProvider MeterProvider { get; protected set; } | ||
|
||
/// <summary> | ||
/// Registers a new <see cref="TracerProvider"/>. | ||
/// This method sets a custom tracer provider to replace the default no-op provider, | ||
/// enabling the collection of tracing data. | ||
/// </summary> | ||
/// <param name="tracerProvider">The tracer provider to register.</param> | ||
public override void RegisterTracerProvider(TracerProvider tracerProvider) | ||
{ | ||
TracerProvider = tracerProvider; | ||
} | ||
|
||
/// <summary> | ||
/// Registers a new <see cref="MeterProvider"/>. | ||
/// This method sets a custom meter provider to replace the default no-op provider, | ||
/// enabling the collection of metrics data. | ||
/// </summary> | ||
/// <param name="meterProvider">The meter provider to register.</param> | ||
public override void RegisterMeterProvider(MeterProvider meterProvider) | ||
{ | ||
MeterProvider = meterProvider; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
sdk/src/Core/Amazon.Runtime/Telemetry/Metrics/AsyncMeasurement.cs
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,34 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
namespace Amazon.Runtime.Telemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// Represents an async measurement. | ||
/// An async measurement records values, such as periodically or based on events. | ||
/// The generic type parameter T specifies the type of value being recorded, such as int, long, etc. | ||
/// </summary> | ||
/// <typeparam name="T">The type of value being measured.</typeparam> | ||
public abstract class AsyncMeasurement<T> where T : struct | ||
{ | ||
/// <summary> | ||
/// Records a value. | ||
/// This method is called to record a measurement value. | ||
/// </summary> | ||
/// <param name="value">The value to be recorded. This value is of type T.</param> | ||
/// <param name="attributes">Optional attributes associated with the measurement.</param> | ||
public abstract void Record(T value, Attributes attributes = null); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
sdk/src/Core/Amazon.Runtime/Telemetry/Metrics/AsyncMeasurementHandle.cs
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 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
namespace Amazon.Runtime.Telemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// Represents a handle for async measurements. | ||
/// The handle is used to manage and stop the async recording of measurements. | ||
/// </summary> | ||
/// <typeparam name="T">The type of value being measured.</typeparam> | ||
public abstract class AsyncMeasurementHandle<T> where T : struct | ||
{ | ||
/// <summary> | ||
/// Gets the meter that created this handle. | ||
/// </summary> | ||
public Meter Meter { get; protected set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AsyncMeasurementHandle{T}"/> class. | ||
/// </summary> | ||
/// <param name="meter">The meter that created this handle.</param> | ||
protected AsyncMeasurementHandle(Meter meter) | ||
{ | ||
Meter = meter; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
sdk/src/Core/Amazon.Runtime/Telemetry/Metrics/Histogram.cs
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,33 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
namespace Amazon.Runtime.Telemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// Abstract class representing a histogram used to record values of a specified type. | ||
/// A histogram is a type of metric instrument that tracks the distribution of values. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the histogram value. Must be a struct.</typeparam> | ||
public abstract class Histogram<T> where T : struct | ||
{ | ||
/// <summary> | ||
/// Records a value in the histogram. | ||
/// </summary> | ||
/// <param name="value">The value to record. This represents a measurement or observation.</param> | ||
/// <param name="attributes">Optional attributes associated with the measurement. These can be used to | ||
/// provide additional context or dimensions to the recorded value.</param> | ||
public abstract void Record(T value, Attributes attributes = null); | ||
} | ||
} |
Oops, something went wrong.