Skip to content

Commit

Permalink
Fix indentation (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
reyang committed Nov 24, 2021
1 parent 0b023a6 commit f7c718e
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 153 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
###############################
# All files
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
# Code files
[*.cs]
[*.{cs,cshtml,htm,html,md,py,sln,xml}]
indent_size = 4
charset = utf-8
###############################
# .NET Coding Conventions #
###############################
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ helper methods.
in each framework that you target.
* Add the following lines to your csproj:

<!-- markdownlint-disable MD013 -->
```xml
<ItemGroup>
<AdditionalFiles
Include=".publicApi\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles
Include=".publicApi\$(TargetFramework)\PublicAPI.Unshipped.txt" />
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Unshipped.txt" />
</ItemGroup>
```
<!-- markdownlint-enable MD013 -->

* Use
[IntelliSense](https://docs.microsoft.com/visualstudio/ide/using-intellisense)
Expand Down
44 changes: 27 additions & 17 deletions build/sanitycheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
CRLF = b'\r\n'
LF = b'\n'

def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF)):
def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF), indent = 1):
error_count = 0

for filename in glob.glob(pattern, recursive=True):
Expand All @@ -26,6 +26,8 @@ def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF)):
for line in content.splitlines(True):
if allow_utf8 and lineno == 1 and line.startswith(b'\xef\xbb\xbf'):
line = line[3:]
if any(b == 7 for b in line):
error.append(' TAB found at Ln:{} {}'.format(lineno, line))
if any(b > 127 for b in line):
error.append(' Non-ASCII character found at Ln:{} {}'.format(lineno, line))
if line[-2:] == CRLF:
Expand All @@ -47,6 +49,14 @@ def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF)):
if eol not in allow_eol:
error.append(' Line ending {} not allowed at Ln:{}'.format(eol, lineno))
break
if line.startswith(b' '):
spc_count = 0
for c in line:
if c != 32:
break
spc_count += 1
if not indent or spc_count % indent:
error.append(' {} SPC found at Ln:{} {}'.format(spc_count, lineno, line))
if line[-1:] == b' ' or line[-1:] == b'\t':
error.append(' Trailing space found at Ln:{} {}'.format(lineno, line))
lineno += 1
Expand All @@ -62,23 +72,23 @@ def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF)):
return error_count

retval = 0
retval += sanitycheck('.editorconfig', allow_eol = (LF,))
retval += sanitycheck('**/Dockerfile', allow_eol = (LF,))
retval += sanitycheck('**/*.cmd', allow_eol = (CRLF,))
retval += sanitycheck('**/*.config', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('.editorconfig', allow_eol = (LF,), indent = 0)
retval += sanitycheck('**/Dockerfile', allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.cmd', allow_eol = (CRLF,), indent = 2)
retval += sanitycheck('**/*.config', allow_utf8 = True, allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.cs', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('**/*.cshtml', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('**/*.csproj', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('**/*.htm', allow_eol = (LF,))
retval += sanitycheck('**/*.html', allow_eol = (LF,))
retval += sanitycheck('**/*.cshtml', allow_utf8 = True, allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.csproj', allow_utf8 = True, allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.htm', allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.html', allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.md', allow_eol = (LF,))
retval += sanitycheck('**/*.proj', allow_eol = (LF,))
retval += sanitycheck('**/*.props', allow_eol = (LF,))
retval += sanitycheck('**/*.py', allow_eol = (LF,))
retval += sanitycheck('**/*.ruleset', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('**/*.sln', allow_utf8 = True, allow_eol = (LF,))
retval += sanitycheck('**/*.targets', allow_eol = (LF,))
retval += sanitycheck('**/*.xml', allow_eol = (LF,))
retval += sanitycheck('**/*.yml', allow_eol = (LF,))
retval += sanitycheck('**/*.proj', allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.props', allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.py', allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.ruleset', allow_utf8 = True, allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.sln', allow_utf8 = True, allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.targets', allow_eol = (LF,), indent = 2)
retval += sanitycheck('**/*.xml', allow_eol = (LF,), indent = 4)
retval += sanitycheck('**/*.yml', allow_eol = (LF,), indent = 2)

sys.exit(retval)
18 changes: 9 additions & 9 deletions docs/metrics/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public static void Main(string[] args)

// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&
instrument.GetType().Name.Contains("Histogram"))
{
return new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
}
return null;
})
{
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&
instrument.GetType().Name.Contains("Histogram"))
{
return new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
}
return null;
})

// An instrument which does not match any views
// gets processed with default behavior. (SDK default)
Expand Down
166 changes: 84 additions & 82 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ particularly useful if there are conflicting instrument names, and you do not
own the instrument to create it with a different name.

```csharp
// Rename an instrument to new name.
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")
// Rename an instrument to new name.
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")
```

```csharp
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
instrument.Name == "MyCounter")
{
{
return new MetricStreamConfiguration() { Name = "MyCounterRenamed" };
}
}

return null;
})
return null;
})
```

#### Drop an instrument
Expand All @@ -145,22 +145,22 @@ instrument from a Meter. If the goal is to drop every instrument from a `Meter`,
then it is recommended to simply not add that `Meter` using `AddMeter`.

```csharp
// Drop the instrument "MyCounterDrop".
.AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop)
// Drop the instrument "MyCounterDrop".
.AddView(instrumentName: "MyCounterDrop", MetricStreamConfiguration.Drop)
```

```csharp
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
instrument.Name == "MyCounterDrop")
{
{
return MetricStreamConfiguration.Drop;
}
}

return null;
})
return null;
})
```

#### Select specific tags
Expand All @@ -173,52 +173,52 @@ with the metric are of interest to you.

```csharp
// Only choose "name" as the dimension for the metric "MyFruitCounter"
.AddView(
instrumentName: "MyFruitCounter",
metricStreamConfiguration: new MetricStreamConfiguration
{
TagKeys = new string[] { "name" },
})

...
// Only the dimension "name" is selected, "color" is dropped
MyFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow"));
MyFruitCounter.Add(2, new("name", "apple"), new("color", "green"));
...

// If you provide an empty `string` array as `TagKeys` to the `MetricStreamConfiguration`
// the SDK will drop all the dimensions associated with the metric
.AddView(
instrumentName: "MyFruitCounter",
metricStreamConfiguration: new MetricStreamConfiguration
{
TagKeys = new string[] { },
})

...
// both "name" and "color" are dropped
MyFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow"));
MyFruitCounter.Add(2, new("name", "apple"), new("color", "green"));
...
.AddView(
instrumentName: "MyFruitCounter",
metricStreamConfiguration: new MetricStreamConfiguration
{
TagKeys = new string[] { "name" },
})

...
// Only the dimension "name" is selected, "color" is dropped
MyFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow"));
MyFruitCounter.Add(2, new("name", "apple"), new("color", "green"));
...

// If you provide an empty `string` array as `TagKeys` to the `MetricStreamConfiguration`
// the SDK will drop all the dimensions associated with the metric
.AddView(
instrumentName: "MyFruitCounter",
metricStreamConfiguration: new MetricStreamConfiguration
{
TagKeys = new string[] { },
})

...
// both "name" and "color" are dropped
MyFruitCounter.Add(1, new("name", "apple"), new("color", "red"));
MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow"));
MyFruitCounter.Add(2, new("name", "apple"), new("color", "green"));
...
```

```csharp
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
instrument.Name == "MyFruitCounter")
{
{
return new MetricStreamConfiguration
{
TagKeys = new string[] { "name" },
TagKeys = new string[] { "name" },
};
}
}

return null;
})
return null;
})
```

#### Specify custom boundaries for Histogram
Expand All @@ -229,41 +229,43 @@ By default, the boundaries used for a Histogram are [`{ 0, 5, 10, 25, 50, 75, 10
Views can be used to provide custom boundaries for a Histogram. The measurements
are then aggregated using the custom boundaries provided instead of the the
default boundaries. This requires the use of `ExplicitBucketHistogramConfiguration`.
[Monday 08:36 PM] Reiley Yang

<!-- markdownlint-disable MD013 -->
```csharp
// Change Histogram boundaries to count measurements under the following buckets:
// (-inf, 10]
// (10, 20]
// (20, +inf)
.AddView(
instrumentName: "MyHistogram",
new ExplicitBucketHistogramConfiguration
{ Boundaries = new double[] { 10, 20 } })

// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
// the SDK will only export the sum and count for the measurements.
// There are no buckets exported in this case.
.AddView(
instrumentName: "MyHistogram",
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { } })
// Change Histogram boundaries to count measurements under the following buckets:
// (-inf, 10]
// (10, 20]
// (20, +inf)
.AddView(
instrumentName: "MyHistogram",
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { 10, 20 } })

// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
// the SDK will only export the sum and count for the measurements.
// There are no buckets exported in this case.
.AddView(
instrumentName: "MyHistogram",
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { } })
```
<!-- markdownlint-enable MD013 -->

```csharp
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
// Advanced selection criteria and config via Func<Instrument, MetricStreamConfiguration>
.AddView((instrument) =>
{
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
instrument.Name == "MyHistogram")
{
{
// `ExplicitBucketHistogramConfiguration` is a child class of `MetricStreamConfiguration`
return new ExplicitBucketHistogramConfiguration
{
Boundaries = new double[] { 10, 20 },
Boundaries = new double[] { 10, 20 },
};
}
}

return null;
})
return null;
})
```

**NOTE:** The SDK currently does not support any changes to `Aggregation` type
Expand Down
14 changes: 7 additions & 7 deletions docs/trace/extending-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ When using such a filtering processor, instead of using extension method to
register the exporter, they must be registered manually as shown below:

```csharp
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new MySampler())
.AddSource("OTel.Demo")
.AddProcessor(new MyFilteringProcessor(
new SimpleActivityExportProcessor(new MyExporter("ExporterX")),
(act) => true))
.Build();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new MySampler())
.AddSource("OTel.Demo")
.AddProcessor(new MyFilteringProcessor(
new SimpleActivityExportProcessor(new MyExporter("ExporterX")),
(act) => true))
.Build();
```

Most [instrumentation libraries](#instrumentation-library) shipped from this
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Exporter.Jaeger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ built-in `AddHttpClient` extension:
```csharp
services.AddHttpClient(
"JaegerExporter",
configureClient: (client) =>
configureClient: (client) =>
client.DefaultRequestHeaders.Add("X-MyCustomHeader", "value"));
```

Expand Down
Loading

0 comments on commit f7c718e

Please sign in to comment.