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

.NET Framework HttpClient metrics #1

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
17d67e0
snapshot
matt-hensley Sep 15, 2023
800a71d
null actvitiy is tracing is disabled
matt-hensley Sep 15, 2023
4a9239e
setup metics without tracing
matt-hensley Sep 15, 2023
d7b2472
only emit when there is a listener
matt-hensley Sep 15, 2023
46de1a9
modify tests for netfx
matt-hensley Sep 15, 2023
4e445b5
always capture response status code
matt-hensley Sep 18, 2023
f0ca432
Merge branch 'main' into net462httpclientmetricsv3
matt-hensley Sep 18, 2023
bed7b2b
undo conditional extraction
matt-hensley Sep 18, 2023
ba04ac0
activity duration or stopwatch
matt-hensley Sep 18, 2023
48c354a
activity duration or stopwatch
matt-hensley Sep 18, 2023
872ce63
Merge branch 'net462httpclientmetricsv3' of https://github.com/matt-h…
matt-hensley Sep 18, 2023
6999167
activity may be null here
matt-hensley Sep 18, 2023
2c5c034
[OpenTracing.Shim] Remove obsolete constructor (#4862)
Kielek Sep 18, 2023
fc1100f
Move @pellared to emeritus (#4856)
pellared Sep 18, 2023
7eb3e73
Align console logging example with ASP.NET Core logging example (#4855)
reyang Sep 18, 2023
224a4cc
Use dotnet-coverage instead of CodeCoverage.exe (#4857)
Kielek Sep 18, 2023
42e9022
duration -> durationMs for now
matt-hensley Sep 18, 2023
527106f
StartTimestamp handling
matt-hensley Sep 18, 2023
e31f687
adopt taglist
matt-hensley Sep 18, 2023
01840c0
using directive is unnecessary
matt-hensley Sep 18, 2023
9ef2915
using directive is unnecessary
matt-hensley Sep 18, 2023
47fc955
Merge branch 'net462httpclientmetricsv3' of https://github.com/matt-h…
matt-hensley Sep 18, 2023
7cb92d3
[integration test] otlp log exporter (#4854)
vishweshbankwar Sep 18, 2023
d9ca497
remove URL attribute
matt-hensley Sep 18, 2023
308ca8f
status enum to int
matt-hensley Sep 18, 2023
480940e
remove ternary
matt-hensley Sep 19, 2023
27ad5ab
early return if tracing and metrics are not enabled
matt-hensley Sep 19, 2023
025c02d
set activity
matt-hensley Sep 19, 2023
dfaa8f7
Update src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebR…
matt-hensley Sep 19, 2023
ad10683
Merge branch 'net462httpclientmetricsv3' of https://github.com/matt-h…
matt-hensley Sep 19, 2023
8bd64ef
Update src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebR…
matt-hensley Sep 19, 2023
6ca5c9d
Update src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebR…
matt-hensley Sep 19, 2023
61a01f7
Merge branch 'net462httpclientmetricsv3' of https://github.com/matt-h…
matt-hensley Sep 19, 2023
b4dd250
flag name change
matt-hensley Sep 19, 2023
bca1361
remove Moq from test
matt-hensley Sep 19, 2023
5200afb
need to pick context off current activity for propagator to work
matt-hensley Sep 19, 2023
4d15ca6
extra line
matt-hensley Sep 19, 2023
dd07ca0
modify tests to handle metrics and/or tracing on/off
matt-hensley Sep 19, 2023
fc47558
null handling
matt-hensley Sep 19, 2023
9ae0193
null check for safety, tests don't blow up here for some reason?
matt-hensley Sep 20, 2023
9c4c3b5
Merge branch 'main' into net462httpclientmetricsv3
matt-hensley Sep 20, 2023
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
22 changes: 9 additions & 13 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,23 @@ jobs:
- name: Install dependencies
run: dotnet restore

- name: dotnet build
- name: Build
run: dotnet build --configuration Release --no-restore --property:ExposeExperimentalFeatures=true

# - name: dotnet test
# run: dotnet test --collect:"XPlat Code Coverage" --results-directory:"TestResults" --configuration Release --no-build -- RunConfiguration.DisableAppDomain=true
- name: Test
run: dotnet test --collect:"Code Coverage" --results-directory:"TestResults" --configuration Release --no-restore --no-build -- RunConfiguration.DisableAppDomain=true

- name: dotnet test
run: dotnet test --collect:"Code Coverage" --results-directory:"TestResults" --configuration Release --no-build -- RunConfiguration.DisableAppDomain=true

- name: Process code coverage
run: .\build\process-codecoverage.ps1
shell: powershell

- name: Install report tool
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Install coverage tool
run: dotnet tool install -g dotnet-coverage

- name: Merging test results
run: reportgenerator -reports:TestResults/**/*.xml -targetdir:TestResults -reporttypes:Cobertura -assemblyFilters:"-microsoft.data.sqlclient*;-grpc.core*;-opentracing*"
run: dotnet-coverage merge -r -f cobertura -o ./TestResults/Cobertura.xml ./TestResults/*.coverage

- uses: codecov/[email protected]
env:
OS: ${{ matrix.os }}
with:
file: TestResults/Cobertura.xml
env_vars: OS
flags: unittests
name: Code Coverage for ${{ matrix.os }}
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="7.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.9" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23402.2]" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="[17.6.3]" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="2.1.2" />
<PackageVersion Include="Microsoft.DotNet.ApiCompat" Version="6.0.0-beta.21308.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[3.1.6,5.0)" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="3.1.20" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="[6.0.0,)" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="[1.0.3,2.0)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.6.3]" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.7.2,18.0.0)" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="[1.1.1,2.0)" />
<PackageVersion Include="MinVer" Version="[4.3.0,5.0)" />
<PackageVersion Include="Moq" Version="[4.18.4,5.0)" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ If you have trouble accessing the doc, please get in touch on

* [Cijo Thomas](https://github.com/cijothomas), Microsoft
* [Reiley Yang](https://github.com/reyang), Microsoft
* [Robert Paj&#x105;k](https://github.com/pellared), Splunk
* [Vishwesh Bankwar](https://github.com/vishweshbankwar), Microsoft

[Emeritus
Expand All @@ -132,6 +131,7 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma
* [Liudmila Molkova](https://github.com/lmolkova)
* [Mike Goldsmith](https://github.com/MikeGoldsmith)
* [Paulo Janotti](https://github.com/pjanotti)
* [Robert Paj&#x105;k](https://github.com/pellared)
* [Sergey Kanzhelev](https://github.com/SergeyKanzhelev)
* [Victor Lu](https://github.com/victlu)

Expand Down
1 change: 0 additions & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Condition="'$(SkipAnalysis)'!='true'" />
<PackageReference Include="Microsoft.CodeCoverage" PrivateAssets="All" Condition="'$(Configuration)'=='Release'" />
<!--
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Condition="'$(SkipAnalysis)'!='true'" />
-->
Expand Down
16 changes: 0 additions & 16 deletions build/process-codecoverage.ps1

This file was deleted.

40 changes: 0 additions & 40 deletions docs/logs/getting-started-console/FoodSupplyLogs.cs

This file was deleted.

53 changes: 29 additions & 24 deletions docs/logs/getting-started-console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,38 @@
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;

namespace SourceGeneration;

public class Program
using var loggerFactory = LoggerFactory.Create(builder =>
{
public static void Main()
builder.AddOpenTelemetry(logging =>
{
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.IncludeScopes = true;
options.ParseStateValues = true;
options.IncludeFormattedMessage = true;
options.AddConsoleExporter();
});
});
logging.AddConsoleExporter();
});
});

var logger = loggerFactory.CreateLogger<Program>();

var logger = loggerFactory.CreateLogger<Program>();
logger.FoodPriceChanged("artichoke", 9.99);

logger.FoodPriceChanged("artichoke", 9.99);
logger.FoodRecallNotice(
logLevel: LogLevel.Critical,
brandName: "Contoso",
productDescription: "Salads",
productType: "Food & Beverages",
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes",
companyName: "Contoso Fresh Vegetables, Inc.");

public static partial class ApplicationLogs
{
[LoggerMessage(EventId = 1, Level = LogLevel.Information, Message = "Food `{name}` price changed to `{price}`.")]
public static partial void FoodPriceChanged(this ILogger logger, string name, double price);

logger.FoodRecallNotice(
logLevel: LogLevel.Critical,
brandName: "Contoso",
productDescription: "Salads",
productType: "Food & Beverages",
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes",
companyName: "Contoso Fresh Vegetables, Inc.");
}
[LoggerMessage(EventId = 2, Message = "A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).")]
public static partial void FoodRecallNotice(
this ILogger logger,
LogLevel logLevel,
string brandName,
string productDescription,
string productType,
string recallReasonDescription,
string companyName);
}
25 changes: 7 additions & 18 deletions docs/logs/getting-started-console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ package:
dotnet add package OpenTelemetry.Exporter.Console
```

Copy the [FoodSupplyLogs.cs](./FoodSupplyLogs.cs) and [Program.cs](./Program.cs)
files to the project folder.
Update the `Program.cs` file with the code from [Program.cs](./Program.cs).

Run the application again (using `dotnet run`) and you should see the log output
on the console.

```text
LogRecord.Timestamp: 2023-08-03T22:53:51.0194130Z
LogRecord.CategoryName: SourceGeneration.Program
LogRecord.Timestamp: 2023-09-15T06:07:03.5502083Z
LogRecord.CategoryName: Program
LogRecord.Severity: Info
LogRecord.SeverityText: Information
LogRecord.FormattedMessage: Food `artichoke` price changed to `9.99`.
LogRecord.Body: Food `{name}` price changed to `{price}`.
LogRecord.Attributes (Key:Value):
name: artichoke
Expand All @@ -51,17 +49,12 @@ LogRecord.Attributes (Key:Value):
LogRecord.EventId: 1
LogRecord.EventName: FoodPriceChanged

Resource associated with LogRecord:
telemetry.sdk.name: opentelemetry
telemetry.sdk.language: dotnet
telemetry.sdk.version: 1.6.0-alpha.1.55
service.name: unknown_service:getting-started
...

LogRecord.Timestamp: 2023-08-03T22:53:51.0403466Z
LogRecord.CategoryName: SourceGeneration.Program
LogRecord.Timestamp: 2023-09-15T06:07:03.5683511Z
LogRecord.CategoryName: Program
LogRecord.Severity: Fatal
LogRecord.SeverityText: Critical
LogRecord.FormattedMessage: A `Food & Beverages` recall notice was published for `Contoso Salads` produced by `Contoso Fresh Vegetables, Inc.` (due to a possible health risk from Listeria monocytogenes).
LogRecord.Body: A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).
LogRecord.Attributes (Key:Value):
brandName: Contoso
Expand All @@ -73,11 +66,7 @@ LogRecord.Attributes (Key:Value):
LogRecord.EventId: 2
LogRecord.EventName: FoodRecallNotice

Resource associated with LogRecord:
telemetry.sdk.name: opentelemetry
telemetry.sdk.language: dotnet
telemetry.sdk.version: 1.6.0-alpha.1.55
service.name: unknown_service:getting-started
...
```

Congratulations! You are now collecting logs using OpenTelemetry.
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal static object Run(LogsOptions options)
{
processorType = ExportProcessorType.Batch;
}
else if (options.Protocol.Trim().ToLower().Equals("simple"))
else if (options.ProcessorType.Trim().ToLower().Equals("simple"))
{
processorType = ExportProcessorType.Simple;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,46 @@ public static OpenTelemetryLoggerOptions AddOtlpExporter(

configureExporterAndProcessor?.Invoke(exporterOptions, processorOptions);

return AddOtlpLogExporterInternal(
loggerOptions,
exporterOptions: exporterOptions,
processorOptions: processorOptions);
return loggerOptions.AddProcessor(BuildOtlpLogExporter(exporterOptions, processorOptions));
}

private static OpenTelemetryLoggerOptions AddOtlpExporterInternal(
OpenTelemetryLoggerOptions loggerOptions,
Action<OtlpExporterOptions> configure)
{
var exporterOptions = new OtlpExporterOptions();

configure?.Invoke(exporterOptions);

return AddOtlpLogExporterInternal(
loggerOptions,
exporterOptions: exporterOptions,
processorOptions: new());
}

private static OpenTelemetryLoggerOptions AddOtlpLogExporterInternal(
OpenTelemetryLoggerOptions loggerOptions,
internal static BaseProcessor<LogRecord> BuildOtlpLogExporter(
OtlpExporterOptions exporterOptions,
LogRecordExportProcessorOptions processorOptions)
LogRecordExportProcessorOptions processorOptions,
Func<BaseExporter<LogRecord>, BaseExporter<LogRecord>> configureExporterInstance = null)
{
var otlpExporter = new OtlpLogExporter(exporterOptions);
BaseExporter<LogRecord> otlpExporter = new OtlpLogExporter(exporterOptions);

if (configureExporterInstance != null)
{
otlpExporter = configureExporterInstance(otlpExporter);
}

if (processorOptions.ExportProcessorType == ExportProcessorType.Simple)
{
loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(otlpExporter));
return new SimpleLogRecordExportProcessor(otlpExporter);
}
else
{
var batchOptions = processorOptions.BatchExportProcessorOptions;

loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(
return new BatchLogRecordExportProcessor(
otlpExporter,
batchOptions.MaxQueueSize,
batchOptions.ScheduledDelayMilliseconds,
batchOptions.ExporterTimeoutMilliseconds,
batchOptions.MaxExportBatchSize));
batchOptions.MaxExportBatchSize);
}
}

private static OpenTelemetryLoggerOptions AddOtlpExporterInternal(
OpenTelemetryLoggerOptions loggerOptions,
Action<OtlpExporterOptions> configure)
{
var exporterOptions = new OtlpExporterOptions();

configure?.Invoke(exporterOptions);

return loggerOptions;
return loggerOptions.AddProcessor(BuildOtlpLogExporter(exporterOptions, new()));
}
}
Loading