Skip to content

Commit

Permalink
PR Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopgrassi committed Oct 9, 2021
1 parent 465af0e commit af86f5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static MeterProviderBuilder AddReader(this MeterProviderBuilder meterProv
public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProviderBuilder, string instrumentName, string name)
{
// we only need to validate the custom view name in case something was actually provided
if (!string.IsNullOrWhiteSpace(name) && !MeterProviderBuilderSdk.IsViewNameValid(name))
if (!string.IsNullOrWhiteSpace(name) && !MeterProviderBuilderSdk.IsValidViewName(name))
{
throw new ArgumentException($"Custom view name {name} is invalid.", nameof(name));
}
Expand All @@ -78,7 +78,7 @@ public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProvid
public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProviderBuilder, string instrumentName, MetricStreamConfiguration metricStreamConfiguration)
{
// we only need to validate the custom view name in case something was actually provided
if (!string.IsNullOrWhiteSpace(metricStreamConfiguration.Name) && !MeterProviderBuilderSdk.IsViewNameValid(metricStreamConfiguration.Name))
if (!string.IsNullOrWhiteSpace(metricStreamConfiguration.Name) && !MeterProviderBuilderSdk.IsValidViewName(metricStreamConfiguration.Name))
{
throw new ArgumentException($"Custom view name {metricStreamConfiguration.Name} is invalid.", nameof(metricStreamConfiguration.Name));
}
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry/Metrics/MeterProviderBuilderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ internal class MeterProviderBuilderSdk : MeterProviderBuilderBase
@"^[a-zA-Z][-.\w]{0,62}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);

/// <summary>
/// Returns whether the given instrument name is valid according with the specification.
/// Returns whether the given instrument name is valid according to the specification.
/// </summary>
/// <remarks>See specification: <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument"/>.</remarks>
/// <param name="instrumentName">The instrument name.</param>
/// <returns>Boolean indicating if the instrument is valid.</returns>
internal static bool IsInstrumentNameValid(string instrumentName)
internal static bool IsValidInstrumentName(string instrumentName)
{
if (string.IsNullOrWhiteSpace(instrumentName))
{
Expand All @@ -40,12 +40,12 @@ internal static bool IsInstrumentNameValid(string instrumentName)
}

/// <summary>
/// Returns whether the given custom view name is valid according with the specification.
/// Returns whether the given custom view name is valid according to the specification.
/// </summary>
/// <remarks>See specification: <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument"/>.</remarks>
/// <param name="customViewName">The view name.</param>
/// <returns>Boolean indicating if the instrument is valid.</returns>
internal static bool IsViewNameValid(string customViewName)
internal static bool IsValidViewName(string customViewName)
{
return InstrumentNameRegex.IsMatch(customViewName);
}
Expand Down
26 changes: 18 additions & 8 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ internal MeterProviderSdk(
var metricStreamConfig = metricStreamConfigs[i];
var metricStreamName = metricStreamConfig?.Name ?? instrument.Name;

if (!MeterProviderBuilderSdk.IsInstrumentNameValid(metricStreamName))
if (!MeterProviderBuilderSdk.IsValidInstrumentName(metricStreamName))
{
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(instrument.Name, instrument.Meter.Name, "Metric name is invalid.", "The name must comply with the OpenTelemetry specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument");
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(
instrument.Name,
instrument.Meter.Name,
"Metric name is invalid.",
"The name must comply with the OpenTelemetry specification.");

continue;
}

Expand Down Expand Up @@ -206,14 +211,19 @@ internal MeterProviderSdk(
{
try
{
if (!MeterProviderBuilderSdk.IsInstrumentNameValid(instrument.Name))
{
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(instrument.Name, instrument.Meter.Name, "Metric name is invalid.", "The name must comply with the OpenTelemetry specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument");
return;
}

if (meterSourcesToSubscribe.ContainsKey(instrument.Meter.Name))
{
if (!MeterProviderBuilderSdk.IsValidInstrumentName(instrument.Name))
{
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(
instrument.Name,
instrument.Meter.Name,
"Metric name is invalid.",
"The name must comply with the OpenTelemetry specification");

return;
}

var metricName = instrument.Name;
Metric metric = null;
lock (this.instrumentCreationLock)
Expand Down

0 comments on commit af86f5e

Please sign in to comment.