Skip to content

[WCF] Fix exception when no endpoint action#4026

Open
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-2584
Open

[WCF] Fix exception when no endpoint action#4026
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-2584

Conversation

@martincostello
Copy link
Copy Markdown
Member

Fixes #2584

Changes

Fix ArgumentNullException when an endpoint's operation action is null.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Fix `ArgumentNullException` when an endpoint's operation action is null.

Fixes open-telemetry#2584.
@github-actions github-actions bot added the comp:instrumentation.wcf Things related to OpenTelemetry.Instrumentation.Wcf label Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.09%. Comparing base (da86069) to head (16f5526).
⚠️ Report is 28 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4026      +/-   ##
==========================================
+ Coverage   71.94%   72.09%   +0.14%     
==========================================
  Files         458      448      -10     
  Lines       17872    17823      -49     
==========================================
- Hits        12858    12849       -9     
+ Misses       5014     4974      -40     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Instrumentation.Wcf 79.73% <100.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...y.Instrumentation.Wcf/TelemetryEndpointBehavior.cs 91.89% <100.00%> (+0.46%) ⬆️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add PR number.
@martincostello martincostello marked this pull request as ready for review March 27, 2026 15:56
@martincostello martincostello requested a review from a team as a code owner March 27, 2026 15:56
Copilot AI review requested due to automatic review settings March 27, 2026 15:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a WCF instrumentation crash when an operation’s SOAP Action is missing by preventing TelemetryEndpointBehavior from inserting null keys into its action-to-metadata map (addressing scenarios like WCF Web HTTP help pages).

Changes:

  • Skip operations with null Action when building action mappings for both client and service paths.
  • Add a unit test ensuring ChannelFactory.Open() does not throw when a client operation has null Action.
  • Document the fix in the WCF instrumentation changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/OpenTelemetry.Instrumentation.Wcf.Tests/TelemetryEndpointBehaviorTests.cs Adds coverage for the client-side null Action scenario.
src/OpenTelemetry.Instrumentation.Wcf/TelemetryEndpointBehavior.cs Avoids ArgumentNullException by handling null Action values when building action mappings.
src/OpenTelemetry.Instrumentation.Wcf/CHANGELOG.md Records the bug fix in Unreleased notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +84 to +88
if (clientOperation.Action == null)
{
continue;
}

Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new null-check avoids the exception, but skipping clientOperation.Action == null (and dispatchOperation.Action == null) means actionless operations are never added to actionMappings. The runtime instrumentation normalizes missing/empty SOAP action to string.Empty (see ClientChannelInstrumentation.BeforeSendRequest / TelemetryDispatchMessageInspector.AfterReceiveRequest), so spans for these operations will end up without rpc.service/rpc.method metadata. Consider mapping null actions to string.Empty (with collision handling) instead of continue, so actionless endpoints still get meaningful tags.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martincostello, what do you think about this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if having an empty action was valid or not.

I can change it if it makes sense, but I figured it at least not throwing an exception and ignoring it was better than the current behaviour.

Comment on lines +14 to +35
[Fact]
public void ApplyClientBehaviorToClientRuntime_WithNullActionOperation_DoesNotThrow()
{
// Arrange
var contract = ContractDescription.GetContract(typeof(IServiceContract));
var endpoint = new ServiceEndpoint(contract, new BasicHttpBinding(), new EndpointAddress("http://localhost/dummy"));

endpoint.EndpointBehaviors.Add(new InjectNullActionOperationBehavior());
endpoint.EndpointBehaviors.Add(new TelemetryEndpointBehavior());

var factory = new ChannelFactory<IServiceContract>(endpoint);

try
{
var exception = Record.Exception(factory.Open);
Assert.Null(exception);
}
finally
{
factory.Abort();
}
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test validates the client-side fix, but the reported crash in #2584 occurs in the server-side path (ApplyDispatchBehaviorToEndpoint) when a DispatchOperation.Action is null. Add a .NET Framework-only unit test covering ApplyDispatchBehaviorToEndpoint with a DispatchOperation whose Action is null to ensure the original failure mode stays covered.

Copilot uses AI. Check for mistakes.
@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.wcf Things related to OpenTelemetry.Instrumentation.Wcf keep-open Prevents issues and pull requests being closed as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] WCF tracing instrumentation fails when using WCF Web HTTP Help Pages

3 participants