Skip to content

Commit

Permalink
Rename TraceConfig to TracerConfiguration and remove Default (#258)
Browse files Browse the repository at this point in the history
* TraceConfig to TracerConfiguration and remove Default

* Add TracerConfiguration file and fix namespace
  • Loading branch information
Liudmila Molkova authored Oct 7, 2019
1 parent e9edb28 commit 6bf0e18
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation
using Google.Cloud.Trace.V2;
using Google.Protobuf.WellKnownTypes;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Config;

internal static class SpanExtensions
{
Expand Down Expand Up @@ -90,8 +89,6 @@ public static Google.Cloud.Trace.V2.Span.Types.Link ToLink(this Link link)
{
ret.Attributes = new Google.Cloud.Trace.V2.Span.Types.Attributes
{
DroppedAttributesCount = TraceConfig.Default.MaxNumberOfAttributes - link.Attributes.Count,

AttributeMap =
{
link.Attributes.ToDictionary(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TraceConfig.cs" company="OpenTelemetry Authors">
// <copyright file="TracerConfiguration.cs" company="OpenTelemetry Authors">
// Copyright 2018, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,32 +14,31 @@
// limitations under the License.
// </copyright>

namespace OpenTelemetry.Trace.Config
namespace OpenTelemetry.Trace.Configuration
{
using System;
using OpenTelemetry.Trace.Sampler;

/// <summary>
/// Trace configuration that can be updates in runtime.
/// </summary>
public sealed class TraceConfig
public sealed class TracerConfiguration
{
/// <summary>
/// Default trace parameters.
/// </summary>
public static readonly TraceConfig Default =
new TraceConfig(Samplers.AlwaysSample, DefaultSpanMaxNumAttributes, DefaultSpanMaxNumEvents, DefaultSpanMaxNumLinks);

private const int DefaultSpanMaxNumAttributes = 32;
private const int DefaultSpanMaxNumEvents = 128;
private const int DefaultSpanMaxNumLinks = 32;

public TraceConfig(ISampler sampler)
public TracerConfiguration()
: this(Samplers.AlwaysSample, DefaultSpanMaxNumAttributes, DefaultSpanMaxNumEvents, DefaultSpanMaxNumLinks)
{
}

public TracerConfiguration(ISampler sampler)
: this(sampler, DefaultSpanMaxNumAttributes, DefaultSpanMaxNumEvents, DefaultSpanMaxNumLinks)
{
}

public TraceConfig(ISampler sampler, int maxNumberOfAttributes, int maxNumberOfEvents, int maxNumberOfLinks)
public TracerConfiguration(ISampler sampler, int maxNumberOfAttributes, int maxNumberOfEvents, int maxNumberOfLinks)
{
if (maxNumberOfAttributes <= 0)
{
Expand Down
18 changes: 9 additions & 9 deletions src/OpenTelemetry/Trace/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenTelemetry.Trace
using System.Diagnostics;
using System.Linq;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
using OpenTelemetry.Trace.Internal;
using OpenTelemetry.Utils;
Expand All @@ -31,7 +31,7 @@ namespace OpenTelemetry.Trace
/// </summary>
public sealed class Span : ISpan
{
private readonly TraceConfig traceConfig;
private readonly TracerConfiguration tracerConfiguration;
private readonly SpanProcessor spanProcessor;
private readonly Lazy<SpanContext> spanContext;
private readonly DateTimeOffset startTimestamp;
Expand All @@ -46,7 +46,7 @@ internal Span(
Activity activity,
IEnumerable<KeyValuePair<string, string>> tracestate,
SpanKind spanKind,
TraceConfig traceConfig,
TracerConfiguration tracerConfiguration,
SpanProcessor spanProcessor,
DateTimeOffset startTimestamp,
bool ownsActivity,
Expand All @@ -59,7 +59,7 @@ internal Span(
this.Activity.ActivityTraceFlags,
tracestate));
this.Name = this.Activity.OperationName;
this.traceConfig = traceConfig;
this.tracerConfiguration = tracerConfiguration;
this.spanProcessor = spanProcessor;
this.Kind = spanKind;
this.OwnsActivity = ownsActivity;
Expand Down Expand Up @@ -185,7 +185,7 @@ public void SetAttribute(KeyValuePair<string, object> keyValuePair)

if (this.attributes == null)
{
this.attributes = new EvictingQueue<KeyValuePair<string, object>>(this.traceConfig.MaxNumberOfAttributes);
this.attributes = new EvictingQueue<KeyValuePair<string, object>>(this.tracerConfiguration.MaxNumberOfAttributes);
}

this.attributes.AddEvent(new KeyValuePair<string, object>(keyValuePair.Key, keyValuePair.Value));
Expand Down Expand Up @@ -216,7 +216,7 @@ public void AddEvent(string name)
if (this.events == null)
{
this.events =
new EvictingQueue<Event>(this.traceConfig.MaxNumberOfEvents);
new EvictingQueue<Event>(this.tracerConfiguration.MaxNumberOfEvents);
}

this.events.AddEvent(new Event(name, PreciseTimestamp.GetUtcNow()));
Expand Down Expand Up @@ -252,7 +252,7 @@ public void AddEvent(string name, IDictionary<string, object> eventAttributes)
if (this.events == null)
{
this.events =
new EvictingQueue<Event>(this.traceConfig.MaxNumberOfEvents);
new EvictingQueue<Event>(this.tracerConfiguration.MaxNumberOfEvents);
}

this.events.AddEvent(new Event(name, PreciseTimestamp.GetUtcNow(), eventAttributes));
Expand Down Expand Up @@ -283,7 +283,7 @@ public void AddEvent(Event addEvent)
if (this.events == null)
{
this.events =
new EvictingQueue<Event>(this.traceConfig.MaxNumberOfEvents);
new EvictingQueue<Event>(this.tracerConfiguration.MaxNumberOfEvents);
}

this.events.AddEvent(addEvent);
Expand Down Expand Up @@ -313,7 +313,7 @@ public void AddLink(Link link)

if (this.links == null)
{
this.links = new EvictingQueue<Link>(this.traceConfig.MaxNumberOfLinks);
this.links = new EvictingQueue<Link>(this.tracerConfiguration.MaxNumberOfLinks);
}

this.links.AddEvent(link);
Expand Down
16 changes: 8 additions & 8 deletions src/OpenTelemetry/Trace/SpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace OpenTelemetry.Trace
using System.Linq;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
using OpenTelemetry.Trace.Internal;

/// <inheritdoc/>
public class SpanBuilder : ISpanBuilder
{
private readonly SpanProcessor spanProcessor;
private readonly TraceConfig traceConfig;
private readonly TracerConfiguration tracerConfiguration;
private readonly string name;

private SpanKind kind;
Expand All @@ -45,11 +45,11 @@ public class SpanBuilder : ISpanBuilder
private DateTimeOffset startTimestamp;
private Resource libraryResource;

internal SpanBuilder(string name, SpanProcessor spanProcessor, TraceConfig traceConfig, Resource libraryResource)
internal SpanBuilder(string name, SpanProcessor spanProcessor, TracerConfiguration tracerConfiguration, Resource libraryResource)
{
this.name = name ?? throw new ArgumentNullException(nameof(name));
this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor));
this.traceConfig = traceConfig ?? throw new ArgumentNullException(nameof(traceConfig));
this.tracerConfiguration = tracerConfiguration ?? throw new ArgumentNullException(nameof(tracerConfiguration));
this.libraryResource = libraryResource ?? throw new ArgumentNullException(nameof(libraryResource));
}

Expand Down Expand Up @@ -217,7 +217,7 @@ public ISpan StartSpan()
this.links,
activityForSpan.TraceId,
activityForSpan.SpanId,
this.traceConfig);
this.tracerConfiguration);

if (sampledIn || this.recordEvents)
{
Expand Down Expand Up @@ -251,7 +251,7 @@ public ISpan StartSpan()
activityForSpan,
childTracestate,
this.kind,
this.traceConfig,
this.tracerConfiguration,
this.spanProcessor,
this.startTimestamp,
ownsActivity: this.contextSource != ContextSource.Activity,
Expand Down Expand Up @@ -300,7 +300,7 @@ private static bool MakeSamplingDecision(
List<Link> parentLinks,
ActivityTraceId traceId,
ActivitySpanId spanId,
TraceConfig traceConfig)
TracerConfiguration tracerConfiguration)
{
// If users set a specific sampler in the SpanBuilder, use it.
if (sampler != null)
Expand All @@ -312,7 +312,7 @@ private static bool MakeSamplingDecision(
// parent).
if (parent == null || !parent.IsValid)
{
return traceConfig
return tracerConfiguration
.Sampler
.ShouldSample(parent, traceId, spanId, name, parentLinks).IsSampled;
}
Expand Down
19 changes: 9 additions & 10 deletions src/OpenTelemetry/Trace/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace OpenTelemetry.Trace
{
using System;
using System.Diagnostics;
using OpenTelemetry.Context;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
using OpenTelemetry.Trace.Internal;

Expand All @@ -40,25 +39,25 @@ static Tracer()
/// Creates an instance of <see cref="ITracer"/>.
/// </summary>
/// <param name="spanProcessor">Span processor.</param>
/// <param name="traceConfig">Trace configuration.</param>
/// <param name="tracerConfiguration">Trace configuration.</param>
/// <param name="libraryResource">Resource describing the instrumentation library.</param>
public Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig, Resource libraryResource)
: this(spanProcessor, traceConfig, new BinaryFormat(), new TraceContextFormat(), libraryResource)
public Tracer(SpanProcessor spanProcessor, TracerConfiguration tracerConfiguration, Resource libraryResource)
: this(spanProcessor, tracerConfiguration, new BinaryFormat(), new TraceContextFormat(), libraryResource)
{
}

/// <summary>
/// Creates an instance of <see cref="Tracer"/>.
/// </summary>
/// <param name="spanProcessor">Span processor.</param>
/// <param name="traceConfig">Trace configuration.</param>
/// <param name="tracerConfiguration">Trace configuration.</param>
/// <param name="binaryFormat">Binary format context propagator.</param>
/// <param name="textFormat">Text format context propagator.</param>
/// <param name="libraryResource">Resource describing the instrumentation library.</param>
internal Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig, IBinaryFormat binaryFormat, ITextFormat textFormat, Resource libraryResource)
internal Tracer(SpanProcessor spanProcessor, TracerConfiguration tracerConfiguration, IBinaryFormat binaryFormat, ITextFormat textFormat, Resource libraryResource)
{
this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor));
this.ActiveTraceConfig = traceConfig ?? throw new ArgumentNullException(nameof(traceConfig));
this.ActiveTracerConfiguration = tracerConfiguration ?? throw new ArgumentNullException(nameof(tracerConfiguration));
this.BinaryFormat = binaryFormat ?? throw new ArgumentNullException(nameof(binaryFormat));
this.TextFormat = textFormat ?? throw new ArgumentNullException(nameof(textFormat));
this.LibraryResource = libraryResource ?? throw new ArgumentNullException(nameof(libraryResource));
Expand All @@ -75,12 +74,12 @@ internal Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig, IBinaryFor
/// <inheritdoc/>
public ITextFormat TextFormat { get; }

public TraceConfig ActiveTraceConfig { get; set; }
public TracerConfiguration ActiveTracerConfiguration { get; set; }

/// <inheritdoc/>
public ISpanBuilder SpanBuilder(string spanName)
{
return new SpanBuilder(spanName, this.spanProcessor, this.ActiveTraceConfig, this.LibraryResource);
return new SpanBuilder(spanName, this.spanProcessor, this.ActiveTracerConfiguration, this.LibraryResource);
}

public IDisposable WithSpan(ISpan span)
Expand Down
12 changes: 6 additions & 6 deletions src/OpenTelemetry/Trace/TracerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ namespace OpenTelemetry.Trace
using System.Collections.Generic;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;

/// <inheritdoc/>
public sealed class TracerFactory : ITracerFactory
{
private readonly object lck = new object();
private readonly SpanProcessor spanProcessor;
private readonly TraceConfig traceConfig;
private readonly TracerConfiguration tracerConfiguration;
private readonly ITextFormat textFormat;
private readonly IBinaryFormat binaryFormat;
private readonly Tracer defaultTracer;
private readonly Dictionary<TracerRegistryKey, ITracer> tracerRegistry = new Dictionary<TracerRegistryKey, ITracer>();

public TracerFactory(SpanProcessor spanProcessor = null, TraceConfig traceConfig = null, ITextFormat textFormat = null, IBinaryFormat binaryFormat = null)
public TracerFactory(SpanProcessor spanProcessor = null, TracerConfiguration tracerConfiguration = null, ITextFormat textFormat = null, IBinaryFormat binaryFormat = null)
{
this.spanProcessor = spanProcessor ?? Tracing.SpanProcessor;
this.traceConfig = traceConfig ?? Tracing.TraceConfig;
this.tracerConfiguration = tracerConfiguration ?? Tracing.TracerConfiguration;
this.textFormat = textFormat ?? new TraceContextFormat();
this.binaryFormat = binaryFormat ?? new BinaryFormat();
this.defaultTracer = new Tracer(this.spanProcessor, this.traceConfig, this.binaryFormat, this.textFormat, Resource.Empty);
this.defaultTracer = new Tracer(this.spanProcessor, this.tracerConfiguration, this.binaryFormat, this.textFormat, Resource.Empty);
}

/// <inheritdoc/>
Expand All @@ -56,7 +56,7 @@ public override ITracer GetTracer(string name, string version = null)
if (!this.tracerRegistry.TryGetValue(key, out var tracer))
{
var labels = CreateLibraryResourceLabels(name, version);
tracer = new Tracer(this.spanProcessor, this.traceConfig, this.binaryFormat, this.textFormat, new Resource(labels));
tracer = new Tracer(this.spanProcessor, this.tracerConfiguration, this.binaryFormat, this.textFormat, new Resource(labels));
this.tracerRegistry.Add(key, tracer);
}

Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry/Trace/Tracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace OpenTelemetry.Trace
{
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;

/// <summary>
Expand All @@ -28,9 +28,9 @@ public static class Tracing

static Tracing()
{
TraceConfig = TraceConfig.Default;
TracerConfiguration = new TracerConfiguration();
SpanProcessor = new BatchingSpanProcessor(new NoopSpanExporter());
tracerFactory = new TracerFactory(SpanProcessor, TraceConfig);
tracerFactory = new TracerFactory(SpanProcessor, TracerConfiguration);
}

/// <summary>
Expand All @@ -46,6 +46,6 @@ static Tracing()
/// <summary>
/// Gets the trace config.
/// </summary>
public static TraceConfig TraceConfig { get; }
public static TracerConfiguration TracerConfiguration { get; }
}
}
12 changes: 6 additions & 6 deletions test/OpenTelemetry.Collector.AspNetCore.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Collector.AspNetCore.Tests
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
using Moq;
using Microsoft.AspNetCore.TestHost;
Expand All @@ -48,8 +48,8 @@ public BasicTests(WebApplicationFactory<Startup> factory)
[Fact]
public async Task SuccessfulTemplateControllerCallGeneratesASpan()
{
var panProcessor = new Mock<SpanProcessor>(new NoopSpanExporter());
var tracerFactory = new TracerFactory(panProcessor.Object);
var spanProcessor = new Mock<SpanProcessor>(new NoopSpanExporter());
var tracerFactory = new TracerFactory(spanProcessor.Object);

void ConfigureTestServices(IServiceCollection services) =>
services.AddSingleton<ITracerFactory>(tracerFactory);
Expand All @@ -69,7 +69,7 @@ void ConfigureTestServices(IServiceCollection services) =>

for (var i = 0; i < 10; i++)
{
if (panProcessor.Invocations.Count == 2)
if (spanProcessor.Invocations.Count == 2)
{
break;
}
Expand All @@ -82,8 +82,8 @@ void ConfigureTestServices(IServiceCollection services) =>
}


Assert.Equal(2, panProcessor.Invocations.Count); // begin and end was called
var span = ((Span)panProcessor.Invocations[1].Arguments[0]);
Assert.Equal(2, spanProcessor.Invocations.Count); // begin and end was called
var span = ((Span)spanProcessor.Invocations[1].Arguments[0]);

Assert.Equal(SpanKind.Server, span.Kind);
Assert.Equal("/api/values", span.Attributes.GetValue("http.path"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Collector.AspNetCore.Tests
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
using Moq;
using Microsoft.AspNetCore.TestHost;
Expand Down
Loading

0 comments on commit 6bf0e18

Please sign in to comment.