open-telemetry / opentelemetry-dotnet-instrumentation

OpenTelemetry .NET Automatic Instrumentation

Home Page:https://opentelemetry.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Windows Forms Instrumentation

JBodkin-Amphora opened this issue · comments

Feature Request

I'm trying to experiment capturing traces from a Windows Form application however I'm encountering an error when clicking a button. The details section on the unhandled exception dialog doesn't expand, so I'm not sure how to progress to resolve the issue.

I've created a class to implement the OnMethodEnd function (and registered the integration name), as follows:

[InstrumentMethod(
    assemblyName: "System.Windows.Forms",
    typeName: "System.Windows.Forms.Button",
    methodName: "OnClick",
    returnTypeName: ClrNames.Void,
    parameterTypeNames: new string[] { "System.EventArgs" },
    minimumVersion: "4.0.0",
    maximumVersion: "4.65535.65535",
    integrationName: "WinForms",
    type: InstrumentationType.Trace)]
internal class ButtonIntegration
{
    internal static CallTargetReturn OnMethodEnd<TTarget>(TTarget instance, Exception exception, in CallTargetState state)
    {
         return CallTargetReturn.GetDefault();
    }
}

When I click the button, I'm getting the following unhandled error:

image

The implementation of the button shows a message box:

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Body", "Title");
}

Do you have any ideas?

The first thing that cross my mind is that the assemblies needed to instrument a .NET Framework may not be registered on the GAC. However, that is a very wild guess. Could you provide a short repro? Debug logs would also be helpful, see here.

Please see this commit for a small application that can be used to reproduce the issue.

These are the log files:
otel-dotnet-auto-native-Example-2552.log
otel-dotnet-auto-Example.exe-2552-20230928.log
otel-dotnet-auto-Example.exe-2552-Loader-20230928.log

From further debugging, the issue seems to be when this method is called OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(2 argument{s}). It looks like it isn't able to call the method which throws an Exception and then the Exception method cannot be called either.

From further debugging, I've found that when it tries to invoke the OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(2 argument{s}) method, it is throwing a MethodAccessException, is there a layer of security that needs to be disabled?

The problem was that the ButtonIntegration class wasn't public, after fixing that, its working

@JBodkin-Amphora, great to hear that you were able to handle the issue.
Could you please share your use case for winforms instrumentation? Based on this, we can consider if it generic enough to include it to this repository.

Our company provides a software as a service (SaaS) solution and we would like to be able to delve deeper into our applications to better understand the chain of events that occur when moving through the system.

The frontend is built on a mixture of different components from Windows Forms, Windows Presentation Foundation and DevExpress. The backend is built on Java (where my expertise lies), which also supports OpenTelemetry, which allows us to see distributed traces.

I would like to be able to capture traces when the end user initiates an action on the user interface (e.g. clicks a button) and to be able to see all the related traces that occur, for example: rending additional components, accessing APIs or querying the database.

SIG meeting: closing as we do not expect it become our standard instrumentation. Still a lot of tasks related to RUM to be defined in specification.

Please rise new issue/reopen if you need any help.