Enable unique EventSource for each project (#879)
* Enable unique EventSource for each project * updating using place from Hosting project * InstrumentationEventSource is now internal, adding EventSource to Hosting project * removing unused methods, updating messages
This commit is contained in:
parent
1ed4a28927
commit
a2b1b45c94
|
|
@ -0,0 +1,81 @@
|
|||
// <copyright file="PrometheusExporterEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Exporter.Prometheus.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Exporter-Prometheus")]
|
||||
internal class PrometheusExporterEventSource : EventSource
|
||||
{
|
||||
public static PrometheusExporterEventSource Log = new PrometheusExporterEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void FailedExport(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedExport(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void CanceledExport(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.CanceledExport(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Failed to export activities: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedExport(string exception)
|
||||
{
|
||||
this.WriteEvent(1, exception);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Canceled to export activities: '{0}'", Level = EventLevel.Error)]
|
||||
private void CanceledExport(string exception)
|
||||
{
|
||||
this.WriteEvent(2, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -117,13 +117,13 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
this.exporter.WriteMetricsCollection(writer);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
// this will happen when cancellation will be requested
|
||||
PrometheusExporterEventSource.Log.CanceledExport(ex);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: report error
|
||||
PrometheusExporterEventSource.Log.FailedExport(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
// <copyright file="ZPagesExporterEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Exporter.Prometheus.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Exporter-ZPages")]
|
||||
internal class ZPagesExporterEventSource : EventSource
|
||||
{
|
||||
public static ZPagesExporterEventSource Log = new ZPagesExporterEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void FailedExport(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedExport(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void CanceledExport(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.CanceledExport(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void FailedProcess(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedProcess(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Failed to export activities: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedExport(string exception)
|
||||
{
|
||||
this.WriteEvent(1, exception);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Canceled to export activities: '{0}'", Level = EventLevel.Error)]
|
||||
private void CanceledExport(string exception)
|
||||
{
|
||||
this.WriteEvent(2, exception);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Failed to process activity: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedProcess(string exception)
|
||||
{
|
||||
this.WriteEvent(3, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ using System.IO;
|
|||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Exporter.Prometheus.Implementation;
|
||||
using OpenTelemetry.Exporter.ZPages.Implementation;
|
||||
#if NET452
|
||||
using OpenTelemetry.Internal;
|
||||
|
|
@ -178,13 +179,13 @@ namespace OpenTelemetry.Exporter.ZPages
|
|||
writer.WriteLine("</div></div></body></html>");
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
// this will happen when cancellation will be requested
|
||||
ZPagesExporterEventSource.Log.CanceledExport(ex);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: report error
|
||||
ZPagesExporterEventSource.Log.FailedExport(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Exporter.Prometheus.Implementation;
|
||||
using OpenTelemetry.Exporter.ZPages.Implementation;
|
||||
#if NET452
|
||||
using OpenTelemetry.Internal;
|
||||
|
|
@ -115,10 +116,10 @@ namespace OpenTelemetry.Exporter.ZPages
|
|||
minuteSpanInformation.LastUpdated = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();
|
||||
hourSpanInformation.LastUpdated = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log.SpanProcessorException("OnEnd", ex);
|
||||
Console.Write("OnEnd", exception);
|
||||
ZPagesExporterEventSource.Log.FailedProcess(ex);
|
||||
Console.Write("OnEnd", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
// <copyright file="HostingExtensionsEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Extensions.Hosting.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Extensions-Hosting")]
|
||||
internal class HostingExtensionsEventSource : EventSource
|
||||
{
|
||||
public static HostingExtensionsEventSource Log = new HostingExtensionsEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void FailedInitialize(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedInitialize(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void FailedOpenTelemetrySDK(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedOpenTelemetrySDK(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Failed to initialize: '{0}'. OpenTelemetry will not work.", Level = EventLevel.Error)]
|
||||
private void FailedInitialize(string exception)
|
||||
{
|
||||
this.WriteEvent(1, exception);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Failed to get OpenTelemetrySDK: '{0}'. OpenTelemetry will not work.", Level = EventLevel.Error)]
|
||||
private void FailedOpenTelemetrySDK(string exception)
|
||||
{
|
||||
this.WriteEvent(2, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
namespace OpenTelemetry.Extensions.Hosting.Implementation
|
||||
{
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -23,6 +21,8 @@ namespace OpenTelemetry.Extensions.Hosting.Implementation
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
|
||||
namespace OpenTelemetry.Extensions.Hosting.Implementation
|
||||
{
|
||||
internal class TelemetryHostedService : IHostedService
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
|
@ -33,6 +33,8 @@ namespace OpenTelemetry.Extensions.Hosting.Implementation
|
|||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// The sole purpose of this HostedService is to ensure
|
||||
// all instrumentations are created and started.
|
||||
|
|
@ -40,6 +42,11 @@ namespace OpenTelemetry.Extensions.Hosting.Implementation
|
|||
// by requesting the OpenTelemetrySdk from DI
|
||||
// it ensures all instrumentations gets started.
|
||||
this.serviceProvider.GetRequiredService<OpenTelemetrySdk>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostingExtensionsEventSource.Log.FailedOpenTelemetrySDK(ex);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry.Extensions.Hosting.Implementation;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for setting up OpenTelemetry services in an <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
|
|
@ -80,8 +80,15 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
throw new ArgumentNullException(nameof(createSdk));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
services.AddSingleton(s => createSdk());
|
||||
AddOpenTelemetryInternal(services);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostingExtensionsEventSource.Log.FailedInitialize(ex);
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
|
@ -104,8 +111,15 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
throw new ArgumentNullException(nameof(createSdk));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
services.AddSingleton(s => createSdk(s));
|
||||
AddOpenTelemetryInternal(services);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostingExtensionsEventSource.Log.FailedInitialize(ex);
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
// <copyright file="AspNetInstrumentationEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-AspNet")]
|
||||
internal class AspNetInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static AspNetInstrumentationEventSource Log = new AspNetInstrumentationEventSource();
|
||||
|
||||
[Event(1, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(1, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
|
||||
public void RequestIsFilteredOut(string eventName)
|
||||
{
|
||||
this.WriteEvent(2, eventName);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,13 +45,13 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
|||
var context = HttpContext.Current;
|
||||
if (context == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity));
|
||||
AspNetInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.options.RequestFilter != null && !this.options.RequestFilter(context))
|
||||
{
|
||||
InstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
|
||||
AspNetInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
|
||||
activity.IsAllDataRequested = false;
|
||||
return;
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
|||
var context = HttpContext.Current;
|
||||
if (context == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity));
|
||||
AspNetInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
// <copyright file="AspNetCoreInstrumentationEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-AspNetCore")]
|
||||
internal class AspNetCoreInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static AspNetCoreInstrumentationEventSource Log = new AspNetCoreInstrumentationEventSource();
|
||||
|
||||
[Event(1, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(1, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
|
||||
public void RequestIsFilteredOut(string eventName)
|
||||
{
|
||||
this.WriteEvent(2, eventName);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,13 +54,13 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
|
||||
if (context == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.options.RequestFilter != null && !this.options.RequestFilter(context))
|
||||
{
|
||||
InstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
|
||||
AspNetCoreInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
|
||||
activity.IsAllDataRequested = false;
|
||||
return;
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
|||
{
|
||||
if (!(this.stopContextFetcher.Fetch(payload) is HttpContext context))
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity));
|
||||
AspNetCoreInstrumentationEventSource.Log.NullPayload(nameof(HttpInListener), nameof(this.OnStopActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,114 @@
|
|||
// <copyright file="DependenciesInstrumentationEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-Dependencies")]
|
||||
internal class DependenciesInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static DependenciesInstrumentationEventSource Log = new DependenciesInstrumentationEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void UnknownErrorProcessingEvent(string handlerName, string eventName, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.UnknownErrorProcessingEvent(handlerName, eventName, ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void FailedProcessResult(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedProcessResult(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void ExceptionInitializingInstrumentation(string instrumentationType, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.ExceptionInitializingInstrumentation(instrumentationType, ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[Event(4, Message = "Current Activity is NULL the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullActivity(string eventName)
|
||||
{
|
||||
this.WriteEvent(4, eventName);
|
||||
}
|
||||
|
||||
[Event(5, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(5, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(6, Message = "Payload is invalid in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void InvalidPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(6, handlerName, eventName);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Unknown error processing event '{1}' from handler '{0}', Exception: {2}", Level = EventLevel.Error)]
|
||||
private void UnknownErrorProcessingEvent(string handlerName, string eventName, string ex)
|
||||
{
|
||||
this.WriteEvent(1, handlerName, eventName, ex);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Failed to process result: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedProcessResult(string ex)
|
||||
{
|
||||
this.WriteEvent(2, ex);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Error initializing instrumentation type {0}. Exception : {1}", Level = EventLevel.Error)]
|
||||
private void ExceptionInitializingInstrumentation(string instrumentationType, string ex)
|
||||
{
|
||||
this.WriteEvent(3, instrumentationType, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.startRequestFetcher.Fetch(payload) is HttpRequestMessage request))
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(GrpcClientDiagnosticListener), nameof(this.OnStartActivity));
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(GrpcClientDiagnosticListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.startRequestFetcher.Fetch(payload) is HttpRequestMessage request))
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.stopExceptionFetcher.Fetch(payload) is Exception exc))
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
|
@ -88,7 +87,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
catch (Exception ex)
|
||||
{
|
||||
// If anything went wrong, just no-op. Write an event so at least we can find out.
|
||||
InstrumentationEventSource.Log.ExceptionInitializingInstrumentation(typeof(HttpWebRequestActivitySource).FullName, ex);
|
||||
DependenciesInstrumentationEventSource.Log.ExceptionInitializingInstrumentation(typeof(HttpWebRequestActivitySource).FullName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,8 +327,9 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.FailedProcessResult(ex);
|
||||
}
|
||||
|
||||
activity.Stop();
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
var command = this.commandFetcher.Fetch(payload);
|
||||
if (command == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
activity.Stop();
|
||||
return;
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (activity == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullActivity(name);
|
||||
DependenciesInstrumentationEventSource.Log.NullActivity(name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (activity == null)
|
||||
{
|
||||
InstrumentationEventSource.Log.NullActivity(name);
|
||||
DependenciesInstrumentationEventSource.Log.NullActivity(name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
else
|
||||
{
|
||||
InstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
InstrumentationEventSource.Log.UnknownErrorProcessingEvent(nameof(SqlEventSourceListener), nameof(this.OnEventWritten), exc);
|
||||
DependenciesInstrumentationEventSource.Log.UnknownErrorProcessingEvent(nameof(SqlEventSourceListener), nameof(this.OnEventWritten), exc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
|
||||
if ((eventData?.Payload?.Count ?? 0) < 4)
|
||||
{
|
||||
InstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnBeginExecute));
|
||||
DependenciesInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnBeginExecute));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
|
||||
if ((eventData?.Payload?.Count ?? 0) < 3)
|
||||
{
|
||||
InstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnEndExecute));
|
||||
DependenciesInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnEndExecute));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,76 +25,29 @@ namespace OpenTelemetry.Instrumentation
|
|||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation")]
|
||||
public class InstrumentationEventSource : EventSource
|
||||
internal class InstrumentationEventSource : EventSource
|
||||
{
|
||||
public static InstrumentationEventSource Log = new InstrumentationEventSource();
|
||||
|
||||
[Event(1, Message = "Span is NULL or blank in the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullOrBlankSpan(string eventName)
|
||||
{
|
||||
this.WriteEvent(1, eventName);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Error getting custom sampler, the default sampler will be used. Exception : {0}", Level = EventLevel.Warning)]
|
||||
public void ExceptionInCustomSampler(string ex)
|
||||
{
|
||||
this.WriteEvent(2, ex);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Current Activity is NULL the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
[Event(1, Message = "Current Activity is NULL the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullActivity(string eventName)
|
||||
{
|
||||
this.WriteEvent(3, eventName);
|
||||
this.WriteEvent(1, eventName);
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void UnknownErrorProcessingEvent(string handlerName, string eventName, Exception ex)
|
||||
{
|
||||
if (!this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.UnknownErrorProcessingEvent(handlerName, eventName, ToInvariantString(ex));
|
||||
}
|
||||
|
||||
[Event(4, Message = "Unknown error processing event '{1}' from handler '{0}', Exception: {2}", Level = EventLevel.Error)]
|
||||
public void UnknownErrorProcessingEvent(string handlerName, string eventName, string ex)
|
||||
{
|
||||
this.WriteEvent(4, handlerName, eventName, ex);
|
||||
}
|
||||
|
||||
[Event(5, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(5, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(6, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
|
||||
public void RequestIsFilteredOut(string eventName)
|
||||
{
|
||||
this.WriteEvent(6, eventName);
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void ExceptionInitializingInstrumentation(string instrumentationType, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.ExceptionInitializingInstrumentation(instrumentationType, ToInvariantString(ex));
|
||||
this.UnknownErrorProcessingEvent(handlerName, eventName, ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[Event(7, Message = "Error initializing instrumentation type {0}. Exception : {1}", Level = EventLevel.Error)]
|
||||
public void ExceptionInitializingInstrumentation(string instrumentationType, string ex)
|
||||
[Event(2, Message = "Unknown error processing event '{1}' from handler '{0}', Exception: {2}", Level = EventLevel.Error)]
|
||||
public void UnknownErrorProcessingEvent(string handlerName, string eventName, string ex)
|
||||
{
|
||||
this.WriteEvent(7, instrumentationType, ex);
|
||||
}
|
||||
|
||||
[Event(8, Message = "Payload is invalid in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void InvalidPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(8, handlerName, eventName);
|
||||
this.WriteEvent(2, handlerName, eventName, ex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue