Skip to content

Commit

Permalink
Renames from span to activity
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti committed Jun 2, 2020
1 parent 3db3ad9 commit 7e1edcd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/OpenTelemetry/Trace/Configuration/OpenTelemetrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ public static IDisposable EnableOpenTelemetry(Action<OpenTelemetryBuilder> confi
in ActivityCreationOptions<ActivityContext> options, out ActivitySamplingParameters samplingParameters)
{
ActivityContext parentContext = options.Parent;
if (options.Parent == default)
if (parentContext == default)
{
// Check if there is already a parent for the current span.
var parentSpan = Activity.Current;
if (parentSpan != null)
// Check if there is already a parent for the current activity.
var parentActivity = Activity.Current;
if (parentActivity != null)
{
parentContext = parentSpan.Context;
parentContext = parentActivity.Context;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/OpenTelemetry/Trace/Samplers/ProbabilityActivitySampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace OpenTelemetry.Trace.Samplers
{
/// <summary>
/// Sampler implementation which will take a sample if parent span or any linked span is sampled.
/// Sampler implementation which will take a sample if parent Activity or any linked Activity is sampled.
/// Otherwise, samples traces according to the specified probability.
/// </summary>
public sealed class ProbabilityActivitySampler : ActivitySampler
Expand All @@ -32,7 +32,7 @@ public sealed class ProbabilityActivitySampler : ActivitySampler
/// Initializes a new instance of the <see cref="ProbabilityActivitySampler"/> class.
/// </summary>
/// <param name="probability">The desired probability of sampling. This must be between 0.0 and 1.0.
/// Higher the value, higher is the probability of a given span to be sampled in.
/// Higher the value, higher is the probability of a given Activity to be sampled in.
/// </param>
public ProbabilityActivitySampler(double probability)
{
Expand Down Expand Up @@ -89,13 +89,13 @@ public override SamplingResult ShouldSample(in ActivitySamplingParameters sampli
}
}

// Always sample if we are within probability range. This is true even for child spans (that
// Always sample if we are within probability range. This is true even for child activities (that
// may have had a different sampling decision made) to allow for different sampling policies,
// and dynamic increases to sampling probabilities for debugging purposes.
// Note use of '<' for comparison. This ensures that we never sample for probability == 0.0,
// while allowing for a (very) small chance of *not* sampling if the id == Long.MAX_VALUE.
// This is considered a reasonable tradeoff for the simplicity/performance requirements (this
// code is executed in-line for every Span creation).
// This is considered a reasonable trade-off for the simplicity/performance requirements (this
// code is executed in-line for every Activity creation).
Span<byte> traceIdBytes = stackalloc byte[16];
samplingParameters.TraceId.CopyTo(traceIdBytes);
return Math.Abs(this.GetLowerLong(traceIdBytes)) < this.idUpperBound ? new SamplingResult(true) : new SamplingResult(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public void BuildSamplingParametersHandlesCurrentActivity()
{
using var activitySource = new ActivitySource(nameof(BuildSamplingParametersHandlesCurrentActivity));

var samplingParameters = new ActivitySamplingParameters();
var latestSamplingParameters = new ActivitySamplingParameters();

using var listener = new ActivityListener
{
ShouldListenTo = _ => true,
GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) =>
{
OpenTelemetrySdk.BuildSamplingParameters(options, out samplingParameters);
OpenTelemetrySdk.BuildSamplingParameters(options, out latestSamplingParameters);
return ActivityDataRequest.AllDataAndRecorded;
},
};
Expand All @@ -54,14 +54,17 @@ public void BuildSamplingParametersHandlesCurrentActivity()

// This enforces the current behavior that the traceId passed to the sampler for the
// root span/activity is not the traceId actually used.
Assert.NotEqual(root.TraceId, samplingParameters.TraceId);
Assert.NotEqual(root.TraceId, latestSamplingParameters.TraceId);
}

using (var parent = activitySource.StartActivity("parent", ActivityKind.Client))
{
// This enforces the current behavior that the traceId passed to the sampler for the
// root span/activity is not the traceId actually used.
Assert.NotEqual(parent.TraceId, latestSamplingParameters.TraceId);
using (var child = activitySource.StartActivity("child"))
{
Assert.Equal(parent.TraceId, samplingParameters.TraceId);
Assert.Equal(parent.TraceId, latestSamplingParameters.TraceId);
Assert.Equal(parent.TraceId, child.TraceId);
Assert.Equal(parent.SpanId, child.ParentSpanId);
}
Expand Down

0 comments on commit 7e1edcd

Please sign in to comment.