Skip to content

Commit

Permalink
Merge branch 'main' into ssl-check
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest authored Dec 16, 2021
2 parents f8c3668 + fd2aa0b commit b7446aa
Show file tree
Hide file tree
Showing 28 changed files with 50 additions and 92 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ On all platforms, the minimum requirements are:

### Linux or MacOS

* Visual Studio for Mac or Visual Studio Code
* Visual Studio 2022+ for Mac or Visual Studio Code

Mono might be required by your IDE but is not required by this project. This is
because unit tests targeting .NET Framework (i.e: `net461`) are disabled outside
of Windows.

### Windows

* Visual Studio 2017+ or Visual Studio Code
* Visual Studio 2022+ or Visual Studio Code
* .NET Framework 4.6.1+

### Public API
Expand Down
1 change: 0 additions & 1 deletion docs/metrics/extending-the-sdk/MyExporterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System;
using OpenTelemetry;
using OpenTelemetry.Metrics;

internal static class MyExporterExtensions
Expand Down
1 change: 0 additions & 1 deletion examples/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using CommandLine;
using OpenTelemetry.Exporter;

namespace Examples.Console
{
Expand Down
6 changes: 1 addition & 5 deletions examples/Console/TestLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;

namespace Examples.Console
Expand All @@ -33,7 +29,7 @@ internal static object Run(LogsOptions options)
builder.AddOpenTelemetry((opt) =>
{
opt.IncludeFormattedMessage = true;
if (options.UseExporter.ToLower() == "otlp")
if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase))
{
/*
* Prerequisite to run this example:
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static object Run(MetricsOptions options)
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("myservice"))
.AddMeter(meter.Name); // All instruments from this meter are enabled.

if (options.UseExporter.ToLower() == "otlp")
if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase))
{
/*
* Prerequisite to run this example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override ExportResult Export(in Batch<Metric> batch)

Console.WriteLine(msg.ToString());

foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
string valueDisplay = string.Empty;
StringBuilder tagsBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
sum.IsMonotonic = true;
sum.AggregationTemporality = temporality;

foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var dataPoint = new OtlpMetrics.NumberDataPoint
{
Expand All @@ -172,7 +172,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
sum.IsMonotonic = true;
sum.AggregationTemporality = temporality;

foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var dataPoint = new OtlpMetrics.NumberDataPoint
{
Expand All @@ -193,7 +193,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
case MetricType.LongGauge:
{
var gauge = new OtlpMetrics.Gauge();
foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var dataPoint = new OtlpMetrics.NumberDataPoint
{
Expand All @@ -214,7 +214,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
case MetricType.DoubleGauge:
{
var gauge = new OtlpMetrics.Gauge();
foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var dataPoint = new OtlpMetrics.NumberDataPoint
{
Expand All @@ -237,7 +237,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
var histogram = new OtlpMetrics.Histogram();
histogram.AggregationTemporality = temporality;

foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var dataPoint = new OtlpMetrics.HistogramDataPoint
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)

if (!metric.MetricType.IsHistogram())
{
foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var tags = metricPoint.Tags;
var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds();
Expand All @@ -52,18 +52,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
{
buffer[cursor++] = unchecked((byte)'{');

int i = 0;
foreach (var tag in tags)
{
if (i++ > 0)
{
buffer[cursor++] = unchecked((byte)',');
}

cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value);
buffer[cursor++] = unchecked((byte)',');
}

buffer[cursor++] = unchecked((byte)'}');
buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra.
}

buffer[cursor++] = unchecked((byte)' ');
Expand Down Expand Up @@ -103,7 +98,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
}
else
{
foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var tags = metricPoint.Tags;
var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds();
Expand Down Expand Up @@ -151,18 +146,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
{
buffer[cursor++] = unchecked((byte)'{');

int i = 0;
foreach (var tag in tags)
{
if (i++ > 0)
{
buffer[cursor++] = unchecked((byte)',');
}

cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value);
buffer[cursor++] = unchecked((byte)',');
}

buffer[cursor++] = unchecked((byte)'}');
buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra.
}

buffer[cursor++] = unchecked((byte)' ');
Expand All @@ -182,18 +172,13 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
{
buffer[cursor++] = unchecked((byte)'{');

int i = 0;
foreach (var tag in tags)
{
if (i++ > 0)
{
buffer[cursor++] = unchecked((byte)',');
}

cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value);
buffer[cursor++] = unchecked((byte)',');
}

buffer[cursor++] = unchecked((byte)'}');
buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra.
}

buffer[cursor++] = unchecked((byte)' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Exporter
{
Expand Down Expand Up @@ -65,10 +66,7 @@ public int ScrapeResponseCacheDurationMilliseconds
get => this.scrapeResponseCacheDurationMilliseconds;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "Value should be greater than or equal to zero.");
}
Guard.Range(value, nameof(value), min: 0);

this.scrapeResponseCacheDurationMilliseconds = value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Exporter.Zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ take precedence over the environment variables.
instance that will be used at runtime to transmit spans over HTTP. See
[Configure HttpClient](#configure-httpclient) for more details.

* `MaxPayloadSizeInBytes`: Maximum payload size - for .NET versions **other**
than 4.5.2 (default 4096).
* `MaxPayloadSizeInBytes`: Maximum payload size of UTF8 JSON chunks sent to
Zipkin (default 4096).

* `ServiceName`: Name of the service reporting telemetry. If the `Resource`
associated with the telemetry has "service.name" defined, then it'll be
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* Fixed an issue with `Filter` and `Enrich` callbacks not firing under certain
conditions when gRPC is used
([#2698](https://github.com/open-telemetry/opentelemetry-dotnet/issues/2698))
([#2698](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2698))

## 1.0.0-rc8

Expand Down
7 changes: 1 addition & 6 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ internal AggregatorStore(
{
this.updateLongCallback = this.UpdateLongCustomTags;
this.updateDoubleCallback = this.UpdateDoubleCustomTags;
var hs = new HashSet<string>(StringComparer.Ordinal);
foreach (var key in tagKeysInteresting)
{
hs.Add(key);
}

var hs = new HashSet<string>(tagKeysInteresting, StringComparer.Ordinal);
this.tagKeysInteresting = hs;
this.tagsKeysInterestingCount = hs.Count;
}
Expand Down
7 changes: 1 addition & 6 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ internal MeterProviderSdk(
}
else if (meterSources.Any())
{
var meterSourcesToSubscribe = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var meterSource in meterSources)
{
meterSourcesToSubscribe.Add(meterSource);
}

var meterSourcesToSubscribe = new HashSet<string>(meterSources, StringComparer.OrdinalIgnoreCase);
shouldListenTo = instrument => meterSourcesToSubscribe.Contains(instrument.Meter.Name);
}

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Metrics/MetricPointsAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal Enumerator(MetricPoint[] metricsPoints, int[] metricPointsToProcess, lo
/// <summary>
/// Gets the <see cref="MetricPoint"/> at the current position of the enumerator.
/// </summary>
public ref MetricPoint Current
public ref readonly MetricPoint Current
{
get
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class TracerProviderBuilderBase : TracerProviderBuilder
private readonly List<InstrumentationFactory> instrumentationFactories = new List<InstrumentationFactory>();
private readonly List<BaseProcessor<Activity>> processors = new List<BaseProcessor<Activity>>();
private readonly List<string> sources = new List<string>();
private readonly Dictionary<string, bool> legacyActivityOperationNames = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> legacyActivityOperationNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private ResourceBuilder resourceBuilder = ResourceBuilder.CreateDefault();
private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler());

Expand Down Expand Up @@ -76,7 +76,7 @@ public override TracerProviderBuilder AddLegacySource(string operationName)
{
Guard.NullOrWhitespace(operationName, nameof(operationName));

this.legacyActivityOperationNames[operationName] = true;
this.legacyActivityOperationNames.Add(operationName);

return this;
}
Expand Down
15 changes: 5 additions & 10 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal TracerProviderSdk(
IEnumerable<TracerProviderBuilderBase.InstrumentationFactory> instrumentationFactories,
Sampler sampler,
List<BaseProcessor<Activity>> processors,
Dictionary<string, bool> legacyActivityOperationNames)
HashSet<string> legacyActivityOperationNames)
{
this.Resource = resource;
this.sampler = sampler;
Expand All @@ -53,10 +53,10 @@ internal TracerProviderSdk(
Regex legacyActivityWildcardModeRegex = null;
foreach (var legacyName in legacyActivityOperationNames)
{
if (legacyName.Key.Contains('*'))
if (legacyName.Contains('*'))
{
legacyActivityWildcardMode = true;
legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames.Keys);
legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames);
break;
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ internal TracerProviderSdk(
}
else
{
legacyActivityPredicate = activity => legacyActivityOperationNames.ContainsKey(activity.OperationName);
legacyActivityPredicate = activity => legacyActivityOperationNames.Contains(activity.OperationName);
}

listener.ActivityStarted = activity =>
Expand Down Expand Up @@ -242,12 +242,7 @@ internal TracerProviderSdk(
}
else
{
var activitySources = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var name in sources)
{
activitySources.Add(name);
}
var activitySources = new HashSet<string>(sources, StringComparer.OrdinalIgnoreCase);

if (this.supportLegacyActivity)
{
Expand Down
2 changes: 0 additions & 2 deletions test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

extern alias Prometheus;

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.IO;
using BenchmarkDotNet.Attributes;
using OpenTelemetry;
using OpenTelemetry.Metrics;
Expand Down
2 changes: 1 addition & 1 deletion test/Benchmarks/Metrics/MetricCollectBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ProcessExport(Batch<Metric> batch)
if (this.UseWithRef)
{
// The performant way of iterating.
foreach (ref var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
sum += metricPoint.GetSumDouble();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
using System.Linq;
using System.Net.Http;
using System.Threading;
#if !NET5_0_OR_GREATER
using System.Threading.Tasks;
#endif
using Moq;
using Moq.Protected;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override string GetUnknownRequestHeader(string name)

public override string GetKnownRequestHeader(int index)
{
var name = HttpWorkerRequest.GetKnownRequestHeaderName(index);
var name = GetKnownRequestHeaderName(index);

if (this.headers.ContainsKey(name))
{
Expand Down
Loading

0 comments on commit b7446aa

Please sign in to comment.