Skip to content

Commit d621add

Browse files
m-reddingjsquirechristothes
authored
[System.ClientModel] Add Logging (Azure#45472)
* initial draft * WIP test stubs pt 1 * WIP test stubs 2 * tweaks * changes * p1 of adding Event Source * tests p1 * test updates * Tests2 * updates * API * try slimming methods and adding retry policy log * test * refactory + add abstraction * add tests and update api * more tests * fix functional tests * static -> instance * updates * tweaks * tweaks * fix * little refactorings * tweaks * tweaks * WIP feedback * reformat * WIP more feedback * WIP * WIP - updates * Export API * API * API tweaks * comment * changes 1 * changes 2 * changes * fixes * more updates * some tests * WIP - experiment * wip * wip fixes * event source / logger tests green * API * fb * implement request ID * adding tests, some fb * more FB * more fb + more tests * WIP * tweaks to logging stream * tests green * test updates * more test updates * Update sdk/core/System.ClientModel/src/Options/ClientLoggingOptions.cs Co-authored-by: Jesse Squire <[email protected]> * fb 1 * fb 2 * fixes * initial samples * api fix and logging.md * tests * Apply suggestions from code review Co-authored-by: Christopher Scott <[email protected]> * feedback 1 * more fb * more feedback * test fix * prefer activity.current for request id * last clean up tweaks --------- Co-authored-by: Jesse Squire <[email protected]> Co-authored-by: Christopher Scott <[email protected]>
1 parent 0a253a1 commit d621add

File tree

52 files changed

+5769
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5769
-200
lines changed

eng/Packages.Data.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
104104
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
105105
<PackageReference Update="Microsoft.CSharp" Version="4.7.0" />
106+
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0"/>
106107

107108
<!-- Azure SDK packages -->
108109
<PackageReference Update="Azure.Communication.Identity" Version="1.3.1" />
@@ -345,6 +346,8 @@
345346
<PackageReference Update="Microsoft.Extensions.Configuration" Version="5.0.0" />
346347
<PackageReference Update="Microsoft.Extensions.Hosting" Version="8.0.1" />
347348
<PackageReference Update="Microsoft.Extensions.Logging.Configuration" Version="8.0.0-rc.1.23419.4" />
349+
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
350+
<PackageReference Update="Microsoft.Extensions.Primitives" Version="6.0.1"/>
348351
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="3.1.32" />
349352
<PackageReference Update="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
350353
<PackageReference Update="Microsoft.Graph" Version="5.57.0" />

sdk/core/Azure.Core/src/DiagnosticsOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ internal DiagnosticsOptions(DiagnosticsOptions? diagnosticsOptions)
4141
}
4242
else
4343
{
44+
// These values are similar to the default values in System.ClientModel.Primitives.ClientLoggingOptions and both
45+
// should be kept in sync. When updating, update the default values in both classes.
4446
LoggedHeaderNames = new List<string>()
4547
{
4648
"x-ms-request-id",

sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ public enum ClientErrorBehaviors
8383
Default = 0,
8484
NoThrow = 1,
8585
}
86+
public partial class ClientLoggingOptions
87+
{
88+
public ClientLoggingOptions() { }
89+
public System.Collections.Generic.IList<string> AllowedHeaderNames { get { throw null; } }
90+
public System.Collections.Generic.IList<string> AllowedQueryParameters { get { throw null; } }
91+
public bool? EnableLogging { get { throw null; } set { } }
92+
public bool? EnableMessageContentLogging { get { throw null; } set { } }
93+
public bool? EnableMessageLogging { get { throw null; } set { } }
94+
public Microsoft.Extensions.Logging.ILoggerFactory? LoggerFactory { get { throw null; } set { } }
95+
public int? MessageContentSizeLimit { get { throw null; } set { } }
96+
protected void AssertNotFrozen() { }
97+
public virtual void Freeze() { }
98+
}
8699
public sealed partial class ClientPipeline
87100
{
88101
internal ClientPipeline() { }
@@ -95,6 +108,8 @@ public void Send(System.ClientModel.Primitives.PipelineMessage message) { }
95108
public partial class ClientPipelineOptions
96109
{
97110
public ClientPipelineOptions() { }
111+
public System.ClientModel.Primitives.ClientLoggingOptions? ClientLoggingOptions { get { throw null; } set { } }
112+
public System.ClientModel.Primitives.PipelinePolicy? MessageLoggingPolicy { get { throw null; } set { } }
98113
public System.TimeSpan? NetworkTimeout { get { throw null; } set { } }
99114
public System.ClientModel.Primitives.PipelinePolicy? RetryPolicy { get { throw null; } set { } }
100115
public System.ClientModel.Primitives.PipelineTransport? Transport { get { throw null; } set { } }
@@ -105,6 +120,7 @@ public virtual void Freeze() { }
105120
public partial class ClientRetryPolicy : System.ClientModel.Primitives.PipelinePolicy
106121
{
107122
public ClientRetryPolicy(int maxRetries = 3) { }
123+
public ClientRetryPolicy(int maxRetries, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
108124
public static System.ClientModel.Primitives.ClientRetryPolicy Default { get { throw null; } }
109125
protected virtual System.TimeSpan GetNextDelay(System.ClientModel.Primitives.PipelineMessage message, int tryCount) { throw null; }
110126
protected virtual void OnRequestSent(System.ClientModel.Primitives.PipelineMessage message) { }
@@ -129,6 +145,7 @@ public partial class HttpClientPipelineTransport : System.ClientModel.Primitives
129145
{
130146
public HttpClientPipelineTransport() { }
131147
public HttpClientPipelineTransport(System.Net.Http.HttpClient client) { }
148+
public HttpClientPipelineTransport(System.Net.Http.HttpClient? client, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
132149
public static System.ClientModel.Primitives.HttpClientPipelineTransport Shared { get { throw null; } }
133150
protected override System.ClientModel.Primitives.PipelineMessage CreateMessageCore() { throw null; }
134151
public void Dispose() { }
@@ -158,6 +175,13 @@ public JsonModelConverter(System.ClientModel.Primitives.ModelReaderWriterOptions
158175
public override System.ClientModel.Primitives.IJsonModel<object> Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
159176
public override void Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.IJsonModel<object> value, System.Text.Json.JsonSerializerOptions options) { }
160177
}
178+
public partial class MessageLoggingPolicy : System.ClientModel.Primitives.PipelinePolicy
179+
{
180+
public MessageLoggingPolicy(System.ClientModel.Primitives.ClientLoggingOptions? options = null) { }
181+
public static System.ClientModel.Primitives.MessageLoggingPolicy Default { get { throw null; } }
182+
public sealed override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
183+
public sealed override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
184+
}
161185
public static partial class ModelReaderWriter
162186
{
163187
public static object? Read(System.BinaryData data, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type returnType, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) { throw null; }
@@ -279,6 +303,7 @@ protected PipelineResponseHeaders() { }
279303
public abstract partial class PipelineTransport : System.ClientModel.Primitives.PipelinePolicy
280304
{
281305
protected PipelineTransport() { }
306+
protected PipelineTransport(bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
282307
public System.ClientModel.Primitives.PipelineMessage CreateMessage() { throw null; }
283308
protected abstract System.ClientModel.Primitives.PipelineMessage CreateMessageCore();
284309
public void Process(System.ClientModel.Primitives.PipelineMessage message) { }

sdk/core/System.ClientModel/api/System.ClientModel.net8.0.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ public enum ClientErrorBehaviors
8383
Default = 0,
8484
NoThrow = 1,
8585
}
86+
public partial class ClientLoggingOptions
87+
{
88+
public ClientLoggingOptions() { }
89+
public System.Collections.Generic.IList<string> AllowedHeaderNames { get { throw null; } }
90+
public System.Collections.Generic.IList<string> AllowedQueryParameters { get { throw null; } }
91+
public bool? EnableLogging { get { throw null; } set { } }
92+
public bool? EnableMessageContentLogging { get { throw null; } set { } }
93+
public bool? EnableMessageLogging { get { throw null; } set { } }
94+
public Microsoft.Extensions.Logging.ILoggerFactory? LoggerFactory { get { throw null; } set { } }
95+
public int? MessageContentSizeLimit { get { throw null; } set { } }
96+
protected void AssertNotFrozen() { }
97+
public virtual void Freeze() { }
98+
}
8699
public sealed partial class ClientPipeline
87100
{
88101
internal ClientPipeline() { }
@@ -95,6 +108,8 @@ public void Send(System.ClientModel.Primitives.PipelineMessage message) { }
95108
public partial class ClientPipelineOptions
96109
{
97110
public ClientPipelineOptions() { }
111+
public System.ClientModel.Primitives.ClientLoggingOptions? ClientLoggingOptions { get { throw null; } set { } }
112+
public System.ClientModel.Primitives.PipelinePolicy? MessageLoggingPolicy { get { throw null; } set { } }
98113
public System.TimeSpan? NetworkTimeout { get { throw null; } set { } }
99114
public System.ClientModel.Primitives.PipelinePolicy? RetryPolicy { get { throw null; } set { } }
100115
public System.ClientModel.Primitives.PipelineTransport? Transport { get { throw null; } set { } }
@@ -105,6 +120,7 @@ public virtual void Freeze() { }
105120
public partial class ClientRetryPolicy : System.ClientModel.Primitives.PipelinePolicy
106121
{
107122
public ClientRetryPolicy(int maxRetries = 3) { }
123+
public ClientRetryPolicy(int maxRetries, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
108124
public static System.ClientModel.Primitives.ClientRetryPolicy Default { get { throw null; } }
109125
protected virtual System.TimeSpan GetNextDelay(System.ClientModel.Primitives.PipelineMessage message, int tryCount) { throw null; }
110126
protected virtual void OnRequestSent(System.ClientModel.Primitives.PipelineMessage message) { }
@@ -129,6 +145,7 @@ public partial class HttpClientPipelineTransport : System.ClientModel.Primitives
129145
{
130146
public HttpClientPipelineTransport() { }
131147
public HttpClientPipelineTransport(System.Net.Http.HttpClient client) { }
148+
public HttpClientPipelineTransport(System.Net.Http.HttpClient? client, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
132149
public static System.ClientModel.Primitives.HttpClientPipelineTransport Shared { get { throw null; } }
133150
protected override System.ClientModel.Primitives.PipelineMessage CreateMessageCore() { throw null; }
134151
public void Dispose() { }
@@ -158,6 +175,13 @@ public JsonModelConverter(System.ClientModel.Primitives.ModelReaderWriterOptions
158175
public override System.ClientModel.Primitives.IJsonModel<object> Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
159176
public override void Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.IJsonModel<object> value, System.Text.Json.JsonSerializerOptions options) { }
160177
}
178+
public partial class MessageLoggingPolicy : System.ClientModel.Primitives.PipelinePolicy
179+
{
180+
public MessageLoggingPolicy(System.ClientModel.Primitives.ClientLoggingOptions? options = null) { }
181+
public static System.ClientModel.Primitives.MessageLoggingPolicy Default { get { throw null; } }
182+
public sealed override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
183+
public sealed override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
184+
}
161185
public static partial class ModelReaderWriter
162186
{
163187
public static object? Read(System.BinaryData data, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type returnType, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) { throw null; }
@@ -279,6 +303,7 @@ protected PipelineResponseHeaders() { }
279303
public abstract partial class PipelineTransport : System.ClientModel.Primitives.PipelinePolicy
280304
{
281305
protected PipelineTransport() { }
306+
protected PipelineTransport(bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
282307
public System.ClientModel.Primitives.PipelineMessage CreateMessage() { throw null; }
283308
protected abstract System.ClientModel.Primitives.PipelineMessage CreateMessageCore();
284309
public void Process(System.ClientModel.Primitives.PipelineMessage message) { }

sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ public enum ClientErrorBehaviors
8383
Default = 0,
8484
NoThrow = 1,
8585
}
86+
public partial class ClientLoggingOptions
87+
{
88+
public ClientLoggingOptions() { }
89+
public System.Collections.Generic.IList<string> AllowedHeaderNames { get { throw null; } }
90+
public System.Collections.Generic.IList<string> AllowedQueryParameters { get { throw null; } }
91+
public bool? EnableLogging { get { throw null; } set { } }
92+
public bool? EnableMessageContentLogging { get { throw null; } set { } }
93+
public bool? EnableMessageLogging { get { throw null; } set { } }
94+
public Microsoft.Extensions.Logging.ILoggerFactory? LoggerFactory { get { throw null; } set { } }
95+
public int? MessageContentSizeLimit { get { throw null; } set { } }
96+
protected void AssertNotFrozen() { }
97+
public virtual void Freeze() { }
98+
}
8699
public sealed partial class ClientPipeline
87100
{
88101
internal ClientPipeline() { }
@@ -95,6 +108,8 @@ public void Send(System.ClientModel.Primitives.PipelineMessage message) { }
95108
public partial class ClientPipelineOptions
96109
{
97110
public ClientPipelineOptions() { }
111+
public System.ClientModel.Primitives.ClientLoggingOptions? ClientLoggingOptions { get { throw null; } set { } }
112+
public System.ClientModel.Primitives.PipelinePolicy? MessageLoggingPolicy { get { throw null; } set { } }
98113
public System.TimeSpan? NetworkTimeout { get { throw null; } set { } }
99114
public System.ClientModel.Primitives.PipelinePolicy? RetryPolicy { get { throw null; } set { } }
100115
public System.ClientModel.Primitives.PipelineTransport? Transport { get { throw null; } set { } }
@@ -105,6 +120,7 @@ public virtual void Freeze() { }
105120
public partial class ClientRetryPolicy : System.ClientModel.Primitives.PipelinePolicy
106121
{
107122
public ClientRetryPolicy(int maxRetries = 3) { }
123+
public ClientRetryPolicy(int maxRetries, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
108124
public static System.ClientModel.Primitives.ClientRetryPolicy Default { get { throw null; } }
109125
protected virtual System.TimeSpan GetNextDelay(System.ClientModel.Primitives.PipelineMessage message, int tryCount) { throw null; }
110126
protected virtual void OnRequestSent(System.ClientModel.Primitives.PipelineMessage message) { }
@@ -129,6 +145,7 @@ public partial class HttpClientPipelineTransport : System.ClientModel.Primitives
129145
{
130146
public HttpClientPipelineTransport() { }
131147
public HttpClientPipelineTransport(System.Net.Http.HttpClient client) { }
148+
public HttpClientPipelineTransport(System.Net.Http.HttpClient? client, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
132149
public static System.ClientModel.Primitives.HttpClientPipelineTransport Shared { get { throw null; } }
133150
protected override System.ClientModel.Primitives.PipelineMessage CreateMessageCore() { throw null; }
134151
public void Dispose() { }
@@ -157,6 +174,13 @@ public JsonModelConverter(System.ClientModel.Primitives.ModelReaderWriterOptions
157174
public override System.ClientModel.Primitives.IJsonModel<object> Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
158175
public override void Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.IJsonModel<object> value, System.Text.Json.JsonSerializerOptions options) { }
159176
}
177+
public partial class MessageLoggingPolicy : System.ClientModel.Primitives.PipelinePolicy
178+
{
179+
public MessageLoggingPolicy(System.ClientModel.Primitives.ClientLoggingOptions? options = null) { }
180+
public static System.ClientModel.Primitives.MessageLoggingPolicy Default { get { throw null; } }
181+
public sealed override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
182+
public sealed override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
183+
}
160184
public static partial class ModelReaderWriter
161185
{
162186
public static object? Read(System.BinaryData data, System.Type returnType, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) { throw null; }
@@ -277,6 +301,7 @@ protected PipelineResponseHeaders() { }
277301
public abstract partial class PipelineTransport : System.ClientModel.Primitives.PipelinePolicy
278302
{
279303
protected PipelineTransport() { }
304+
protected PipelineTransport(bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory) { }
280305
public System.ClientModel.Primitives.PipelineMessage CreateMessage() { throw null; }
281306
protected abstract System.ClientModel.Primitives.PipelineMessage CreateMessageCore();
282307
public void Process(System.ClientModel.Primitives.PipelineMessage message) { }

0 commit comments

Comments
 (0)