-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// <copyright file="ITracerProvider.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, 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> | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
/// <summary> | ||
/// Creates Tracers for an instrumentation library. | ||
/// </summary> | ||
public interface ITracerProvider | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
longility
Author
Owner
|
||
{ | ||
/// <summary> | ||
/// Returns an Tracer for a given name and version. | ||
/// </summary> | ||
/// <param name="name">Name of the instrumentation library.</param> | ||
/// <param name="version">Version of the instrumentation library (optional).</param> | ||
/// <returns>Tracer for the given name and version information.</returns> | ||
Tracer GetTracer(string name, string version = null); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// <copyright file="ProxyTracer.cs" company="OpenTelemetry Authors"> | ||
// <copyright file="NoopTracer.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -17,58 +17,49 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
/// <summary> | ||
/// No-op tracer. | ||
/// </summary> | ||
internal sealed class ProxyTracer : Tracer | ||
public sealed class NoopTracer : Tracer | ||
This comment has been minimized.
Sorry, something went wrong.
cijothomas
|
||
{ | ||
private static readonly IDisposable NoopScope = new NoopDisposable(); | ||
|
||
private Tracer realTracer; | ||
private readonly TelemetrySpan noopSpan = new NoopSpan(); | ||
|
||
/// <inheritdoc/> | ||
public override TelemetrySpan CurrentSpan => this.realTracer?.CurrentSpan ?? BlankSpan.Instance; | ||
public override TelemetrySpan CurrentSpan => this.noopSpan; | ||
|
||
/// <inheritdoc/> | ||
public override IDisposable WithSpan(TelemetrySpan span, bool endOnDispose) | ||
{ | ||
return this.realTracer != null ? this.realTracer.WithSpan(span, endOnDispose) : NoopScope; | ||
return NoopScope; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override TelemetrySpan StartRootSpan(string operationName, SpanKind kind, SpanCreationOptions options) | ||
{ | ||
return this.realTracer != null ? this.realTracer.StartRootSpan(operationName, kind, options) : BlankSpan.Instance; | ||
return this.noopSpan; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override TelemetrySpan StartSpan(string operationName, TelemetrySpan parent, SpanKind kind, SpanCreationOptions options) | ||
{ | ||
return this.realTracer != null ? this.realTracer.StartSpan(operationName, parent, kind, options) : BlankSpan.Instance; | ||
return this.noopSpan; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override TelemetrySpan StartSpan(string operationName, in SpanContext parent, SpanKind kind, SpanCreationOptions options) | ||
{ | ||
return this.realTracer != null ? this.realTracer.StartSpan(operationName, parent, kind, options) : BlankSpan.Instance; | ||
return this.noopSpan; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override TelemetrySpan StartSpanFromActivity(string operationName, Activity activity, SpanKind kind, IEnumerable<Link> links) | ||
{ | ||
return this.realTracer != null ? this.realTracer.StartSpanFromActivity(operationName, activity, kind, links) : BlankSpan.Instance; | ||
} | ||
|
||
public void UpdateTracer(Tracer realTracer) | ||
{ | ||
if (this.realTracer != null) | ||
{ | ||
return; | ||
} | ||
|
||
// just in case user calls init concurrently | ||
Interlocked.CompareExchange(ref this.realTracer, realTracer, null); | ||
return this.noopSpan; | ||
} | ||
|
||
private class NoopDisposable : IDisposable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// <copyright file="NoopTracerProvider.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, 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; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
/// <summary> | ||
/// No-op tracer provider. | ||
/// </summary> | ||
public class NoopTracerProvider : ITracerProvider | ||
{ | ||
private readonly NoopTracer tracer = new NoopTracer(); | ||
|
||
/// <inheritdoc/> | ||
public Tracer GetTracer(string name, string version = null) | ||
{ | ||
return this.tracer; | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// <copyright file="TracerProvider.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, 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> | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
/// <summary> | ||
/// Creates Tracers for an instrumentation library. | ||
/// </summary> | ||
public class TracerProvider | ||
{ | ||
/// <summary> | ||
/// Gets or sets the global instance of <see cref="ITracerProvider"/>. | ||
/// </summary> | ||
public static ITracerProvider GlobalInstance { get; protected set; } = new NoopTracerProvider(); | ||
|
||
/// <summary> | ||
/// Returns an Tracer for a given name and version. | ||
/// </summary> | ||
/// <param name="name">Name of the instrumentation library.</param> | ||
/// <param name="version">Version of the instrumentation library (optional).</param> | ||
/// <returns>Tracer for the given name and version information.</returns> | ||
public static Tracer GetTracer(string name, string version = null) | ||
{ | ||
return GlobalInstance.GetTracer(name, version); | ||
} | ||
|
||
// for tests | ||
internal void Reset() | ||
{ | ||
GlobalInstance = new NoopTracerProvider(); | ||
} | ||
} | ||
} |
in general, we try to use abstract classes instead of interfaces, so that if we ever need to extend this, we can do that without breaking existing users.