| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Diagnostics.Tracing; |
| | 6 | |
|
| | 7 | | namespace Azure.Core.Diagnostics |
| | 8 | | { |
| | 9 | | [EventSource(Name = EventSourceName)] |
| | 10 | | internal sealed class AzureCoreEventSource : EventSource |
| | 11 | | { |
| | 12 | | private const string EventSourceName = "Azure-Core"; |
| | 13 | |
|
| | 14 | | private const int BackgroundRefreshFailedEvent = 19; |
| | 15 | | private const int RequestEvent = 1; |
| | 16 | | private const int RequestContentEvent = 2; |
| | 17 | | private const int RequestContentTextEvent = 17; |
| | 18 | | private const int ResponseEvent = 5; |
| | 19 | | private const int ResponseContentEvent = 6; |
| | 20 | | private const int ResponseDelayEvent = 7; |
| | 21 | | private const int ResponseContentTextEvent = 13; |
| | 22 | | private const int ResponseContentBlockEvent = 11; |
| | 23 | | private const int ResponseContentTextBlockEvent = 15; |
| | 24 | | private const int ErrorResponseEvent = 8; |
| | 25 | | private const int ErrorResponseContentEvent = 9; |
| | 26 | | private const int ErrorResponseContentTextEvent = 14; |
| | 27 | | private const int ErrorResponseContentBlockEvent = 12; |
| | 28 | | private const int ErrorResponseContentTextBlockEvent = 16; |
| | 29 | | private const int RequestRetryingEvent = 10; |
| | 30 | | private const int ExceptionResponseEvent = 18; |
| | 31 | |
|
| 4 | 32 | | private AzureCoreEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.Tra |
| | 33 | |
|
| 746 | 34 | | public static AzureCoreEventSource Singleton { get; } = new AzureCoreEventSource(); |
| | 35 | |
|
| | 36 | | [Event(BackgroundRefreshFailedEvent, Level = EventLevel.Informational, Message = "Background token refresh [{0}] |
| | 37 | | public void BackgroundRefreshFailed(string requestId, string exception) |
| | 38 | | { |
| 12 | 39 | | WriteEvent(BackgroundRefreshFailedEvent, requestId, exception); |
| 12 | 40 | | } |
| | 41 | |
|
| | 42 | | [Event(RequestEvent, Level = EventLevel.Informational, Message = "Request [{0}] {1} {2}\r\n{3}client assembly: { |
| | 43 | | public void Request(string requestId, string method, string uri, string headers, string? clientAssembly) |
| | 44 | | { |
| 2132 | 45 | | WriteEvent(RequestEvent, requestId, method, uri, headers, clientAssembly); |
| 2132 | 46 | | } |
| | 47 | |
|
| | 48 | | [Event(RequestContentEvent, Level = EventLevel.Verbose, Message = "Request [{0}] content: {1}")] |
| | 49 | | public void RequestContent(string requestId, byte[] content) |
| | 50 | | { |
| 8 | 51 | | WriteEvent(RequestContentEvent, requestId, content); |
| 8 | 52 | | } |
| | 53 | |
|
| | 54 | | [Event(RequestContentTextEvent, Level = EventLevel.Verbose, Message = "Request [{0}] content: {1}")] |
| | 55 | | public void RequestContentText(string requestId, string content) |
| | 56 | | { |
| 8 | 57 | | WriteEvent(RequestContentTextEvent, requestId, content); |
| 8 | 58 | | } |
| | 59 | |
|
| | 60 | | [Event(ResponseEvent, Level = EventLevel.Informational, Message = "Response [{0}] {1} {2} ({4:00.0}s)\r\n{3}")] |
| | 61 | | public void Response(string requestId, int status, string reasonPhrase, string headers, double seconds) |
| | 62 | | { |
| 1672 | 63 | | WriteEvent(ResponseEvent, requestId, status, reasonPhrase, headers, seconds); |
| 1672 | 64 | | } |
| | 65 | |
|
| | 66 | | [Event(ResponseContentEvent, Level = EventLevel.Verbose, Message = "Response [{0}] content: {1}")] |
| | 67 | | public void ResponseContent(string requestId, byte[] content) |
| | 68 | | { |
| 4 | 69 | | WriteEvent(ResponseContentEvent, requestId, content); |
| 4 | 70 | | } |
| | 71 | |
|
| | 72 | | [Event(ResponseContentBlockEvent, Level = EventLevel.Verbose, Message = "Response [{0}] content block {1}: {2}") |
| | 73 | | public void ResponseContentBlock(string requestId, int blockNumber, byte[] content) |
| | 74 | | { |
| 8 | 75 | | WriteEvent(ResponseContentBlockEvent, requestId, blockNumber, content); |
| 8 | 76 | | } |
| | 77 | |
|
| | 78 | | [Event(ResponseContentTextEvent, Level = EventLevel.Verbose, Message = "Response [{0}] content: {1}")] |
| | 79 | | public void ResponseContentText(string requestId, string content) |
| | 80 | | { |
| 8 | 81 | | WriteEvent(ResponseContentTextEvent, requestId, content); |
| 8 | 82 | | } |
| | 83 | |
|
| | 84 | | [Event(ResponseContentTextBlockEvent, Level = EventLevel.Verbose, Message = "Response [{0}] content block {1}: { |
| | 85 | | public void ResponseContentTextBlock(string requestId, int blockNumber, string content) |
| | 86 | | { |
| 12 | 87 | | WriteEvent(ResponseContentTextBlockEvent, requestId, blockNumber, content); |
| 12 | 88 | | } |
| | 89 | |
|
| | 90 | | [Event(ErrorResponseEvent, Level = EventLevel.Warning, Message = "Error response [{0}] {1} {2} ({4:00.0}s)\r\n{3 |
| | 91 | | public void ErrorResponse(string requestId, int status, string reasonPhrase, string headers, double seconds) |
| | 92 | | { |
| 438 | 93 | | WriteEvent(ErrorResponseEvent, requestId, status, reasonPhrase, headers, seconds); |
| 438 | 94 | | } |
| | 95 | |
|
| | 96 | | [Event(ErrorResponseContentEvent, Level = EventLevel.Informational, Message = "Error response [{0}] content: {1} |
| | 97 | | public void ErrorResponseContent(string requestId, byte[] content) |
| | 98 | | { |
| 4 | 99 | | WriteEvent(ErrorResponseContentEvent, requestId, content); |
| 4 | 100 | | } |
| | 101 | |
|
| | 102 | | [Event(ErrorResponseContentBlockEvent, Level = EventLevel.Informational, Message = "Error response [{0}] content |
| | 103 | | public void ErrorResponseContentBlock(string requestId, int blockNumber, byte[] content) |
| | 104 | | { |
| 8 | 105 | | WriteEvent(ErrorResponseContentBlockEvent, requestId, blockNumber, content); |
| 8 | 106 | | } |
| | 107 | |
|
| | 108 | | [Event(ErrorResponseContentTextEvent, Level = EventLevel.Informational, Message = "Error response [{0}] content: |
| | 109 | | public void ErrorResponseContentText(string requestId, string content) |
| | 110 | | { |
| 4 | 111 | | WriteEvent(ErrorResponseContentTextEvent, requestId, content); |
| 4 | 112 | | } |
| | 113 | |
|
| | 114 | | [Event(ErrorResponseContentTextBlockEvent, Level = EventLevel.Informational, Message = "Error response [{0}] con |
| | 115 | | public void ErrorResponseContentTextBlock(string requestId, int blockNumber, string content) |
| | 116 | | { |
| 8 | 117 | | WriteEvent(ErrorResponseContentTextBlockEvent, requestId, blockNumber, content); |
| 8 | 118 | | } |
| | 119 | |
|
| | 120 | | [Event(RequestRetryingEvent, Level = EventLevel.Informational, Message = "Request [{0}] retry number {1} took {2 |
| | 121 | | public void RequestRetrying(string requestId, int retryNumber, double seconds) |
| | 122 | | { |
| 640 | 123 | | WriteEvent(RequestRetryingEvent, requestId, retryNumber, seconds); |
| 640 | 124 | | } |
| | 125 | |
|
| | 126 | | [Event(ResponseDelayEvent, Level = EventLevel.Warning, Message = "Response [{0}] took {1:00.0}s")] |
| | 127 | | public void ResponseDelay(string requestId, double seconds) |
| | 128 | | { |
| 0 | 129 | | WriteEvent(ResponseDelayEvent, requestId, seconds); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | [Event(ExceptionResponseEvent, Level = EventLevel.Informational, Message = "Request [{0}] exception {1}")] |
| | 133 | | public void ExceptionResponse(string requestId, string exception) |
| | 134 | | { |
| 20 | 135 | | WriteEvent(ExceptionResponseEvent, requestId, exception); |
| 20 | 136 | | } |
| | 137 | | } |
| | 138 | | } |