Skip to content

Commit

Permalink
Minimize telemetry surface area (#2844)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid authored and bachuv committed Jul 9, 2024
1 parent 0647368 commit 6dc67b9
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ bool IDurableEntityContext.HasState
public void CaptureInternalError(Exception e, TaskEntityShim shim)
{
// first, try to get a quick ETW message out to help us diagnose what happened
string details = Utils.IsFatal(e) ? e.GetType().Name : e.ToString();
this.Config.TraceHelper.EntityBatchFailed(
this.HubName,
this.Name,
this.InstanceId,
shim.TraceFlags,
details);
e);

// then, record the error for additional reporting and tracking in other places
this.InternalError = ExceptionDispatchInfo.Capture(e);
Expand Down Expand Up @@ -180,22 +179,27 @@ public void ThrowApplicationExceptionsIfAny()
}
}

public bool ErrorsPresent(out string description)
public bool ErrorsPresent(out string error, out string sanitizedError)
{
if (this.InternalError != null)
{
description = $"Internal error: {this.InternalError.SourceException}";
error = $"Internal error: {this.InternalError.SourceException}";
sanitizedError = $"Internal error: {this.InternalError.SourceException.GetType().FullName} \n {this.InternalError.SourceException.StackTrace}";
return true;
}
else if (this.ApplicationErrors != null)
{
var messages = this.ApplicationErrors.Select(i => $"({i.SourceException.Message})");
description = $"One or more operations failed: {string.Concat(messages)}";
error = $"One or more operations failed: {string.Concat(messages)}";

string errorTypes = string.Join(", ", this.ApplicationErrors.Select(i => i.SourceException.GetType().FullName));
sanitizedError = $"One or more operations failed: {errorTypes}";
return true;
}
else
{
description = string.Empty;
error = string.Empty;
sanitizedError = string.Empty;
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ internal async Task<TResult> CallDurableTaskFunctionAsync<TResult>(
operationId,
operationName,
input: "(replayed)",
exception: "(replayed)",
exception: exception,
duration: 0,
isReplay: true);
}
Expand All @@ -791,7 +791,7 @@ internal async Task<TResult> CallDurableTaskFunctionAsync<TResult>(
this.Config.Options.HubName,
functionName,
this.InstanceId,
reason: $"(replayed {exception.GetType().Name})",
exception: exception,
functionType: functionType,
isReplay: true);
}
Expand Down Expand Up @@ -933,7 +933,7 @@ internal void RaiseEvent(string name, string input)
FunctionType.Orchestrator,
this.InstanceId,
name,
this.Config.GetIntputOutputTrace(responseMessage.Result),
responseMessage.Result,
this.IsReplaying);
}
else
Expand All @@ -943,7 +943,7 @@ internal void RaiseEvent(string name, string input)
this.Name,
this.InstanceId,
name,
this.Config.GetIntputOutputTrace(input),
input,
this.IsReplaying);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,11 @@ internal OrchestratorExecutionResult GetResult()
return this.executionResult ?? throw new InvalidOperationException($"The execution result has not yet been set using {nameof(this.SetResult)}.");
}

internal bool TryGetOrchestrationErrorDetails(out string details)
internal bool TryGetOrchestrationErrorDetails(out Exception? failure)
{
if (this.failure != null)
{
details = this.failure.Message;
return true;
}
else
{
details = string.Empty;
return false;
}
bool hasError = this.failure != null;
failure = hasError ? this.failure : null;
return hasError;
}

internal void SetResult(IEnumerable<OrchestratorAction> actions, string customStatus)
Expand Down
38 changes: 5 additions & 33 deletions src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public DurableTaskExtension(

ILogger logger = loggerFactory.CreateLogger(LoggerCategoryName);

this.TraceHelper = new EndToEndTraceHelper(logger, this.Options.Tracing.TraceReplayEvents);
this.TraceHelper = new EndToEndTraceHelper(logger, this.Options.Tracing.TraceReplayEvents, this.Options.Tracing.TraceInputsAndOutputs);
this.LifeCycleNotificationHelper = lifeCycleNotificationHelper ?? this.CreateLifeCycleNotificationHelper();
this.durabilityProviderFactory = GetDurabilityProviderFactory(this.Options, logger, orchestrationServiceFactories);
this.defaultDurabilityProvider = this.durabilityProviderFactory.GetDurabilityProvider();
Expand Down Expand Up @@ -1038,7 +1038,7 @@ private async Task EntityMiddleware(DispatchMiddlewareContext dispatchContext, F
entityContext.HubName,
entityContext.Name,
entityContext.InstanceId,
this.GetIntputOutputTrace(runtimeState.Input),
runtimeState.Input,
FunctionType.Entity,
isReplay: false);
Expand All @@ -1064,13 +1064,14 @@ private async Task EntityMiddleware(DispatchMiddlewareContext dispatchContext, F
await next();
// 5. If there were internal or application errors, trace them for DF
if (entityContext.ErrorsPresent(out var description))
if (entityContext.ErrorsPresent(out string description, out string sanitizedError))
{
this.TraceHelper.FunctionFailed(
entityContext.HubName,
entityContext.Name,
entityContext.InstanceId,
description,
sanitizedReason: sanitizedError,
functionType: FunctionType.Entity,
isReplay: false);
}
Expand All @@ -1080,7 +1081,7 @@ private async Task EntityMiddleware(DispatchMiddlewareContext dispatchContext, F
entityContext.HubName,
entityContext.Name,
entityContext.InstanceId,
this.GetIntputOutputTrace(entityContext.State.EntityState),
entityContext.State.EntityState,
continuedAsNew: true,
functionType: FunctionType.Entity,
isReplay: false);
Expand Down Expand Up @@ -1487,35 +1488,6 @@ bool HasActiveListeners(RegisteredFunctionInfo info)
return false;
}

internal string GetIntputOutputTrace(string rawInputOutputData)
{
if (this.Options.Tracing.TraceInputsAndOutputs)
{
return rawInputOutputData;
}
else if (rawInputOutputData == null)
{
return "(null)";
}
else
{
// Azure Storage uses UTF-32 encoding for string payloads
return "(" + Encoding.UTF32.GetByteCount(rawInputOutputData) + " bytes)";
}
}

internal string GetExceptionTrace(string rawExceptionData)
{
if (rawExceptionData == null)
{
return "(null)";
}
else
{
return rawExceptionData;
}
}

/// <inheritdoc/>
Task<HttpResponseMessage> IAsyncConverter<HttpRequestMessage, HttpResponseMessage>.ConvertAsync(
HttpRequestMessage request,
Expand Down
Loading

0 comments on commit 6dc67b9

Please sign in to comment.