Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
8d9dd93
initial draft
m-redding Jun 14, 2024
74c77c4
WIP test stubs pt 1
m-redding Jun 18, 2024
4192f6c
WIP test stubs 2
m-redding Jun 19, 2024
7f5c7cf
tweaks
m-redding Jun 20, 2024
edccce7
changes
m-redding Jun 24, 2024
b08f2c5
p1 of adding Event Source
m-redding Jun 26, 2024
291365d
tests p1
m-redding Jun 26, 2024
107abf0
test updates
m-redding Jun 27, 2024
207b215
Tests2
m-redding Jun 28, 2024
3747094
updates
m-redding Jul 17, 2024
c986aed
API
m-redding Jul 17, 2024
d802bc3
try slimming methods and adding retry policy log
m-redding Jul 18, 2024
fc17694
test
m-redding Jul 22, 2024
7253073
conflicts
m-redding Aug 13, 2024
205ef71
refactory + add abstraction
m-redding Aug 13, 2024
1c2f4dc
add tests and update api
m-redding Aug 13, 2024
cb53622
more tests
m-redding Aug 13, 2024
8f98aec
fix functional tests
m-redding Aug 15, 2024
06126f2
static -> instance
m-redding Aug 15, 2024
6f51ac6
updates
m-redding Aug 19, 2024
69ced27
tweaks
m-redding Aug 19, 2024
e445a1b
tweaks
m-redding Aug 19, 2024
dec45fd
fix
m-redding Aug 19, 2024
524edc9
Merge branch 'Azure:main' into loggingpolicy2
m-redding Sep 4, 2024
469aeb7
little refactorings
m-redding Sep 9, 2024
ecf0a26
tweaks
m-redding Sep 11, 2024
373fb99
tweaks
m-redding Sep 11, 2024
441ee3e
WIP feedback
m-redding Sep 13, 2024
49a3bcd
reformat
m-redding Sep 17, 2024
da1b7f8
WIP more feedback
m-redding Sep 17, 2024
86dc327
WIP
m-redding Sep 17, 2024
672390a
Merge branch 'Azure:main' into loggingpolicy2
m-redding Sep 18, 2024
ef183ef
Merge branch 'loggingpolicy2' of https://github.com/m-redding/azure-s…
m-redding Sep 18, 2024
9f93eea
Merge branch 'Azure:main' into loggingpolicy2
m-redding Oct 8, 2024
281aa37
Merge branch 'loggingpolicy2' of https://github.com/m-redding/azure-s…
m-redding Oct 8, 2024
b5d97f0
Merge branch 'Azure:main' into loggingpolicy2
m-redding Oct 22, 2024
4a97e78
WIP - updates
m-redding Oct 23, 2024
2726470
Export API
m-redding Oct 23, 2024
e93cbd9
API
m-redding Oct 23, 2024
9e5f1d3
API tweaks
m-redding Oct 23, 2024
87bafa7
comment
m-redding Oct 23, 2024
009792c
Merge branch 'Azure:main' into loggingpolicy2
m-redding Nov 4, 2024
1fb84da
changes 1
m-redding Nov 5, 2024
d5a9360
changes 2
m-redding Nov 7, 2024
985844f
changes
m-redding Nov 7, 2024
3afbc2e
fixes
m-redding Nov 7, 2024
b5ba8ac
more updates
m-redding Nov 7, 2024
382f0d7
some tests
m-redding Nov 7, 2024
eaebe02
WIP - experiment
m-redding Nov 7, 2024
72c2062
Merge branch 'Azure:main' into loggingpolicy2
m-redding Nov 14, 2024
21bea5e
wip
m-redding Nov 15, 2024
fca37df
Merge branch 'Azure:main' into loggingpolicy2
m-redding Nov 18, 2024
7818432
Merge branch 'loggingpolicy2' of https://github.com/m-redding/azure-s…
m-redding Nov 18, 2024
909cdb8
wip fixes
m-redding Nov 25, 2024
e21486a
Merge branch 'Azure:main' into loggingpolicy2
m-redding Nov 27, 2024
f474c2c
event source / logger tests green
m-redding Dec 2, 2024
8cd0d58
API
m-redding Dec 2, 2024
75c24dc
fb
m-redding Dec 2, 2024
bc0c547
implement request ID
m-redding Dec 2, 2024
80ca39a
adding tests, some fb
m-redding Dec 3, 2024
f35144c
more FB
m-redding Dec 3, 2024
2e92d6f
more fb + more tests
m-redding Dec 3, 2024
7cdeb49
WIP
m-redding Dec 10, 2024
41e3abd
tweaks to logging stream
m-redding Dec 10, 2024
eadd1bb
tests green
m-redding Dec 10, 2024
37975b6
test updates
m-redding Dec 12, 2024
9b2f9a0
more test updates
m-redding Dec 12, 2024
8d307b8
Update sdk/core/System.ClientModel/src/Options/ClientLoggingOptions.cs
m-redding Dec 13, 2024
0ebff9d
fb 1
m-redding Dec 13, 2024
778c70b
fb 2
m-redding Dec 13, 2024
dccb471
fixes
m-redding Dec 14, 2024
57b9166
Merge branch 'Azure:main' into loggingpolicy2
m-redding Dec 14, 2024
bdf8068
initial samples
m-redding Jan 2, 2025
91e2a03
api fix and logging.md
m-redding Jan 3, 2025
18d6ae0
tests
m-redding Jan 6, 2025
fbcbf57
Merge branch 'Azure:main' into loggingpolicy2
m-redding Jan 6, 2025
9f75d15
Merge branch 'Azure:main' into loggingpolicy2
m-redding Jan 22, 2025
d0123df
Merge branch 'Azure:main' into loggingpolicy2
m-redding Jan 25, 2025
2ade2a6
Apply suggestions from code review
m-redding Jan 25, 2025
96a36c8
feedback 1
m-redding Jan 27, 2025
433a018
more fb
m-redding Jan 27, 2025
7dbc599
more feedback
m-redding Jan 29, 2025
9f5b4e6
test fix
m-redding Jan 29, 2025
ccd5775
prefer activity.current for request id
m-redding Jan 30, 2025
0ce5416
last clean up tweaks
m-redding Feb 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP - updates
  • Loading branch information
m-redding committed Oct 23, 2024
commit 4a97e780f2de7d0da75844acda1dff03b8f92604
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@

namespace System.ClientModel.Internal;

internal class LoggingHandler
internal class PipelineLoggingHandler
{
private readonly ILogger _logger;
private readonly PipelineMessageSanitizer _sanitizer;
private readonly ClientModelLogMessages _logMessages;
private readonly ClientModelLogMessages? _logMessages;
private readonly bool _useILogger;

public LoggingHandler(ILogger logger, PipelineMessageSanitizer sanitizer)
public PipelineLoggingHandler(ILogger? logger, PipelineMessageSanitizer sanitizer)
{
_logger = logger;
_logger = logger ?? NullLogger.Instance;
_sanitizer = sanitizer;
_logMessages = new ClientModelLogMessages(logger, _sanitizer);
_useILogger = logger is not NullLogger;
if (_useILogger)
{
_logMessages = new ClientModelLogMessages(_logger, _sanitizer);
}
}

/// <summary>
Expand All @@ -41,7 +44,7 @@ public void LogRequest(PipelineRequest request, string requestId, string? assemb
{
if (_useILogger)
{
_logMessages.Request(requestId, request, assemblyName);
_logMessages?.Request(requestId, request, assemblyName);
}
else
{
Expand All @@ -53,7 +56,7 @@ public void LogRequestContent(string requestId, byte[] content, Encoding? textEn
{
if (_useILogger)
{
_logMessages.RequestContent(requestId, content, textEncoding);
_logMessages?.RequestContent(requestId, content, textEncoding);
}
else
{
Expand All @@ -65,7 +68,7 @@ public void LogResponse(string requestId, PipelineResponse response, double seco
{
if (_useILogger)
{
_logMessages.Response(requestId, response, seconds);
_logMessages?.Response(requestId, response, seconds);
}
else
{
Expand All @@ -77,7 +80,7 @@ public void LogResponseContent(string requestId, byte[] content, Encoding? textE
{
if (_useILogger)
{
_logMessages.ResponseContent(requestId, content, textEncoding);
_logMessages?.ResponseContent(requestId, content, textEncoding);
}
else
{
Expand All @@ -89,7 +92,7 @@ public void LogResponseContentBlock(string requestId, int blockNumber, byte[] co
{
if (_useILogger)
{
_logMessages.ResponseContentBlock(requestId, blockNumber, content, textEncoding);
_logMessages?.ResponseContentBlock(requestId, blockNumber, content, textEncoding);
}
else
{
Expand All @@ -101,7 +104,7 @@ public void LogErrorResponse(string requestId, PipelineResponse response, double
{
if (_useILogger)
{
_logMessages.ErrorResponse(requestId, response, seconds);
_logMessages?.ErrorResponse(requestId, response, seconds);
}
else
{
Expand All @@ -113,7 +116,7 @@ public void LogErrorResponseContent(string requestId, byte[] content, Encoding?
{
if (_useILogger)
{
_logMessages.ErrorResponseContent(requestId, content, textEncoding);
_logMessages?.ErrorResponseContent(requestId, content, textEncoding);
}
else
{
Expand All @@ -125,7 +128,7 @@ public void LogErrorResponseContentBlock(string requestId, int blockNumber, byte
{
if (_useILogger)
{
_logMessages.ErrorResponseContentBlock(requestId, blockNumber, content, textEncoding);
_logMessages?.ErrorResponseContentBlock(requestId, blockNumber, content, textEncoding);
}
else
{
Expand All @@ -137,7 +140,7 @@ public void LogRequestRetrying(string requestId, int retryCount, double seconds)
{
if (_useILogger)
{
_logMessages.RequestRetrying(requestId, retryCount, seconds);
_logMessages?.RequestRetrying(requestId, retryCount, seconds);
}
else
{
Expand All @@ -149,7 +152,7 @@ public void LogResponseDelay(string requestId, double seconds)
{
if (_useILogger)
{
_logMessages.ResponseDelay(requestId, seconds);
_logMessages?.ResponseDelay(requestId, seconds);
}
else
{
Expand All @@ -164,7 +167,7 @@ public void LogExceptionResponse(string requestId, Exception exception)

if (_useILogger && isLoggerEnabled)
{
_logMessages.ExceptionResponse(requestId, exception);
_logMessages?.ExceptionResponse(requestId, exception);
}
else if (isEventSourceEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string SanitizeUrl(string url)
return url;
}

#if NET5_0_OR_GREATER
#if NET6_0_OR_GREATER
int indexOfQuerySeparator = url.IndexOf('?', StringComparison.Ordinal);
#else
int indexOfQuerySeparator = url.IndexOf('?');
Expand Down
69 changes: 69 additions & 0 deletions sdk/core/System.ClientModel/src/Internal/TrackingList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;

namespace System.ClientModel.Internal;

internal class TrackingList<T> : List<T>, IList<T>
{
public TrackingList(IEnumerable<T> collection) : base(collection)
{
}

public bool HasChanged { get; private set; }

public new T this[int index]
{
get => base[index];
set
{
if (!EqualityComparer<T>.Default.Equals(base[index], value))
{
HasChanged = true;
}
base[index] = value;
}
}

public new void Add(T item)
{
base.Add(item);
HasChanged = true;
}

public new void Clear()
{
if (Count > 0)
{
HasChanged = true;
}
base.Clear();
}

public new bool Remove(T item)
{
if (base.Remove(item))
{
HasChanged = true;
return true;
}
return false;
}

public new void RemoveAt(int index)
{
if (index >= 0 && index < Count)
{
HasChanged = true;
}
base.RemoveAt(index);
}

public void AcceptChanges()
{
HasChanged = false;
}
}
2 changes: 0 additions & 2 deletions sdk/core/System.ClientModel/src/Message/PipelineMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ public void SetProperty(Type key, object? value) =>

internal int RetryCount { get; set; }

internal string? LoggingCorrelationId { get; set; }

/// <summary>
/// Gets or sets the value indicating whether the response should be buffered
/// in-memory by the pipeline. Defaults to true.
Expand Down
5 changes: 5 additions & 0 deletions sdk/core/System.ClientModel/src/Message/PipelineRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public BinaryContent? Content
/// </summary>
protected abstract BinaryContent? ContentCore { get; set; }

/// <summary>
/// The client request id to include in log entries.
/// </summary>
internal string? ClientRequestId { get; set; }

/// <inheritdoc/>
public abstract void Dispose();
}
5 changes: 5 additions & 0 deletions sdk/core/System.ClientModel/src/Message/PipelineResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public abstract class PipelineResponse : IDisposable
/// </remarks>
public abstract BinaryData Content { get; }

/// <summary>
/// The client request id to include in log entries.
/// </summary>
internal string? ClientRequestId { get; set; }

/// <summary>
/// Transfer the contents of the response network stream from
/// <see cref="ContentStream"/> to a buffered cache on this
Expand Down
Loading