Skip to content

Commit

Permalink
[WCF.Intrumentation] Filescoped namespace (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Aug 4, 2022
1 parent 6ee4eba commit 2c57ff0
Show file tree
Hide file tree
Showing 24 changed files with 1,110 additions and 1,125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
// limitations under the License.
// </copyright>

namespace OpenTelemetry.Instrumentation.Wcf
namespace OpenTelemetry.Instrumentation.Wcf;

internal sealed class ActionMetadata
{
internal sealed class ActionMetadata
{
public string ContractName { get; set; }
public string ContractName { get; set; }

public string OperationName { get; set; }
}
public string OperationName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,32 @@
using System.Diagnostics;
using System.ServiceModel.Channels;

namespace OpenTelemetry.Instrumentation.Wcf
namespace OpenTelemetry.Instrumentation.Wcf;

/// <summary>
/// WCF instrumentation.
/// </summary>
internal static class WcfInstrumentationActivitySource
{
/// <summary>
/// WCF instrumentation.
/// </summary>
internal static class WcfInstrumentationActivitySource
{
public const string ActivitySourceName = "OpenTelemetry.WCF";
public const string IncomingRequestActivityName = ActivitySourceName + ".IncomingRequest";
public const string OutgoingRequestActivityName = ActivitySourceName + ".OutgoingRequest";

private static readonly Version Version = typeof(WcfInstrumentationActivitySource).Assembly.GetName().Version;

public static ActivitySource ActivitySource { get; } = new ActivitySource(ActivitySourceName, Version.ToString());

public static Func<Message, string, IEnumerable<string>> MessageHeaderValuesGetter { get; }
= (request, name) =>
{
var headerIndex = request.Headers.FindHeader(name, "https://www.w3.org/TR/trace-context/");
return headerIndex < 0
? null
: new[] { request.Headers.GetHeader<string>(headerIndex) };
};

public static Action<Message, string, string> MessageHeaderValueSetter { get; }
= (request, name, value) => request.Headers.Add(MessageHeader.CreateHeader(name, "https://www.w3.org/TR/trace-context/", value, false));

public static WcfInstrumentationOptions Options { get; set; }
}
public const string ActivitySourceName = "OpenTelemetry.WCF";
public const string IncomingRequestActivityName = ActivitySourceName + ".IncomingRequest";
public const string OutgoingRequestActivityName = ActivitySourceName + ".OutgoingRequest";

private static readonly Version Version = typeof(WcfInstrumentationActivitySource).Assembly.GetName().Version;

public static ActivitySource ActivitySource { get; } = new ActivitySource(ActivitySourceName, Version.ToString());

public static Func<Message, string, IEnumerable<string>> MessageHeaderValuesGetter { get; }
= (request, name) =>
{
var headerIndex = request.Headers.FindHeader(name, "https://www.w3.org/TR/trace-context/");
return headerIndex < 0
? null
: new[] { request.Headers.GetHeader<string>(headerIndex) };
};

public static Action<Message, string, string> MessageHeaderValueSetter { get; }
= (request, name, value) => request.Headers.Add(MessageHeader.CreateHeader(name, "https://www.w3.org/TR/trace-context/", value, false));

public static WcfInstrumentationOptions Options { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
// limitations under the License.
// </copyright>

namespace OpenTelemetry.Instrumentation.Wcf
namespace OpenTelemetry.Instrumentation.Wcf;

internal static class WcfInstrumentationConstants
{
internal static class WcfInstrumentationConstants
{
public const string RpcSystemTag = "rpc.system";
public const string RpcServiceTag = "rpc.service";
public const string RpcMethodTag = "rpc.method";
public const string NetHostNameTag = "net.host.name";
public const string NetHostPortTag = "net.host.port";
public const string NetPeerNameTag = "net.peer.name";
public const string NetPeerPortTag = "net.peer.port";
public const string SoapMessageVersionTag = "soap.message_version";
public const string SoapReplyActionTag = "soap.reply_action";
public const string SoapViaTag = "soap.via";
public const string WcfChannelSchemeTag = "wcf.channel.scheme";
public const string WcfChannelPathTag = "wcf.channel.path";
public const string RpcSystemTag = "rpc.system";
public const string RpcServiceTag = "rpc.service";
public const string RpcMethodTag = "rpc.method";
public const string NetHostNameTag = "net.host.name";
public const string NetHostPortTag = "net.host.port";
public const string NetPeerNameTag = "net.peer.name";
public const string NetPeerPortTag = "net.peer.port";
public const string SoapMessageVersionTag = "soap.message_version";
public const string SoapReplyActionTag = "soap.reply_action";
public const string SoapViaTag = "soap.via";
public const string WcfChannelSchemeTag = "wcf.channel.scheme";
public const string WcfChannelPathTag = "wcf.channel.path";

public const string WcfSystemValue = "wcf";
}
public const string WcfSystemValue = "wcf";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,72 @@
using System.Globalization;
using System.Threading;

namespace OpenTelemetry.Instrumentation.Wcf.Implementation
namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

[EventSource(Name = "OpenTelemetry-Instrumentation-Wcf")]
internal sealed class WcfInstrumentationEventSource : EventSource
{
[EventSource(Name = "OpenTelemetry-Instrumentation-Wcf")]
internal sealed class WcfInstrumentationEventSource : EventSource
{
public static readonly WcfInstrumentationEventSource Log = new WcfInstrumentationEventSource();
public static readonly WcfInstrumentationEventSource Log = new WcfInstrumentationEventSource();

[NonEvent]
public void RequestFilterException(Exception ex)
[NonEvent]
public void RequestFilterException(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.RequestFilterException(ToInvariantString(ex));
}
this.RequestFilterException(ToInvariantString(ex));
}
}

[Event(EventIds.RequestIsFilteredOut, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
public void RequestIsFilteredOut()
{
this.WriteEvent(EventIds.RequestIsFilteredOut);
}
[Event(EventIds.RequestIsFilteredOut, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
public void RequestIsFilteredOut()
{
this.WriteEvent(EventIds.RequestIsFilteredOut);
}

[Event(EventIds.RequestFilterException, Message = "InstrumentationFilter threw exception. Request will not be collected. Exception {0}.", Level = EventLevel.Error)]
public void RequestFilterException(string exception)
{
this.WriteEvent(EventIds.RequestFilterException, exception);
}
[Event(EventIds.RequestFilterException, Message = "InstrumentationFilter threw exception. Request will not be collected. Exception {0}.", Level = EventLevel.Error)]
public void RequestFilterException(string exception)
{
this.WriteEvent(EventIds.RequestFilterException, exception);
}

[NonEvent]
public void EnrichmentException(Exception exception)
[NonEvent]
public void EnrichmentException(Exception exception)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.EnrichmentException(ToInvariantString(exception));
}
this.EnrichmentException(ToInvariantString(exception));
}
}

[Event(EventIds.EnrichmentException, Message = "Enrichment threw exception. Exception {0}.", Level = EventLevel.Error)]
public void EnrichmentException(string exception)
{
this.WriteEvent(EventIds.EnrichmentException, exception);
}
[Event(EventIds.EnrichmentException, Message = "Enrichment threw exception. Exception {0}.", Level = EventLevel.Error)]
public void EnrichmentException(string exception)
{
this.WriteEvent(EventIds.EnrichmentException, exception);
}

/// <summary>
/// Returns a culture-independent string representation of the given <paramref name="exception"/> object,
/// appropriate for diagnostics tracing.
/// </summary>
private static string ToInvariantString(Exception exception)
{
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
/// <summary>
/// Returns a culture-independent string representation of the given <paramref name="exception"/> object,
/// appropriate for diagnostics tracing.
/// </summary>
private static string ToInvariantString(Exception exception)
{
var originalUICulture = Thread.CurrentThread.CurrentUICulture;

try
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
return exception.ToString();
}
finally
{
Thread.CurrentThread.CurrentUICulture = originalUICulture;
}
try
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
return exception.ToString();
}

private class EventIds
finally
{
public const int RequestIsFilteredOut = 1;
public const int RequestFilterException = 2;
public const int EnrichmentException = 3;
Thread.CurrentThread.CurrentUICulture = originalUICulture;
}
}

private class EventIds
{
public const int RequestIsFilteredOut = 1;
public const int RequestFilterException = 2;
public const int EnrichmentException = 3;
}
}
Loading

0 comments on commit 2c57ff0

Please sign in to comment.