forked from Azure/azure-webjobs-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to TraceWriter pipeline (adding TraceEvent, FunctionInvo…
…cationException)
- Loading branch information
Showing
18 changed files
with
352 additions
and
84 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
85 changes: 85 additions & 0 deletions
85
src/Microsoft.Azure.WebJobs.Host/FunctionInvocationException.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,85 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Microsoft.Azure.WebJobs.Host | ||
{ | ||
/// <summary> | ||
/// Exception thrown when a job function invocation fails. | ||
/// </summary> | ||
[Serializable] | ||
public class FunctionInvocationException : Exception | ||
{ | ||
/// <inheritdoc/> | ||
public FunctionInvocationException() : base() | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public FunctionInvocationException(string message) : base(message) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public FunctionInvocationException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new instance. | ||
/// </summary> | ||
/// <param name="info">The <see cref="SerializationInfo"/>.</param> | ||
/// <param name="context">The <see cref="StreamingContext"/>.</param> | ||
protected FunctionInvocationException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
{ | ||
if (info == null) | ||
{ | ||
throw new ArgumentNullException("info"); | ||
} | ||
|
||
InstanceId = Guid.Parse(info.GetString("InstanceId")); | ||
MethodName = info.GetString("MethodName"); | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new instance. | ||
/// </summary> | ||
/// <param name="message">The exception message.</param> | ||
/// <param name="instanceId">The function instance Id.</param> | ||
/// <param name="methodName">The fully qualified method name.</param> | ||
/// <param name="innerException">The exception that is the cause of the current exception (or null).</param> | ||
public FunctionInvocationException(string message, Guid instanceId, string methodName, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
InstanceId = instanceId; | ||
MethodName = methodName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the instance Id of the failed invocation. This value can be correlated | ||
/// to the Dashboard logs. | ||
/// </summary> | ||
public Guid InstanceId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the fully qualified name of the function. | ||
/// </summary> | ||
public string MethodName { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
if (info == null) | ||
{ | ||
throw new ArgumentNullException("info"); | ||
} | ||
|
||
info.AddValue("InstanceId", this.InstanceId); | ||
info.AddValue("MethodName", this.MethodName); | ||
|
||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
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,80 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Microsoft.Azure.WebJobs.Host | ||
{ | ||
/// <summary> | ||
/// Defines a trace event that can be written to a <see cref="TraceWriter"/>. | ||
/// </summary> | ||
public class TraceEvent | ||
{ | ||
private IDictionary<string, object> _properties; | ||
|
||
/// <summary> | ||
/// Constructs a new instance. | ||
/// </summary> | ||
/// <param name="level">The level of the trace.</param> | ||
/// <param name="message">The trace message.</param> | ||
/// <param name="source">The source of the trace (may be null).</param> | ||
/// <param name="exception">The exception that caused the trace (may be null).</param> | ||
public TraceEvent(TraceLevel level, string message, string source = null, Exception exception = null) | ||
{ | ||
Level = level; | ||
Message = message; | ||
Source = source; | ||
Exception = exception; | ||
Timestamp = DateTime.UtcNow; | ||
} | ||
|
||
/// <summary> | ||
/// The time the trace was recorded. | ||
/// </summary> | ||
public DateTime Timestamp { get; set; } | ||
|
||
/// <summary> | ||
/// The level of the trace. | ||
/// </summary> | ||
public TraceLevel Level { get; set; } | ||
|
||
/// <summary> | ||
/// The source of the trace. | ||
/// </summary> | ||
public string Source { get; set; } | ||
|
||
/// <summary> | ||
/// The trace message. | ||
/// </summary> | ||
public string Message { get; set; } | ||
|
||
/// <summary> | ||
/// The exception that caused the trace. | ||
/// </summary> | ||
public Exception Exception { get; set; } | ||
|
||
/// <summary> | ||
/// Gets a set of properties for the <see cref="TraceEvent"/>. | ||
/// </summary> | ||
public IDictionary<string, object> Properties | ||
{ | ||
get | ||
{ | ||
if (_properties == null) | ||
{ | ||
_properties = new Dictionary<string, object>(); | ||
} | ||
return _properties; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4}", Timestamp, Level.ToString(), Message, Source, Exception); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.