open-telemetry / opentelemetry-dotnet-contrib

This repository contains set of components extending functionality of the OpenTelemetry .NET SDK. Instrumentation libraries, exporters, and other components can find their home here.
https://opentelemetry.io
Apache License 2.0
471 stars 279 forks source link

OpenTelemetry.Instrumentation.Wcf supported transport protocols and framework #1242

Open YanlingCui opened 1 year ago

YanlingCui commented 1 year ago

Questions with OpenTelemetry.Instrumentation.Wcf

There is a multi-targeting service that using WCF framework. We want to automatically collect trace data for it. Hopefully, we can achieve this by leveraging OpenTelemetry.Instrumentation.Wcf.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyName>.....Worker</AssemblyName>
    <OutputType>exe</OutputType>
    <TargetFrameworks>net6.0;net472</TargetFrameworks>
.....

Here, I have several questions about the supported features of OpenTelemetry.Instrumentation.Wcf.

  1. Supported transport protocols We know WCF has several built-in transport protocols like HTTP, HTTPS, TCP, named pipes and so on. Can OpenTelemetry.Instrumentation.Wcf collect trace data from all these protocols? If not, which protocols does the library support?

  2. Supported message encoders WCF includes three message encoders: the text message encoder (POX, SOAP), the binary message encoder, MTOM encoder. According to my understanding, instrumentation library collects trace data regardless of message encoders. So, OpenTelemetry.Instrumentation.Wcf can collect trace data of all kinds of encoded message, right?

  3. There is only an example about adding IDispatchMessageInspector instrumentation to a service of .NET Framework. Can OpenTelemetry.Instrumentation.Wcf instrument services of both .NET Framework and .NET Core?

  4. The README shows that using the AddWcfInstrumentation extension method to add WCF instrumentation to an OpenTelemetry TracerProvider:

    using var openTelemetry = Sdk.CreateTracerProviderBuilder()
    .AddWcfInstrumentation()
    .Build();

    I checked the function description, AddWcfInstrumentation enables the outgoing requests automatic data collection for WCF. I wonder only outgoing requests are collected by AddWcfInstrumentation or both incoming and outgoing requests can be collected?

Appreciate if anyone could help. 🌹

CodeBlanch commented 1 year ago

Hey @YanlingCui!

The WCF instrumentation works with .NET Framework & .NET/Core clients. It also works for .NET Framework servers. Some examples in this folder: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/examples/wcf

Previously when this work was done there were no server bits for .NET/Core. There are now server bits available via https://github.com/corewcf/corewcf. I am not sure if this instrumentation works with that. @mconnew do you know?

As far as supported transports and encoding the WCF instrumentation should work with all of that stuff. It plugs into the pipeline and is called once messages are available. It shouldn't matter the transport or the encoding. I have not personally verified anything other than the tests/examples in the repo though.

FYI there seem to be some issues with the current implementation and efforts are underway to change how things work (ex: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1247). Not sure what all will land and how things will be impacted.

YanlingCui commented 1 year ago

Thank you @CodeBlanch for the detailed explaination.

I created a CoreWCF service locally and tried to instrument the service using the library. It requires adding TelemetryDispatchMessageInspector into endpoint behaviors. Unfortunately, TelemetryDispatchMessageInspector only supports NETFRAMEWORK, which means I can't instrument a NET Core WCF service. Is my understanding right?

LynnLi11 commented 11 months ago

Hi @CodeBlanch!

Seems WCF instrumentation could not work with corewcf server, do you have any plan to support this and can I raise a feature ask on it? Since we have many wcf projects would like to onboard distributed tracing and wcf instrumentation is very important to us!

Kielek commented 11 months ago

@LynnLi11, you are right, there is no support for CoreWCF in this package. The best option is to implement support directly in CoreWCF library. There is an issue to track the progress https://github.com/CoreWCF/CoreWCF/issues/790.

LynnLi11 commented 11 months ago

@Kielek Cool, thank you! Looking forward this feature!

LynnLi11 commented 11 months ago

@Kielek, do you have any ideas on how to temporally add traces for CoreWCF while the feature is not ready? Shall we implement a MessageInspector in our service code? Would that work as well?

Kielek commented 11 months ago

I am not an WCF (Core) expert, but is can be a good idea. I suppose it should be implemented in the similar way for WCF (Classic).

LynnLi11 commented 11 months ago

@Kielek Thanks, I'll try it.