Skip to content

Commit

Permalink
Add telemetry provider to AWSConfigs and ClientConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-othman committed Jun 16, 2024
1 parent eb2d20b commit 257d613
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sdk/src/Core/AWSConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Amazon.Util.Internal;
using System.Collections.Generic;
using Amazon.Runtime;
using Amazon.Runtime.Telemetry;

namespace Amazon
{
Expand Down Expand Up @@ -90,6 +91,7 @@ public static partial class AWSConfigs
// for reading from awsconfigs.xml
private static object _lock = new object();
private static List<string> standardConfigs = new List<string>() { "region", "logging", "correctForClockSkew" };
private static TelemetryProvider _telemetryProvider = new DefaultTelemetryProvider();

#pragma warning disable 414
private static bool configPresent = true;
Expand Down Expand Up @@ -474,6 +476,19 @@ public static bool UseAlternateUserAgentHeader
set { _rootConfig.UseAlternateUserAgentHeader = value; }
}

/// <summary>
/// Gets or sets the global <see cref="TelemetryProvider"/> instance.
/// <para>
/// This global telemetry provider is used to collect and report telemetry data
/// (such as traces and metrics) for all AWS SDK operations.
/// </para>
/// </summary>
public static TelemetryProvider TelemetryProvider
{
get { return _telemetryProvider; }
set { _telemetryProvider = value; }
}

/// <summary>
/// Configuration for the region endpoint section of AWS configuration.
/// Changes may not take effect until a new client is constructed.
Expand Down
17 changes: 17 additions & 0 deletions sdk/src/Core/Amazon.Runtime/ClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.ComponentModel.Design;
using Amazon.Runtime.CredentialManagement;
using Amazon.Runtime.Internal.Settings;
using Amazon.Runtime.Telemetry;

#if NETSTANDARD
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -93,6 +94,7 @@ public abstract partial class ClientConfig : IClientConfig
private const long DefaultMinCompressionSizeBytes = 10240;
private bool didProcessServiceURL = false;
private IAWSTokenProvider _awsTokenProvider = new DefaultAWSTokenProviderChain();
private TelemetryProvider telemetryProvider = AWSConfigs.TelemetryProvider;

private CredentialProfileStoreChain credentialProfileStoreChain;
#if BCL
Expand Down Expand Up @@ -1239,5 +1241,20 @@ public TimeSpan? ReadWriteTimeout
/// but can be changed to use custom user supplied EndpointProvider.
/// </summary>
public IEndpointProvider EndpointProvider { get; set; }

/// <summary>
/// Gets or sets the <see cref="TelemetryProvider"/> instance for this client configuration.
/// <para>
/// This telemetry provider is used to collect and report telemetry data
/// (such as traces and metrics) for operations performed by this specific client.
/// If this property is not explicitly set, it will default to the global
/// <see cref="AWSConfigs.TelemetryProvider"/>.
/// </para>
/// </summary>
public TelemetryProvider TelemetryProvider
{
get { return this.telemetryProvider; }
set { this.telemetryProvider = value; }
}
}
}
11 changes: 11 additions & 0 deletions sdk/src/Core/Amazon.Runtime/IClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Amazon.Runtime.Endpoints;
using Amazon.Runtime.Internal.Auth;
using Amazon.Util;
using Amazon.Runtime.Telemetry;
#if NETSTANDARD
using System.Net.Http;
#endif
Expand Down Expand Up @@ -369,6 +370,16 @@ public partial interface IClientConfig
/// which doesn't allow to specify the User-Agent header.
/// </summary>
bool UseAlternateUserAgentHeader { get; }

/// <summary>
/// <para>
/// This telemetry provider is used to collect and report telemetry data
/// (such as traces and metrics) for operations performed by this specific client.
/// If this property is not explicitly set, it will default to the global
/// <see cref="AWSConfigs.TelemetryProvider"/>.
/// </para>
/// </summary>
TelemetryProvider TelemetryProvider { get; }
#if BCL
/// <summary>
/// Gets the TCP keep-alive values to use for service requests. Enabling TCP keep-alive sends periodic TCP keep-alive probe packets, to prevent disconnection due to
Expand Down

0 comments on commit 257d613

Please sign in to comment.