Skip to content

Commit 40e2e4e

Browse files
committed
Merge from main.
2 parents 66b71f6 + 41a3371 commit 40e2e4e

File tree

46 files changed

+292
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+292
-206
lines changed

.github/workflows/code-coverage.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Code Coverage
22

33
on:
4+
push:
5+
branches: [ main, metrics ]
6+
paths-ignore:
7+
- '**.md'
48
pull_request:
59
branches: [ main, metrics ]
610
paths-ignore:
@@ -19,6 +23,8 @@ jobs:
1923

2024
steps:
2125
- uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0 # fetching all
2228

2329
- name: Install dependencies
2430
run: dotnet restore

build/Common.nonprod.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<MicrosoftExtensionsLoggingPkgVer>[5.0.0,6.0)</MicrosoftExtensionsLoggingPkgVer>
3737
<MicrosoftExtensionsLoggingAbstractionsPkgVer>[5.0.0,6.0)</MicrosoftExtensionsLoggingAbstractionsPkgVer>
3838
<MicrosoftExtensionsLoggingConsolePkgVer>[5.0.0,6.0)</MicrosoftExtensionsLoggingConsolePkgVer>
39-
<MicrosoftNETTestSdkPkgVer>[16.9.0-preview-20201020-06]</MicrosoftNETTestSdkPkgVer>
39+
<MicrosoftNETTestSdkPkgVer>[16.9.1]</MicrosoftNETTestSdkPkgVer>
4040
<MoqPkgVer>[4.14.5,5.0)</MoqPkgVer>
4141
<RabbitMQClientPkgVer>[6.1.0,7.0)</RabbitMQClientPkgVer>
4242
<StackExchangeRedisPkgVer>[2.1.58,3.0)</StackExchangeRedisPkgVer>

build/Common.props

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<MicrosoftAspNetCoreHttpFeaturesPkgVer>[2.1.1,6.0)</MicrosoftAspNetCoreHttpFeaturesPkgVer>
3131
<MicrosoftAspNetTelemetryCorrelationPkgVer>[1.0.7,2.0)</MicrosoftAspNetTelemetryCorrelationPkgVer>
3232
<MicrosoftCodeAnalysisAnalyzersPkgVer>[3.3.1]</MicrosoftCodeAnalysisAnalyzersPkgVer>
33-
<MicrosoftCodeCoveragePkgVer>[16.9.0-preview-20201020-06]</MicrosoftCodeCoveragePkgVer>
33+
<MicrosoftCodeCoveragePkgVer>[16.9.1]</MicrosoftCodeCoveragePkgVer>
3434
<MicrosoftExtensionsHostingAbstractionsPkgVer>[2.1.0,6.0)</MicrosoftExtensionsHostingAbstractionsPkgVer>
3535
<MicrosoftExtensionsLoggingPkgVer>[2.1.0,6.0)</MicrosoftExtensionsLoggingPkgVer>
3636
<MicrosoftExtensionsLoggingConfigurationPkgVer>[2.1.0,6.0)</MicrosoftExtensionsLoggingConfigurationPkgVer>
@@ -61,4 +61,25 @@
6161
<PrivateAssets>all</PrivateAssets>
6262
</PackageReference>-->
6363
</ItemGroup>
64+
65+
<ItemGroup Condition="'$(IncludeDiagnosticSourceInstrumentationHelpers)'=='true'">
66+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\ActivityInstrumentationHelper.cs" Link="Includes\ActivityInstrumentationHelper.cs" />
67+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\DiagnosticSourceInstrumentation\DiagnosticSourceListener.cs" Link="Includes\DiagnosticSourceListener.cs" />
68+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\DiagnosticSourceInstrumentation\DiagnosticSourceSubscriber.cs" Link="Includes\DiagnosticSourceSubscriber.cs" />
69+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\DiagnosticSourceInstrumentation\InstrumentationEventSource.cs" Link="Includes\InstrumentationEventSource.cs" />
70+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\DiagnosticSourceInstrumentation\ListenerHandler.cs" Link="Includes\ListenerHandler.cs" />
71+
<Compile Include="$(RepoRoot)\src\OpenTelemetry\DiagnosticSourceInstrumentation\PropertyFetcher.cs" Link="Includes\PropertyFetcher.cs" />
72+
</ItemGroup>
73+
74+
<ItemGroup Condition="'$(IncludeInstrumentationHelpers)'=='true' Or '$(IncludeDiagnosticSourceInstrumentationHelpers)'=='true'">
75+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ActivityHelperExtensions.cs" Link="Includes\ActivityHelperExtensions.cs" />
76+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\EnumerationHelper.cs" Link="Includes\EnumerationHelper.cs" />
77+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
78+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\IActivityEnumerator.cs" Link="Includes\IActivityEnumerator.cs" />
79+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\SemanticConventions.cs" Link="Includes\SemanticConventions.cs" />
80+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\SpanAttributeConstants.cs" Link="Includes\SpanAttributeConstants.cs" />
81+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\SpanHelper.cs" Link="Includes\SpanHelper.cs" />
82+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\StatusHelper.cs" Link="Includes\StatusHelper.cs" />
83+
</ItemGroup>
84+
6485
</Project>

build/process-codecoverage.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Write-Host $env:USERPROFILE
33
foreach ($file in $files)
44
{
5-
$command = $env:USERPROFILE+ '\.nuget\packages\microsoft.codecoverage\16.9.0-preview-20201020-06\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:' + $file.DirectoryName + '\' + $file.Name + '.xml '+ $file.FullName
5+
$command = $env:USERPROFILE+ '\.nuget\packages\microsoft.codecoverage\16.9.1\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:' + $file.DirectoryName + '\' + $file.Name + '.xml '+ $file.FullName
66
Write-Host $command
77
Invoke-Expression $command
88
}

docs/Directory.Build.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax.
1616
-->
1717
<MicrosoftExtensionsLoggingPkgVer>[5.0.0,6.0)</MicrosoftExtensionsLoggingPkgVer>
18-
<OpenTelemetryExporterConsolePkgVer>[0.4.0-beta.2,1.0)</OpenTelemetryExporterConsolePkgVer>
19-
<OpenTelemetryPkgVer>[0.4.0-beta.2,1.0)</OpenTelemetryPkgVer>
2018
</PropertyGroup>
2119
</Project>

docs/logs/extending-the-sdk/MyExporter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ public override ExportResult Export(in Batch<LogRecord> batch)
4242
sb.Append(", ");
4343
}
4444

45-
sb.Append($"{record}");
45+
sb.Append($"{record}(");
46+
47+
record.ForEachScope(ProcessScope, sb);
48+
49+
static void ProcessScope(object scope, StringBuilder builder)
50+
=> builder.Append($"{scope}");
51+
52+
sb.Append($")");
4653
}
4754

4855
Console.WriteLine($"{this.name}.Export([{sb.ToString()}])");

docs/logs/extending-the-sdk/Program.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ public static void Main()
3131
#else
3232
using var loggerFactory = LoggerFactory.Create(builder =>
3333
#endif
34-
{
35-
builder.AddOpenTelemetry(options => options
36-
.AddProcessor(new MyProcessor("ProcessorA"))
37-
.AddProcessor(new MyProcessor("ProcessorB"))
38-
.AddProcessor(new SimpleLogRecordExportProcessor(new MyExporter("ExporterX")))
39-
.AddMyExporter());
40-
});
34+
builder.AddOpenTelemetry(options =>
35+
{
36+
options.IncludeScopes = true;
37+
options.AddProcessor(new MyProcessor("ProcessorA"))
38+
.AddProcessor(new MyProcessor("ProcessorB"))
39+
.AddProcessor(new SimpleLogRecordExportProcessor(new MyExporter("ExporterX")))
40+
.AddMyExporter();
41+
}));
4142

4243
#if NETCOREAPP2_1
4344
using var serviceProvider = serviceCollection.BuildServiceProvider();
@@ -67,6 +68,13 @@ public static void Main()
6768
["Name"] = "truffle",
6869
["Price"] = 299.99,
6970
});
71+
72+
// log with scopes
73+
using (logger.BeginScope("[operation]"))
74+
using (logger.BeginScope("[hardware]"))
75+
{
76+
logger.LogError("{name} is broken.", "refrigerator");
77+
}
7078
}
7179

7280
internal struct Food

docs/logs/extending-the-sdk/extending-the-sdk.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
4-
</PropertyGroup>
5-
62
<ItemGroup>
73
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
84
</ItemGroup>

docs/logs/getting-started/getting-started.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
4-
</PropertyGroup>
5-
62
<ItemGroup>
73
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
84
</ItemGroup>

docs/trace/extending-the-sdk/README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ the library they instrument, and steps for enabling them.
9393
client](../../../src/OpenTelemetry.Instrumentation.StackExchangeRedis/README.md)
9494
* [SQL client](../../../src/OpenTelemetry.Instrumentation.SqlClient/README.md)
9595

96+
More community contributed instrumentations are available in [OpenTelemetry .NET
97+
Contrib](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src).
98+
If you are writing an instrumentation library yourself, use the following
99+
guidelines.
100+
96101
### Writing own instrumentation library
97102

98103
This section describes the steps required to write your own instrumentation
@@ -158,20 +163,29 @@ Writing an instrumentation library typically involves 3 steps.
158163
the instrumented library must be documented so that end users can enable
159164
it using `AddSource` method on `TracerProviderBuilder`.
160165

161-
There is a special case for libraries which are already instrumented with
166+
### Special case : Instrumentation for libraries producing legacy Activity
167+
168+
There is a special case for libraries which are already instrumented to produce
162169
[Activity](https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md),
163170
but using the
164171
[DiagnosticSource](https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md)
165-
method. These libraries already emit activities, but it may not conform to the
166-
OpenTelemetry semantic conventions. Also, as these libraries do not use
167-
ActivitySource to create Activity, they cannot be simply subscribed to. In such
168-
cases, the instrumentation library should subscribe to the DiagnosticSource
169-
events from the instrumented library, and in turn produce *new* activity using
170-
ActivitySource. This new activity must be created as a sibling of the activity
171-
already produced by the library. i.e the new activity must have the same parent
172-
as the original activity. Some common examples of such libraries include
173-
Asp.Net, Asp.Net Core, HttpClient (.NET Core). Instrumentation libraries for
174-
these are already provided in this repo.
172+
method. These are referred to as "legacy Activity" in this repo. These libraries
173+
already create activities but they do so by using the `Activity` constructor
174+
directly, rather than using `ActivitySource.StartActivity` method. These
175+
activities does not by default runs though the samplers, and will have their
176+
`Kind` set to internal and they'll have empty ActivitySource name associated
177+
with it.
178+
179+
Some common examples of such libraries include ASP.NET, ASP.NET Core, HttpClient
180+
(.NET Core). Instrumentation libraries for these are already provided in this
181+
repo. The OpenTelemetry .NET Contrib Repo also has instrumentations for
182+
libraries like
183+
[ElasticSearch](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Contrib.Instrumentation.Elasticsearch),
184+
[EntityFramework](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Contrib.Instrumentation.EntityFrameworkCore)
185+
etc. which fall in this category.
186+
187+
If you are writing instrumentation for such library, it is recommended to refer
188+
to one of the above as a reference.
175189

176190
## Processor
177191

0 commit comments

Comments
 (0)