Fix indentation (#2680)
This commit is contained in:
parent
0b023a6cd1
commit
f7c718eae0
|
|
@ -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 #
|
||||
###############################
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ CR = b'\r'
|
|||
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):
|
||||
|
|
@ -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:
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -44,15 +44,15 @@ public class Program
|
|||
|
||||
// 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 } };
|
||||
}
|
||||
{
|
||||
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&
|
||||
instrument.GetType().Name.Contains("Histogram"))
|
||||
{
|
||||
return new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
return null;
|
||||
})
|
||||
|
||||
// An instrument which does not match any views
|
||||
// gets processed with default behavior. (SDK default)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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" },
|
||||
})
|
||||
.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"));
|
||||
...
|
||||
...
|
||||
// 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[] { },
|
||||
})
|
||||
// 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"));
|
||||
...
|
||||
...
|
||||
// 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
|
||||
|
|
@ -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 } })
|
||||
// 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[] { } })
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ built-in `AddHttpClient` extension:
|
|||
```csharp
|
||||
services.AddHttpClient(
|
||||
"JaegerExporter",
|
||||
configureClient: (client) =>
|
||||
configureClient: (client) =>
|
||||
client.DefaultRequestHeaders.Add("X-MyCustomHeader", "value"));
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -43,11 +43,10 @@ using OpenTelemetry.Trace;
|
|||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddOpenTelemetryTracing(
|
||||
(builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddJaegerExporter()
|
||||
);
|
||||
services.AddOpenTelemetryTracing((builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddJaegerExporter()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -65,19 +64,18 @@ method of you applications `Startup` class as shown below.
|
|||
```csharp
|
||||
// Configure
|
||||
services.Configure<AspNetCoreInstrumentationOptions>(options =>
|
||||
{
|
||||
options.Filter = (httpContext) =>
|
||||
{
|
||||
// only collect telemetry about HTTP GET requests
|
||||
return httpContext.Request.Method.Equals("GET");
|
||||
};
|
||||
});
|
||||
{
|
||||
options.Filter = (httpContext) =>
|
||||
{
|
||||
// only collect telemetry about HTTP GET requests
|
||||
return httpContext.Request.Method.Equals("GET");
|
||||
};
|
||||
});
|
||||
|
||||
services.AddOpenTelemetryTracing(
|
||||
(builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddJaegerExporter()
|
||||
);
|
||||
services.AddOpenTelemetryTracing((builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddJaegerExporter()
|
||||
);
|
||||
```
|
||||
|
||||
### Filter
|
||||
|
|
@ -93,17 +91,14 @@ The following code snippet shows how to use `Filter` to only allow GET
|
|||
requests.
|
||||
|
||||
```csharp
|
||||
services.AddOpenTelemetryTracing(
|
||||
(builder) => builder
|
||||
.AddAspNetCoreInstrumentation(
|
||||
(options) => options.Filter =
|
||||
(httpContext) =>
|
||||
{
|
||||
// only collect telemetry about HTTP GET requests
|
||||
return httpContext.Request.Method.Equals("GET");
|
||||
})
|
||||
services.AddOpenTelemetryTracing((builder) => builder
|
||||
.AddAspNetCoreInstrumentation((options) => options.Filter = httpContext =>
|
||||
{
|
||||
// only collect telemetry about HTTP GET requests
|
||||
return httpContext.Request.Method.Equals("GET");
|
||||
})
|
||||
.AddJaegerExporter()
|
||||
);
|
||||
);
|
||||
```
|
||||
|
||||
It is important to note that this `Filter` option is specific to this
|
||||
|
|
@ -126,8 +121,7 @@ The following code snippet shows how to add additional tags using `Enrich`.
|
|||
```csharp
|
||||
services.AddOpenTelemetryTracing((builder) =>
|
||||
{
|
||||
builder
|
||||
.AddAspNetCoreInstrumentation((options) => options.Enrich
|
||||
builder.AddAspNetCoreInstrumentation((options) => options.Enrich
|
||||
= (activity, eventName, rawObject) =>
|
||||
{
|
||||
if (eventName.Equals("OnStartActivity"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue