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 14 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 @@ -8,6 +8,11 @@
* Updated OpenTelemetry core component version(s) to `1.10.0`.
([#2317](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2317))

* Add possibility to record exceptions from the client side.
ysolomchenko marked this conversation as resolved.
Show resolved Hide resolved
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))

## 1.0.0-rc.18

Released 2024-Oct-28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ 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)
Expand All @@ -97,6 +95,11 @@ public static void AfterRequestCompleted(Message? reply, RequestTelemetryState?
#pragma warning disable CS0618 // Type or member is obsolete
activity.SetStatus(Status.Error);
#pragma warning restore CS0618 // Type or member is obsolete

if (WcfInstrumentationActivitySource.Options!.RecordException && exception != null)
{
activity.AddException(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
11 changes: 11 additions & 0 deletions src/OpenTelemetry.Instrumentation.Wcf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ on the service contracts you want to instrument:
}
```

## Advanced configuration

This instrumentation can be configured to change the default behavior by using
`WcfInstrumentationOptions`.

### RecordException
ysolomchenko marked this conversation as resolved.
Show resolved Hide resolved

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,16 @@ 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>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