-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.0-preview5] Remove dependency from OpenTelemetry.Instrumen…
…tation.StackExchangeRedis (#3198) * Remove dependency from OpenTelemetry.Instrumentation.StackExchangeRedis * Fix test builds * Fix ActivitySourceName * Undo IsAotCompatible change * Update suppression comment to match OTel PR. * Update code sync instruction for AOT --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
- Loading branch information
1 parent
4d3325b
commit 4d551ed
Showing
22 changed files
with
2,033 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...trumentation.SqlClient/Shared/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#nullable disable | ||
|
||
using System.Diagnostics; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Instrumentation; | ||
|
||
internal sealed class DiagnosticSourceListener : IObserver<KeyValuePair<string, object>> | ||
{ | ||
private readonly ListenerHandler handler; | ||
|
||
private readonly Action<string, string, Exception> logUnknownException; | ||
|
||
public DiagnosticSourceListener(ListenerHandler handler, Action<string, string, Exception> logUnknownException) | ||
{ | ||
Guard.ThrowIfNull(handler); | ||
|
||
this.handler = handler; | ||
this.logUnknownException = logUnknownException; | ||
} | ||
|
||
public void OnCompleted() | ||
{ | ||
} | ||
|
||
public void OnError(Exception error) | ||
{ | ||
} | ||
|
||
public void OnNext(KeyValuePair<string, object> value) | ||
{ | ||
if (!this.handler.SupportsNullActivity && Activity.Current == null) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
this.handler.OnEventWritten(value.Key, value.Value); | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.logUnknownException?.Invoke(this.handler?.SourceName, value.Key, ex); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...umentation.SqlClient/Shared/DiagnosticSourceInstrumentation/DiagnosticSourceSubscriber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#nullable disable | ||
|
||
using System.Diagnostics; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Instrumentation; | ||
|
||
internal sealed class DiagnosticSourceSubscriber : IDisposable, IObserver<DiagnosticListener> | ||
{ | ||
private readonly List<IDisposable> listenerSubscriptions; | ||
private readonly Func<string, ListenerHandler> handlerFactory; | ||
private readonly Func<DiagnosticListener, bool> diagnosticSourceFilter; | ||
private readonly Func<string, object, object, bool> isEnabledFilter; | ||
private readonly Action<string, string, Exception> logUnknownException; | ||
private long disposed; | ||
private IDisposable allSourcesSubscription; | ||
|
||
public DiagnosticSourceSubscriber( | ||
ListenerHandler handler, | ||
Func<string, object, object, bool> isEnabledFilter, | ||
Action<string, string, Exception> logUnknownException) | ||
: this(_ => handler, value => handler.SourceName == value.Name, isEnabledFilter, logUnknownException) | ||
{ | ||
} | ||
|
||
public DiagnosticSourceSubscriber( | ||
Func<string, ListenerHandler> handlerFactory, | ||
Func<DiagnosticListener, bool> diagnosticSourceFilter, | ||
Func<string, object, object, bool> isEnabledFilter, | ||
Action<string, string, Exception> logUnknownException) | ||
{ | ||
Guard.ThrowIfNull(handlerFactory); | ||
|
||
this.listenerSubscriptions = new List<IDisposable>(); | ||
this.handlerFactory = handlerFactory; | ||
this.diagnosticSourceFilter = diagnosticSourceFilter; | ||
this.isEnabledFilter = isEnabledFilter; | ||
this.logUnknownException = logUnknownException; | ||
} | ||
|
||
public void Subscribe() | ||
{ | ||
if (this.allSourcesSubscription == null) | ||
{ | ||
this.allSourcesSubscription = DiagnosticListener.AllListeners.Subscribe(this); | ||
} | ||
} | ||
|
||
public void OnNext(DiagnosticListener value) | ||
{ | ||
if ((Interlocked.Read(ref this.disposed) == 0) && | ||
this.diagnosticSourceFilter(value)) | ||
{ | ||
var handler = this.handlerFactory(value.Name); | ||
var listener = new DiagnosticSourceListener(handler, this.logUnknownException); | ||
var subscription = this.isEnabledFilter == null ? | ||
value.Subscribe(listener) : | ||
value.Subscribe(listener, this.isEnabledFilter); | ||
|
||
lock (this.listenerSubscriptions) | ||
{ | ||
this.listenerSubscriptions.Add(subscription); | ||
} | ||
} | ||
} | ||
|
||
public void OnCompleted() | ||
{ | ||
} | ||
|
||
public void OnError(Exception error) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() | ||
{ | ||
this.Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
if (Interlocked.CompareExchange(ref this.disposed, 1, 0) == 1) | ||
{ | ||
return; | ||
} | ||
|
||
lock (this.listenerSubscriptions) | ||
{ | ||
foreach (var listenerSubscription in this.listenerSubscriptions) | ||
{ | ||
listenerSubscription?.Dispose(); | ||
} | ||
|
||
this.listenerSubscriptions.Clear(); | ||
} | ||
|
||
this.allSourcesSubscription?.Dispose(); | ||
this.allSourcesSubscription = null; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...metry.Instrumentation.SqlClient/Shared/DiagnosticSourceInstrumentation/ListenerHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Diagnostics; | ||
|
||
namespace OpenTelemetry.Instrumentation; | ||
|
||
/// <summary> | ||
/// ListenerHandler base class. | ||
/// </summary> | ||
internal abstract class ListenerHandler | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ListenerHandler"/> class. | ||
/// </summary> | ||
/// <param name="sourceName">The name of the <see cref="ListenerHandler"/>.</param> | ||
public ListenerHandler(string sourceName) | ||
{ | ||
this.SourceName = sourceName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the <see cref="ListenerHandler"/>. | ||
/// </summary> | ||
public string SourceName { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the <see cref="ListenerHandler"/> supports NULL <see cref="Activity"/>. | ||
/// </summary> | ||
public virtual bool SupportsNullActivity { get; } | ||
|
||
/// <summary> | ||
/// Method called for an event which does not have 'Start', 'Stop' or 'Exception' as suffix. | ||
/// </summary> | ||
/// <param name="name">Custom name.</param> | ||
/// <param name="payload">An object that represent the value being passed as a payload for the event.</param> | ||
public virtual void OnEventWritten(string name, object payload) | ||
{ | ||
} | ||
} |
Oops, something went wrong.