Skip to content

Commit

Permalink
Merge branch 'main' into jamesnk/connection-metrics-buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Nov 3, 2023
2 parents 65b0386 + c8f939e commit 2d59aec
Show file tree
Hide file tree
Showing 44 changed files with 1,056 additions and 325 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/dotnet-format-md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ name: dotnet format
on:
pull_request:
branches: [ 'main*' ]
paths-ignore:
- '**.cs'
- '.editorconfig'
paths:
- '**.md'

jobs:
check-format:
check-format-stable:
runs-on: ubuntu-latest

steps:
- run: 'echo "No build required"'

check-format-experimental:
runs-on: ubuntu-latest

steps:
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- '.editorconfig'

jobs:
check-format:
check-format-stable:
runs-on: windows-latest

steps:
Expand All @@ -23,8 +23,28 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v3

- name: Install format tool
run: dotnet tool install -g dotnet-format
- name: dotnet restore
run: dotnet restore

- name: dotnet format
run: dotnet-format --folder --check
run: dotnet format OpenTelemetry.sln --no-restore --verify-no-changes
env:
ExposeExperimentalFeatures: false

check-format-experimental:
runs-on: windows-latest

steps:
- name: check out code
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v3

- name: dotnet restore
run: dotnet restore

- name: dotnet format
run: dotnet format OpenTelemetry.sln --no-restore --verify-no-changes
env:
ExposeExperimentalFeatures: true
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
-->
<!-- 'net7.0' is the default `TargetFramework`. Use `VersionOverride` in the project to override the package versions from a different `TargetFramework` -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="[0.13.6,0.14)" />
<PackageVersion Include="BenchmarkDotNet" Version="[0.13.10,0.14)" />
<PackageVersion Include="CommandLineParser" Version="[2.9.1,3.0)" />
<PackageVersion Include="Grpc.AspNetCore" Version="[2.55.0,3.0)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.55.0, 3.0)" />
Expand Down
10 changes: 9 additions & 1 deletion OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEM
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{E69578EB-B456-4062-A645-877CD964528B}"
ProjectSection(SolutionItems) = preProject
.github\workflows\ci-aot.yml = .github\workflows\ci-aot.yml
.github\workflows\ci-aot-md.yml = .github\workflows\ci-aot-md.yml
.github\workflows\ci-aot.yml = .github\workflows\ci-aot.yml
.github\workflows\ci-instrumentation-libraries-md.yml = .github\workflows\ci-instrumentation-libraries-md.yml
.github\workflows\ci-instrumentation-libraries.yml = .github\workflows\ci-instrumentation-libraries.yml
.github\workflows\ci-md.yml = .github\workflows\ci-md.yml
Expand Down Expand Up @@ -269,6 +269,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A49299
src\Shared\PeriodicExportingMetricReaderHelper.cs = src\Shared\PeriodicExportingMetricReaderHelper.cs
src\Shared\PooledList.cs = src\Shared\PooledList.cs
src\Shared\ResourceSemanticConventions.cs = src\Shared\ResourceSemanticConventions.cs
src\Shared\RequestMethodHelper.cs = src\Shared\RequestMethodHelper.cs
src\Shared\SemanticConventions.cs = src\Shared\SemanticConventions.cs
src\Shared\SpanAttributeConstants.cs = src\Shared\SpanAttributeConstants.cs
src\Shared\SpanHelper.cs = src\Shared\SpanHelper.cs
Expand Down Expand Up @@ -315,6 +316,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metrics", "Metrics", "{1C45
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-aspnetcore", "docs\logs\getting-started-aspnetcore\getting-started-aspnetcore.csproj", "{99B4D965-8782-4694-8DFA-B7A3630CEF60}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "links-creation", "docs\trace\links-creation-with-new-activities\links-creation.csproj", "{B4856711-6D4C-4246-A686-49458D4C1301}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -589,6 +592,10 @@ Global
{99B4D965-8782-4694-8DFA-B7A3630CEF60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99B4D965-8782-4694-8DFA-B7A3630CEF60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99B4D965-8782-4694-8DFA-B7A3630CEF60}.Release|Any CPU.Build.0 = Release|Any CPU
{B4856711-6D4C-4246-A686-49458D4C1301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4856711-6D4C-4246-A686-49458D4C1301}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4856711-6D4C-4246-A686-49458D4C1301}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4856711-6D4C-4246-A686-49458D4C1301}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -637,6 +644,7 @@ Global
{A0CB9A10-F22D-4E66-A449-74B3D0361A9C} = {A49299FB-C5CD-4E0E-B7E1-B7867BBD67CC}
{1C459B5B-C702-46FF-BF1A-EE795E420FFA} = {A49299FB-C5CD-4E0E-B7E1-B7867BBD67CC}
{99B4D965-8782-4694-8DFA-B7A3630CEF60} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{B4856711-6D4C-4246-A686-49458D4C1301} = {5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}
Expand Down
2 changes: 0 additions & 2 deletions build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<Content Include="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenTelemetry.sln'))\build\xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!--Temp workaround to allow using daily dotnet 6 builds-->
<!--<PackageReference Include="System.Runtime.CompilerServices.Unsafe" PrivateAssets="All" NoWarn="NU1605" Version="6.0.0-preview.4.21253.7" />-->
</ItemGroup>

<PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ with the metric are of interest to you.
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"));
// Because "color" is dropped the resulting metric values are - name:apple LongSum Value:3 and name:lemon LongSum Value:2
...

// If you provide an empty `string` array as `TagKeys` to the `MetricStreamConfiguration`
Expand All @@ -214,6 +215,7 @@ with the metric are of interest to you.
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"));
// Because both "name" and "color" are dropped the resulting metric value is - LongSum Value:5
...
```

Expand Down
99 changes: 99 additions & 0 deletions docs/trace/links-creation-with-new-activities/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;

namespace LinksCreationWithNewRootActivitiesDemo;

internal class Program
{
private static readonly ActivitySource MyActivitySource = new("LinksCreationWithNewRootActivities");

public static async Task Main(string[] args)
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("LinksCreationWithNewRootActivities")
.AddConsoleExporter()
.Build();

using (var activity = MyActivitySource.StartActivity("OrchestratingActivity"))
{
activity?.SetTag("foo", 1);
await DoFanoutAsync();

using (var nestedActivity = MyActivitySource.StartActivity("WrapUp"))
{
nestedActivity?.SetTag("foo", 1);
}
}
}

public static async Task DoFanoutAsync()
{
var previous = Activity.Current;
const int NumConcurrentOperations = 10;

var activityContext = Activity.Current!.Context;
var links = new List<ActivityLink>
{
new ActivityLink(activityContext),
};

var tasks = new List<Task>();

// Fanning out to N concurrent operations.
// We create a new root activity for each operation and
// link it to an outer activity that happens to be the current
// activity.
for (int i = 0; i < NumConcurrentOperations; i++)
{
int operationIndex = i;

var task = Task.Run(() =>
{
// Reference: https://opentelemetry.io/docs/instrumentation/net/manual/#creating-new-root-activities
// Since we want to create a new root activity for each of the fanned out operations,
// this step helps us "de-parent" it from the current activity.
// Note: At least as of Oct 2023, this is the only mechanism to create a new root
// activity in the presence of an existing activity. This might change in the future
// if/when issue https://github.com/open-telemetry/opentelemetry-dotnet/issues/984
// is addressed.
Activity.Current = null;

// Reference: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Api#activity-creation-options
// Reference: https://opentelemetry.io/docs/instrumentation/net/manual/#adding-links
// We create a new root activity for each of the fanned out operations and link it to the outer activity.
using var newRootActivityForFannedOutOperation = MyActivitySource.StartActivity(
ActivityKind.Internal, // Set this to the appropriate ActivityKind depending on your scenario
name: $"FannedOutActivity {operationIndex + 1}",
links: links);

// DO THE FANOUT WORK HERE...
});

tasks.Add(task);
}

// Wait for all tasks to complete
await Task.WhenAll(tasks);

// Reset to the previous activity now that we are done with the fanout
// This will ensure that the rest of the code executes in the context of the original activity.
Activity.Current = previous;
}
}
Loading

0 comments on commit 2d59aec

Please sign in to comment.