Skip to content

Commit

Permalink
Merge branch 'main' into add-configurable-path-to-jaeger-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
abe545 authored Feb 23, 2022
2 parents e007798 + 843d6fd commit 9a2eac7
Show file tree
Hide file tree
Showing 137 changed files with 1,221 additions and 478 deletions.
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coverage:
round: down
range: "70...100"
status:
project: off
patch: off

parsers:
Expand Down
12 changes: 2 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ Add your fork as an origin:
git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-dotnet.git
```

By default your work will be targeting the `main` branch. If you want to work on
the experimental metrics feature, please switch to the `metrics` feature branch:

```sh
# only do this when you want to work on the experimental metrics feature
git checkout metrics
```

Run tests:

```sh
Expand Down Expand Up @@ -174,8 +166,8 @@ A PR is considered to be **ready to merge** when:
* Urgent fix can take exception as long as it has been actively communicated.

Any Maintainer can merge the PR once it is **ready to merge**. Note, that some
PR may not be merged immediately if repo is being in process of a major release
and the new feature doesn't fit it.
PRs may not be merged immediately if the repo is in the process of a release and
the maintainers decided to defer the PR to the next release train.

If a PR has been stuck (e.g. there are lots of debates and people couldn't agree
on each other), the owner should try to get people aligned by:
Expand Down
3 changes: 3 additions & 0 deletions examples/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ internal class MetricsOptions

[Option("useExporter", Default = "console", HelpText = "Options include otlp or console.", Required = false)]
public string UseExporter { get; set; }

[Option('p', "useGrpc", HelpText = "Use gRPC or HTTP when using the OTLP exporter", Required = false, Default = true)]
public bool UseGrpc { get; set; }
}

[Verb("grpc", HelpText = "Specify the options required to test Grpc.Net.Client")]
Expand Down
11 changes: 7 additions & 4 deletions examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

Expand Down Expand Up @@ -66,11 +67,13 @@ internal static object Run(MetricsOptions options)
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

providerBuilder
.AddOtlpExporter(o =>
.AddOtlpExporter((exporterOptions, metricReaderOptions) =>
{
o.MetricReaderType = MetricReaderType.Periodic;
o.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
o.AggregationTemporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf;

metricReaderOptions.MetricReaderType = MetricReaderType.Periodic;
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
});
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Utils.Messaging
public class MessageReceiver : IDisposable
{
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver));
private static readonly TextMapPropagator Propagator = new TraceContextPropagator();
private static readonly TextMapPropagator Propagator = Propagators.DefaultTextMapPropagator;

private readonly ILogger<MessageReceiver> logger;
private readonly IConnection connection;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Baggage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public IReadOnlyDictionary<string, string> GetBaggage()
/// <returns>Baggage item or <see langword="null"/> if nothing was found.</returns>
public string GetBaggage(string name)
{
Guard.ThrowIfNullOrEmpty(name, nameof(name));
Guard.ThrowIfNullOrEmpty(name);

return this.baggage != null && this.baggage.TryGetValue(name, out string value)
? value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CompositeTextMapPropagator : TextMapPropagator
/// <param name="propagators">List of <see cref="TextMapPropagator"/> wire context propagator.</param>
public CompositeTextMapPropagator(IEnumerable<TextMapPropagator> propagators)
{
Guard.ThrowIfNull(propagators, nameof(propagators));
Guard.ThrowIfNull(propagators);

this.propagators = new List<TextMapPropagator>(propagators);
}
Expand Down
14 changes: 7 additions & 7 deletions src/OpenTelemetry.Api/Context/RuntimeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class RuntimeContext
/// <returns>The slot registered.</returns>
public static RuntimeContextSlot<T> RegisterSlot<T>(string slotName)
{
Guard.ThrowIfNullOrEmpty(slotName, nameof(slotName));
Guard.ThrowIfNullOrEmpty(slotName);

lock (Slots)
{
Expand All @@ -66,9 +66,9 @@ public static RuntimeContextSlot<T> RegisterSlot<T>(string slotName)
/// <returns>The slot previously registered.</returns>
public static RuntimeContextSlot<T> GetSlot<T>(string slotName)
{
Guard.ThrowIfNullOrEmpty(slotName, nameof(slotName));
Guard.ThrowIfNullOrEmpty(slotName);
var slot = GuardNotFound(slotName);
var contextSlot = Guard.ThrowIfNotOfType<RuntimeContextSlot<T>>(slot, nameof(slot));
var contextSlot = Guard.ThrowIfNotOfType<RuntimeContextSlot<T>>(slot);
return contextSlot;
}

Expand Down Expand Up @@ -127,9 +127,9 @@ public static T GetValue<T>(string slotName)
/// <param name="value">The value to be set.</param>
public static void SetValue(string slotName, object value)
{
Guard.ThrowIfNullOrEmpty(slotName, nameof(slotName));
Guard.ThrowIfNullOrEmpty(slotName);
var slot = GuardNotFound(slotName);
var runtimeContextSlotValueAccessor = Guard.ThrowIfNotOfType<IRuntimeContextSlotValueAccessor>(slot, nameof(slot));
var runtimeContextSlotValueAccessor = Guard.ThrowIfNotOfType<IRuntimeContextSlotValueAccessor>(slot);
runtimeContextSlotValueAccessor.Value = value;
}

Expand All @@ -140,9 +140,9 @@ public static void SetValue(string slotName, object value)
/// <returns>The value retrieved from the context slot.</returns>
public static object GetValue(string slotName)
{
Guard.ThrowIfNullOrEmpty(slotName, nameof(slotName));
Guard.ThrowIfNullOrEmpty(slotName);
var slot = GuardNotFound(slotName);
var runtimeContextSlotValueAccessor = Guard.ThrowIfNotOfType<IRuntimeContextSlotValueAccessor>(slot, nameof(slot));
var runtimeContextSlotValueAccessor = Guard.ThrowIfNotOfType<IRuntimeContextSlotValueAccessor>(slot);
return runtimeContextSlotValueAccessor.Value;
}

Expand Down
50 changes: 40 additions & 10 deletions src/OpenTelemetry.Api/Internal/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,53 @@
using System.Runtime.CompilerServices;
using System.Threading;

#if !NETCOREAPP3_0_OR_GREATER
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Allows capturing of the expressions passed to a method.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name
internal sealed class CallerArgumentExpressionAttribute : Attribute
#pragma warning restore SA1649 // File name should match first type name
#pragma warning restore SA1402 // File may only contain a single type
{
/// <summary>
/// Initializes a new instance of the <see cref="CallerArgumentExpressionAttribute"/> class.
/// </summary>
/// <param name="parameterName">The name of the targeted parameter.</param>
public CallerArgumentExpressionAttribute(string parameterName)
{
this.ParameterName = parameterName;
}

/// <summary>
/// Gets the target parameter name of the CallerArgumentExpression.
/// </summary>
public string ParameterName { get; }
}
}
#endif

#pragma warning disable SA1403 // File may only contain a single namespace
namespace OpenTelemetry.Internal
#pragma warning restore SA1403 // File may only contain a single namespace
{
/// <summary>
/// Methods for guarding against exception throwing values.
/// </summary>
internal static class Guard
{
private const string DefaultParamName = "N/A";

/// <summary>
/// Throw an exception if the value is null.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNull(object value, string paramName = DefaultParamName)
public static void ThrowIfNull(object value, [CallerArgumentExpression("value")] string paramName = null)
{
if (value is null)
{
Expand All @@ -50,7 +80,7 @@ public static void ThrowIfNull(object value, string paramName = DefaultParamName
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrEmpty(string value, string paramName = DefaultParamName)
public static void ThrowIfNullOrEmpty(string value, [CallerArgumentExpression("value")] string paramName = null)
{
if (string.IsNullOrEmpty(value))
{
Expand All @@ -65,7 +95,7 @@ public static void ThrowIfNullOrEmpty(string value, string paramName = DefaultPa
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrWhitespace(string value, string paramName = DefaultParamName)
public static void ThrowIfNullOrWhitespace(string value, [CallerArgumentExpression("value")] string paramName = null)
{
if (string.IsNullOrWhiteSpace(value))
{
Expand All @@ -81,7 +111,7 @@ public static void ThrowIfNullOrWhitespace(string value, string paramName = Defa
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfZero(int value, string message = "Must not be zero", string paramName = DefaultParamName)
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression("value")] string paramName = null)
{
if (value == 0)
{
Expand All @@ -96,7 +126,7 @@ public static void ThrowIfZero(int value, string message = "Must not be zero", s
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfInvalidTimeout(int value, string paramName = DefaultParamName)
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("value")] string paramName = null)
{
ThrowIfOutOfRange(value, paramName, min: Timeout.Infinite, message: $"Must be non-negative or '{nameof(Timeout)}.{nameof(Timeout.Infinite)}'");
}
Expand All @@ -113,7 +143,7 @@ public static void ThrowIfInvalidTimeout(int value, string paramName = DefaultPa
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(int value, string paramName = DefaultParamName, int min = int.MinValue, int max = int.MaxValue, string minName = null, string maxName = null, string message = null)
public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value")] string paramName = null, int min = int.MinValue, int max = int.MaxValue, string minName = null, string maxName = null, string message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -130,7 +160,7 @@ public static void ThrowIfOutOfRange(int value, string paramName = DefaultParamN
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(double value, string paramName = DefaultParamName, double min = double.MinValue, double max = double.MaxValue, string minName = null, string maxName = null, string message = null)
public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("value")] string paramName = null, double min = double.MinValue, double max = double.MaxValue, string minName = null, string maxName = null, string message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -144,7 +174,7 @@ public static void ThrowIfOutOfRange(double value, string paramName = DefaultPar
/// <returns>The value casted to the specified type.</returns>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ThrowIfNotOfType<T>(object value, string paramName = DefaultParamName)
public static T ThrowIfNotOfType<T>(object value, [CallerArgumentExpression("value")] string paramName = null)
{
if (value is not T result)
{
Expand Down
8 changes: 6 additions & 2 deletions src/OpenTelemetry.Api/Internal/SpanHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
// </copyright>

using System.Diagnostics;

namespace OpenTelemetry.Trace
{
/// <summary>
Expand All @@ -25,11 +27,13 @@ internal static class SpanHelper
/// Helper method that populates span properties from http status code according
/// to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status.
/// </summary>
/// <param name="kind">The span kind.</param>
/// <param name="httpStatusCode">Http status code.</param>
/// <returns>Resolved span <see cref="Status"/> for the Http status code.</returns>
public static Status ResolveSpanStatusForHttpStatusCode(int httpStatusCode)
public static Status ResolveSpanStatusForHttpStatusCode(ActivityKind kind, int httpStatusCode)
{
if (httpStatusCode >= 100 && httpStatusCode <= 399)
var upperBound = kind == ActivityKind.Client ? 399 : 499;
if (httpStatusCode >= 100 && httpStatusCode <= upperBound)
{
return Status.Unset;
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Api/Trace/SpanAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SpanAttributes()
public SpanAttributes(IEnumerable<KeyValuePair<string, object>> attributes)
: this()
{
Guard.ThrowIfNull(attributes, nameof(attributes));
Guard.ThrowIfNull(attributes);

foreach (KeyValuePair<string, object> kvp in attributes)
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public void Add(string key, double[] values)

private void AddInternal(string key, object value)
{
Guard.ThrowIfNull(key, nameof(key));
Guard.ThrowIfNull(key);

this.Attributes[key] = value;
}
Expand Down
15 changes: 11 additions & 4 deletions src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ public override ExportResult Export(in Batch<Activity> batch)
{
foreach (var activity in batch)
{
this.WriteLine($"Activity.Id: {activity.Id}");
if (!string.IsNullOrEmpty(activity.ParentId))
this.WriteLine($"Activity.TraceId: {activity.TraceId}");
this.WriteLine($"Activity.SpanId: {activity.SpanId}");
this.WriteLine($"Activity.TraceFlags: {activity.ActivityTraceFlags}");
if (!string.IsNullOrEmpty(activity.TraceStateString))
{
this.WriteLine($"Activity.ParentId: {activity.ParentId}");
this.WriteLine($"Activity.TraceState: {activity.TraceStateString}");
}

if (activity.ParentSpanId != default)
{
this.WriteLine($"Activity.ParentSpanId: {activity.ParentSpanId}");
}

this.WriteLine($"Activity.ActivitySourceName: {activity.Source.Name}");
Expand All @@ -45,7 +52,7 @@ public override ExportResult Export(in Batch<Activity> batch)
this.WriteLine($"Activity.Duration: {activity.Duration}");
if (activity.TagObjects.Any())
{
this.WriteLine("Activity.TagObjects:");
this.WriteLine("Activity.Tags:");
foreach (var tag in activity.TagObjects)
{
var array = tag.Value as Array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class ConsoleExporterHelperExtensions
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The objects should not be disposed.")]
public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action<ConsoleExporterOptions> configure = null)
{
Guard.ThrowIfNull(builder, nameof(builder));
Guard.ThrowIfNull(builder);

if (builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace OpenTelemetry.Logs
public static class ConsoleExporterLoggingExtensions
{
/// <summary>
/// Adds Console Exporter as a configuration to the OpenTelemetry ILoggingBuilder.
/// Adds Console exporter with OpenTelemetryLoggerOptions.
/// </summary>
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action<ConsoleExporterOptions> configure = null)
{
Guard.ThrowIfNull(loggerOptions, nameof(loggerOptions));
Guard.ThrowIfNull(loggerOptions);

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class ConsoleExporterMetricsExtensions
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The objects should not be disposed.")]
public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder, Action<ConsoleExporterOptions> configure = null)
{
Guard.ThrowIfNull(builder, nameof(builder));
Guard.ThrowIfNull(builder);

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static class InMemoryExporterHelperExtensions
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The objects should not be disposed.")]
public static TracerProviderBuilder AddInMemoryExporter(this TracerProviderBuilder builder, ICollection<Activity> exportedItems)
{
Guard.ThrowIfNull(builder, nameof(builder));
Guard.ThrowIfNull(exportedItems, nameof(exportedItems));
Guard.ThrowIfNull(builder);
Guard.ThrowIfNull(exportedItems);

if (builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder)
{
Expand Down
Loading

0 comments on commit 9a2eac7

Please sign in to comment.