-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StackOverflowException if tracer needs ILoggerFactory (resolves #14)
- Loading branch information
Showing
7 changed files
with
99 additions
and
2 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
12 changes: 12 additions & 0 deletions
12
src/OpenTracing.Contrib.NetCore/Internal/GlobalTracerAccessor.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,12 @@ | ||
using OpenTracing.Util; | ||
|
||
namespace OpenTracing.Contrib.NetCore.Internal | ||
{ | ||
public class GlobalTracerAccessor : IGlobalTracerAccessor | ||
{ | ||
public ITracer GetGlobalTracer() | ||
{ | ||
return GlobalTracer.Instance; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/OpenTracing.Contrib.NetCore/Internal/IGlobalTracerAccessor.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,10 @@ | ||
namespace OpenTracing.Contrib.NetCore.Internal | ||
{ | ||
/// <summary> | ||
/// Helper interface which allows unit tests to mock the <see cref="OpenTracing.Util.GlobalTracer"/>. | ||
/// </summary> | ||
public interface IGlobalTracerAccessor | ||
{ | ||
ITracer GetGlobalTracer(); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
test/OpenTracing.Contrib.NetCore.Tests/Logging/LoggingDependencyInjectionTest.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,55 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using OpenTracing.Propagation; | ||
using Xunit; | ||
|
||
namespace OpenTracing.Contrib.Netcore.Tests.Logging | ||
{ | ||
public class LoggingDependencyInjectionTest | ||
{ | ||
[Fact] | ||
public void Resolving_tracer_that_needs_ILoggerFactory_succeeds() | ||
{ | ||
// https://github.com/opentracing-contrib/csharp-netcore/issues/14 | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddLogging() | ||
.AddOpenTracingCoreServices(ot => | ||
{ | ||
ot.AddLoggerProvider(); | ||
ot.Services.AddSingleton<ITracer, TracerWithLoggerFactory>(); | ||
}) | ||
.BuildServiceProvider(); | ||
|
||
var tracer = serviceProvider.GetRequiredService<ITracer>(); | ||
Assert.IsType<TracerWithLoggerFactory>(tracer); | ||
} | ||
|
||
private class TracerWithLoggerFactory : ITracer | ||
{ | ||
public TracerWithLoggerFactory(ILoggerFactory loggerFactory) | ||
{ | ||
} | ||
|
||
public IScopeManager ScopeManager => throw new NotSupportedException(); | ||
|
||
public ISpan ActiveSpan => throw new NotSupportedException(); | ||
|
||
public ISpanBuilder BuildSpan(string operationName) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public ISpanContext Extract<TCarrier>(IFormat<TCarrier> format, TCarrier carrier) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public void Inject<TCarrier>(ISpanContext spanContext, IFormat<TCarrier> format, TCarrier carrier) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} | ||
} |
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