Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instrumentation.Wcf] Add RecordException #2271

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.IncomingRequestFilte
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.IncomingRequestFilter.set -> void
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.OutgoingRequestFilter.get -> System.Func<System.ServiceModel.Channels.Message!, bool>?
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.OutgoingRequestFilter.set -> void
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.SetSoapMessageVersion.get -> bool
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.SetSoapMessageVersion.set -> void
OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions.SuppressDownstreamInstrumentation.get -> bool
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Instrumentation.Wcf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Add possibility to record exceptions from the client side.
Added a `RecordException` property to specify if exceptions
should be recorded (defaults to `false`).
([#2271](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2271))

* Drop support for .NET 6 as this target is no longer supported and add .NET 8 target.
([#2263](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2263))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,25 @@ public static RequestTelemetryState BeforeSendRequest(Message request, Uri? remo
};
}

public static void AfterRequestCompleted(Message? reply, RequestTelemetryState? state)
public static void AfterRequestCompleted(Message? reply, RequestTelemetryState? state, Exception? exception = null)
{
Guard.ThrowIfNull(state);

state.SuppressionScope?.Dispose();

if (state.Activity is Activity activity)
{
if (activity.IsAllDataRequested)
{
if (reply == null || reply.IsFault)
{
activity.SetStatus(Status.Error);

if (WcfInstrumentationActivitySource.Options!.RecordException)
{
if (exception != null)
{
activity.RecordException(exception);
}
}
}

if (reply != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public void EndSend(IAsyncResult result)
{
this.Inner.EndSend(asyncResult.Inner);
}
catch (Exception)
catch (Exception ex)
{
ClientChannelInstrumentation.AfterRequestCompleted(null, asyncResult.TelemetryState);
ClientChannelInstrumentation.AfterRequestCompleted(null, asyncResult.TelemetryState, ex);
throw;
}
}
Expand Down Expand Up @@ -196,9 +196,9 @@ void ExecuteInChildContext(object? unused)
{
ExecutionContext.Run(executionContext, ExecuteInChildContext, null);
}
catch (Exception)
catch (Exception ex)
{
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState);
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState, ex);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Message IRequestChannel.Request(Message message)
{
reply = this.Inner.Request(message);
}
catch (Exception)
catch (Exception ex)
{
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState);
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState, ex);
throw;
}

Expand All @@ -50,9 +50,9 @@ Message IRequestChannel.Request(Message message, TimeSpan timeout)
{
reply = this.Inner.Request(message, timeout);
}
catch (Exception)
catch (Exception ex)
{
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState);
ClientChannelInstrumentation.AfterRequestCompleted(null, telemetryState, ex);
throw;
}

Expand Down Expand Up @@ -86,9 +86,9 @@ Message IRequestChannel.EndRequest(IAsyncResult result)
{
reply = this.Inner.EndRequest(asyncResult.Inner);
}
catch (Exception)
catch (Exception ex)
{
ClientChannelInstrumentation.AfterRequestCompleted(null, asyncResult.TelemetryState);
ClientChannelInstrumentation.AfterRequestCompleted(null, asyncResult.TelemetryState, ex);
throw;
}

Expand Down
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Instrumentation.Wcf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ on the service contracts you want to instrument:
}
```

### RecordException

This instrumentation automatically sets Activity Status to Error if an unhandled
exception is thrown. Additionally, `RecordException` feature may be turned on,
to store the exception to the Activity itself as ActivityEvent.

## References

* [OpenTelemetry Project](https://opentelemetry.io/)
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@ public class WcfInstrumentationOptions
/// Gets or sets a value indicating whether or not the SOAP message version should be added as the <see cref="WcfInstrumentationConstants.SoapMessageVersionTag"/> tag. Default value: False.
/// </summary>
public bool SetSoapMessageVersion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether exception will be recorded
/// as an <see cref="ActivityEvent"/> or not. Default value: <see
/// langword="false"/>.
/// </summary>
/// <remarks>
/// <para><b>RecordException is supported on all runtimes.</b></para>
/// <para>For specification details see: <see
/// href="https://github.com/open-telemetry/semantic-conventions/blob/main/docs/exceptions/exceptions-spans.md"
/// />.</para>
/// </remarks>
public bool RecordException { get; set; }
}
Loading