Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: C# 8 and nullable reference types #380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/open-telemetry/opentelemetry-dotnet</PackageProjectUrl>
<LangVersion>7.3</LangVersion>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> ge
return SpanContext.BlankRemote;
}

List<KeyValuePair<string, string>> tracestate = null;
List<KeyValuePair<string, string>>? tracestate = null;
var tracestateCollection = getter(carrier, "tracestate");
if (tracestateCollection != null)
{
Expand Down Expand Up @@ -234,7 +234,7 @@ private byte HexCharToByte(char c)
throw new ArgumentOutOfRangeException(nameof(c), $"Invalid character: {c}.");
}

private bool TryExtractTracestate(string[] tracestateCollection, out List<KeyValuePair<string, string>> tracestateResult)
private bool TryExtractTracestate(string[] tracestateCollection, out List<KeyValuePair<string, string>>? tracestateResult)
{
tracestateResult = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ internal static class TracestateUtils
/// <returns>True if string was parsed successfully and tracestate was recognized, false otherwise.</returns>
internal static bool AppendTracestate(string tracestateString, List<KeyValuePair<string, string>> tracestate)
{
Debug.Assert(tracestate != null, "tracestate list cannot be null");
if (string.IsNullOrEmpty(tracestateString))
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Metrics/MeterFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static MeterFactoryBase Default
/// <param name="name">Name of the instrumentation library.</param>
/// <param name="version">Version of the instrumentation library (optional).</param>
/// <returns>Meter with the given component name and version.</returns>
public virtual Meter GetMeter(string name, string version = null)
public virtual Meter GetMeter(string name, string? version = null)
{
return noOpMeter;
}
Expand Down
1 change: 1 addition & 0 deletions src/OpenTelemetry.Api/OpenTelemetry.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Description>OpenTelemetry .NET instrumentation API</Description>
<RootNamespace>OpenTelemetry</RootNamespace>
<DefineConstants>$(DefineConstants);API</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Trace\Internal\**" />
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry.Api/Trace/ITracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface ITracer
/// <param name="kind">Kind.</param>
/// <param name="options">Advanced span creation options.</param>
/// <returns>Span instance.</returns>
ISpan StartRootSpan(string operationName, SpanKind kind, SpanCreationOptions options);
ISpan StartRootSpan(string operationName, SpanKind kind, SpanCreationOptions? options);

/// <summary>
/// Starts span.
Expand All @@ -68,7 +68,7 @@ public interface ITracer
/// <param name="kind">Kind.</param>
/// <param name="options">Advanced span creation options.</param>
/// <returns>Span instance.</returns>
ISpan StartSpan(string operationName, ISpan parent, SpanKind kind, SpanCreationOptions options);
ISpan StartSpan(string operationName, ISpan? parent, SpanKind kind, SpanCreationOptions? options);

/// <summary>
/// Starts span.
Expand All @@ -78,7 +78,7 @@ public interface ITracer
/// <param name="kind">Kind.</param>
/// <param name="options">Advanced span creation options.</param>
/// <returns>Span instance.</returns>
ISpan StartSpan(string operationName, in SpanContext parent, SpanKind kind, SpanCreationOptions options);
ISpan StartSpan(string operationName, in SpanContext parent, SpanKind kind, SpanCreationOptions? options);

/// <summary>
/// Starts span from auto-collected <see cref="Activity"/>.
Expand All @@ -88,6 +88,6 @@ public interface ITracer
/// <param name="kind">Kind.</param>
/// <param name="links">Links collection.</param>
/// <returns>Span scope instance.</returns>
ISpan StartSpanFromActivity(string operationName, Activity activity, SpanKind kind, IEnumerable<Link> links);
ISpan StartSpanFromActivity(string operationName, Activity activity, SpanKind kind, IEnumerable<Link>? links);
}
}
10 changes: 5 additions & 5 deletions src/OpenTelemetry.Api/Trace/ProxyTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed class ProxyTracer : ITracer
private readonly IBinaryFormat binaryFormat = new BinaryFormat();
private readonly ITextFormat textFormat = new TraceContextFormat();

private ITracer realTracer;
private ITracer? realTracer;

/// <inheritdoc/>
public ISpan CurrentSpan => this.realTracer?.CurrentSpan ?? BlankSpan.Instance;
Expand All @@ -48,22 +48,22 @@ public IDisposable WithSpan(ISpan span, bool endOnDispose)
return this.realTracer != null ? this.realTracer.WithSpan(span, endOnDispose) : NoopScope;
}

public ISpan StartRootSpan(string operationName, SpanKind kind, SpanCreationOptions options)
public ISpan StartRootSpan(string operationName, SpanKind kind, SpanCreationOptions? options)
{
return this.realTracer != null ? this.realTracer.StartRootSpan(operationName, kind, options) : BlankSpan.Instance;
}

public ISpan StartSpan(string operationName, ISpan parent, SpanKind kind, SpanCreationOptions options)
public ISpan StartSpan(string operationName, ISpan? parent, SpanKind kind, SpanCreationOptions? options)
{
return this.realTracer != null ? this.realTracer.StartSpan(operationName, parent, kind, options) : BlankSpan.Instance;
}

public ISpan StartSpan(string operationName, in SpanContext parent, SpanKind kind, SpanCreationOptions options)
public ISpan StartSpan(string operationName, in SpanContext parent, SpanKind kind, SpanCreationOptions? options)
{
return this.realTracer != null ? this.realTracer.StartSpan(operationName, parent, kind, options) : BlankSpan.Instance;
}

public ISpan StartSpanFromActivity(string operationName, Activity activity, SpanKind kind, IEnumerable<Link> links)
public ISpan StartSpanFromActivity(string operationName, Activity activity, SpanKind kind, IEnumerable<Link>? links)
{
return this.realTracer != null ? this.realTracer.StartSpanFromActivity(operationName, activity, kind, links) : BlankSpan.Instance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Trace/SpanContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class SpanContext
/// associate with the <see cref="SpanContext"/>.</param>
/// <param name="isRemote">The value indicating whether this <see cref="SpanContext"/> was propagated from the remote parent.</param>
/// <param name="tracestate">The tracestate to associate with the <see cref="SpanContext"/>.</param>
public SpanContext(ActivityTraceId traceId, ActivitySpanId spanId, ActivityTraceFlags traceOptions, bool isRemote = false, IEnumerable<KeyValuePair<string, string>> tracestate = null)
public SpanContext(ActivityTraceId traceId, ActivitySpanId spanId, ActivityTraceFlags traceOptions, bool isRemote = false, IEnumerable<KeyValuePair<string, string>>? tracestate = null)
{
this.TraceId = traceId;
this.SpanId = spanId;
Expand Down
6 changes: 3 additions & 3 deletions src/OpenTelemetry.Api/Trace/SpanCreationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public class SpanCreationOptions
/// <summary>
/// Gets or sets list of <see cref="Link"/>.
/// </summary>
public IEnumerable<Link> Links { get; set; }
public IEnumerable<Link>? Links { get; set; }

/// <summary>
/// Gets or sets attributes known prior to span creation.
/// </summary>
public IDictionary<string, object> Attributes { get; set; }
public IDictionary<string, object>? Attributes { get; set; }

/// <summary>
/// Gets or sets Links factory. Use it to deserialize list of <see cref="Link"/> lazily
/// when application configures OpenTelemetry implementation that supports links.
/// </summary>
public Func<IEnumerable<Link>> LinksFactory { get; set; }
public Func<IEnumerable<Link>>? LinksFactory { get; set; }
}
}
8 changes: 4 additions & 4 deletions src/OpenTelemetry.Api/Trace/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public struct Status
/// </summary>
public static readonly Status DataLoss = new Status(CanonicalCode.DataLoss);

internal Status(CanonicalCode canonicalCode, string description = null)
internal Status(CanonicalCode canonicalCode, string? description = null)
{
this.CanonicalCode = canonicalCode;
this.Description = description;
Expand All @@ -163,10 +163,10 @@ internal Status(CanonicalCode canonicalCode, string description = null)
/// <summary>
/// Gets the status description.
/// </summary>
public string Description { get; }
public string? Description { get; }

/// <summary>
/// Gets a value indicating whether span completed sucessfully.
/// Gets a value indicating whether span completed successfully.
/// </summary>
public bool IsOk
{
Expand Down Expand Up @@ -208,7 +208,7 @@ public override int GetHashCode()
{
var result = 1;
result = (31 * result) + this.CanonicalCode.GetHashCode();
result = (31 * result) + this.Description.GetHashCode();
result = (31 * result) + this.Description?.GetHashCode() ?? 0;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Trace/TracerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static ISpan StartSpan(this ITracer tracer, string operationName, SpanKin
/// <param name="kind">Kind.</param>
/// <param name="options">Advanced span creation options.</param>
/// <returns>Span instance.</returns>
public static ISpan StartSpan(this ITracer tracer, string operationName, SpanKind kind, SpanCreationOptions options)
public static ISpan StartSpan(this ITracer tracer, string operationName, SpanKind kind, SpanCreationOptions? options)
{
return tracer.StartSpan(operationName, null, kind, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Trace/TracerFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void SetDefault(TracerFactoryBase tracerFactory)
/// <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 virtual ITracer GetTracer(string name, string version = null)
public virtual ITracer GetTracer(string? name, string? version = null)
{
return isInitialized ? defaultFactory.GetTracer(name, version) : proxy;
}
Expand Down