From 6ca4c13a188585c00c8655e2749e30f5d96cf41a Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 11 Feb 2022 11:12:35 -0800 Subject: [PATCH 1/4] Minor improvement to console trace exporter output (#2890) --- .../ConsoleActivityExporter.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs index d24317b1f16..0cfe228e6bd 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs @@ -32,10 +32,17 @@ public override ExportResult Export(in Batch batch) { foreach (var activity in batch) { - this.WriteLine($"Activity.Id: {activity.Id}"); - if (!string.IsNullOrEmpty(activity.ParentId)) + this.WriteLine($"Activity.TraceId: {activity.TraceId}"); + this.WriteLine($"Activity.SpanId: {activity.SpanId}"); + this.WriteLine($"Activity.TraceFlags: {activity.ActivityTraceFlags}"); + if (!string.IsNullOrEmpty(activity.TraceStateString)) { - this.WriteLine($"Activity.ParentId: {activity.ParentId}"); + this.WriteLine($"Activity.TraceState: {activity.TraceStateString}"); + } + + if (activity.ParentSpanId != default) + { + this.WriteLine($"Activity.ParentSpanId: {activity.ParentSpanId}"); } this.WriteLine($"Activity.ActivitySourceName: {activity.Source.Name}"); @@ -45,7 +52,7 @@ public override ExportResult Export(in Batch batch) this.WriteLine($"Activity.Duration: {activity.Duration}"); if (activity.TagObjects.Any()) { - this.WriteLine("Activity.TagObjects:"); + this.WriteLine("Activity.Tags:"); foreach (var tag in activity.TagObjects) { var array = tag.Value as Array; From 8dc2d4afa36827aa26ded06531facd16121fb0ed Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 11 Feb 2022 15:16:31 -0800 Subject: [PATCH 2/4] Minor addition to MetricView tests (#2893) --- .../Metrics/MetricViewTests.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs index 2d75c883ac5..bd75f35d2b0 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs @@ -520,6 +520,48 @@ public void ViewToDropSingleInstrument() Assert.Equal("counterInteresting", metric.Name); } + [Fact] + public void ViewToDropSingleInstrumentObservableCounter() + { + using var meter = new Meter(Utils.GetCurrentMethodName()); + var exportedItems = new List(); + using var meterProvider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .AddView("observableCounterNotInteresting", new MetricStreamConfiguration() { Aggregation = Aggregation.Drop }) + .AddInMemoryExporter(exportedItems) + .Build(); + + // Expecting one metric stream. + meter.CreateObservableCounter("observableCounterNotInteresting", () => { return 10; }, "ms"); + meter.CreateObservableCounter("observableCounterInteresting", () => { return 10; }, "ms"); + + meterProvider.ForceFlush(MaxTimeToAllowForFlush); + Assert.Single(exportedItems); + var metric = exportedItems[0]; + Assert.Equal("observableCounterInteresting", metric.Name); + } + + [Fact] + public void ViewToDropSingleInstrumentObservableGauge() + { + using var meter = new Meter(Utils.GetCurrentMethodName()); + var exportedItems = new List(); + using var meterProvider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .AddView("observableGaugeNotInteresting", new MetricStreamConfiguration() { Aggregation = Aggregation.Drop }) + .AddInMemoryExporter(exportedItems) + .Build(); + + // Expecting one metric stream. + meter.CreateObservableGauge("observableGaugeNotInteresting", () => { return 10; }, "ms"); + meter.CreateObservableGauge("observableGaugeInteresting", () => { return 10; }, "ms"); + + meterProvider.ForceFlush(MaxTimeToAllowForFlush); + Assert.Single(exportedItems); + var metric = exportedItems[0]; + Assert.Equal("observableGaugeInteresting", metric.Name); + } + [Fact] public void ViewToDropMultipleInstruments() { From 9232e569b1f87d31e8144b7061ea7c66cff537fa Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Mon, 14 Feb 2022 20:59:40 -0800 Subject: [PATCH 3/4] Add stress test for strong-typed logging (#2892) * Add stress test for strong-typed logging * simplify proj * ... * eol * ref type * tweak Co-authored-by: Cijo Thomas --- .../DummyProcessor.cs | 27 ++++ .../OpenTelemetry.Tests.Stress.Logs.csproj | 19 +++ .../Payload.cs | 120 ++++++++++++++++++ .../Program.cs | 53 ++++++++ .../OpenTelemetry.Tests.Stress.Logs/README.md | 14 ++ 5 files changed, 233 insertions(+) create mode 100644 test/OpenTelemetry.Tests.Stress.Logs/DummyProcessor.cs create mode 100644 test/OpenTelemetry.Tests.Stress.Logs/OpenTelemetry.Tests.Stress.Logs.csproj create mode 100644 test/OpenTelemetry.Tests.Stress.Logs/Payload.cs create mode 100644 test/OpenTelemetry.Tests.Stress.Logs/Program.cs create mode 100644 test/OpenTelemetry.Tests.Stress.Logs/README.md diff --git a/test/OpenTelemetry.Tests.Stress.Logs/DummyProcessor.cs b/test/OpenTelemetry.Tests.Stress.Logs/DummyProcessor.cs new file mode 100644 index 00000000000..004bb3aba94 --- /dev/null +++ b/test/OpenTelemetry.Tests.Stress.Logs/DummyProcessor.cs @@ -0,0 +1,27 @@ +// +// 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. +// + +using OpenTelemetry; +using OpenTelemetry.Logs; + +namespace OpenTelemetry.Tests.Stress; + +internal class DummyProcessor : BaseProcessor +{ + public override void OnEnd(LogRecord record) + { + } +} diff --git a/test/OpenTelemetry.Tests.Stress.Logs/OpenTelemetry.Tests.Stress.Logs.csproj b/test/OpenTelemetry.Tests.Stress.Logs/OpenTelemetry.Tests.Stress.Logs.csproj new file mode 100644 index 00000000000..2067f9dec5d --- /dev/null +++ b/test/OpenTelemetry.Tests.Stress.Logs/OpenTelemetry.Tests.Stress.Logs.csproj @@ -0,0 +1,19 @@ + + + + Exe + netcoreapp3.1;net5.0;net6.0;net462 + false + + + + + + + + + + + + + diff --git a/test/OpenTelemetry.Tests.Stress.Logs/Payload.cs b/test/OpenTelemetry.Tests.Stress.Logs/Payload.cs new file mode 100644 index 00000000000..37fdcfcc243 --- /dev/null +++ b/test/OpenTelemetry.Tests.Stress.Logs/Payload.cs @@ -0,0 +1,120 @@ +// +// 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. +// + +namespace OpenTelemetry.Tests.Stress; + +internal class Payload +{ + public int Field001 = 0; + public float Field002 = 2.718281828f; + public double Field003 = 3.141592653589793d; + public string Field004 = "Hello, World!"; + public bool Field005 = true; + public int Field006 = 6; + public int Field007 = 7; + public int Field008 = 8; + public int Field009 = 9; + public int Field010 = 10; + public int Field011 = 11; + public int Field012 = 12; + public int Field013 = 13; + public int Field014 = 14; + public int Field015 = 15; + public int Field016 = 16; + public int Field017 = 17; + public int Field018 = 18; + public int Field019 = 19; + public int Field020 = 20; + public int Field021 = 21; + public int Field022 = 22; + public int Field023 = 23; + public int Field024 = 24; + public int Field025 = 25; + public int Field026 = 26; + public int Field027 = 27; + public int Field028 = 28; + public int Field029 = 29; + public int Field030 = 30; + public int Field031 = 31; + public int Field032 = 32; + public int Field033 = 33; + public int Field034 = 34; + public int Field035 = 35; + public int Field036 = 36; + public int Field037 = 37; + public int Field038 = 38; + public int Field039 = 39; + public int Field040 = 40; + public int Field041 = 41; + public int Field042 = 42; + public int Field043 = 43; + public int Field044 = 44; + public int Field045 = 45; + public int Field046 = 46; + public int Field047 = 47; + public int Field048 = 48; + public int Field049 = 49; + public int Field050 = 50; + public int Field051 = 51; + public int Field052 = 52; + public int Field053 = 53; + public int Field054 = 54; + public int Field055 = 55; + public int Field056 = 56; + public int Field057 = 57; + public int Field058 = 58; + public int Field059 = 59; + public int Field060 = 60; + public int Field061 = 61; + public int Field062 = 62; + public int Field063 = 63; + public int Field064 = 64; + public int Field065 = 65; + public int Field066 = 66; + public int Field067 = 67; + public int Field068 = 68; + public int Field069 = 69; + public int Field070 = 70; + public int Field071 = 71; + public int Field072 = 72; + public int Field073 = 73; + public int Field074 = 74; + public int Field075 = 75; + public int Field076 = 76; + public int Field077 = 77; + public int Field078 = 78; + public int Field079 = 79; + public int Field080 = 80; + public int Field081 = 81; + public int Field082 = 82; + public int Field083 = 83; + public int Field084 = 84; + public int Field085 = 85; + public int Field086 = 86; + public int Field087 = 87; + public int Field088 = 88; + public int Field089 = 89; + public int Field090 = 90; + public int Field091 = 91; + public int Field092 = 92; + public int Field093 = 93; + public int Field094 = 94; + public int Field095 = 95; + public int Field096 = 96; + public int Field097 = 97; + public int Field098 = 98; + public int Field099 = 99; +} diff --git a/test/OpenTelemetry.Tests.Stress.Logs/Program.cs b/test/OpenTelemetry.Tests.Stress.Logs/Program.cs new file mode 100644 index 00000000000..1239e08432c --- /dev/null +++ b/test/OpenTelemetry.Tests.Stress.Logs/Program.cs @@ -0,0 +1,53 @@ +// +// 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. +// + +using System.Runtime.CompilerServices; +using Microsoft.Extensions.Logging; +using OpenTelemetry.Logs; + +namespace OpenTelemetry.Tests.Stress; + +public partial class Program +{ + private static ILogger logger; + private static Payload payload = new Payload(); + + public static void Main() + { + using var loggerFactory = LoggerFactory.Create(builder => + { + builder.AddOpenTelemetry(options => + { + options.AddProcessor(new DummyProcessor()); + }); + }); + + logger = loggerFactory.CreateLogger(); + + Stress(prometheusPort: 9184); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected static void Run() + { + logger.Log( + logLevel: LogLevel.Information, + eventId: 2, + state: payload, + exception: null, + formatter: (state, ex) => string.Empty); + } +} diff --git a/test/OpenTelemetry.Tests.Stress.Logs/README.md b/test/OpenTelemetry.Tests.Stress.Logs/README.md new file mode 100644 index 00000000000..20c4b87db6e --- /dev/null +++ b/test/OpenTelemetry.Tests.Stress.Logs/README.md @@ -0,0 +1,14 @@ +# OpenTelemetry Stress Tests for Logs + +This is Stress Test specifically for logging, and is +based on the [OpenTelemetry.Tests.Stress](../OpenTelemetry.Tests.Stress/README.md). + +* [Running the stress test](#running-the-stress-test) + +## Running the stress test + +Open a console, run the following command from the current folder: + +```sh +dotnet run --framework net6.0 --configuration Release +``` From 84821ff9bca240388438d952b2c439279dd93c79 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Mon, 14 Feb 2022 21:17:36 -0800 Subject: [PATCH 4/4] Make IResourceDetector public to allow custom implementations of resource detectors. (#2897) * initial commit * changelog Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com> --- src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt | 2 ++ .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 2 ++ src/OpenTelemetry/CHANGELOG.md | 3 +++ src/OpenTelemetry/Resources/IResourceDetector.cs | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index 79e52486ff0..dd09baf95e8 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -104,6 +104,8 @@ OpenTelemetry.ReadOnlyTagCollection.Enumerator.Enumerator() -> void OpenTelemetry.ReadOnlyTagCollection.Enumerator.MoveNext() -> bool OpenTelemetry.ReadOnlyTagCollection.GetEnumerator() -> OpenTelemetry.ReadOnlyTagCollection.Enumerator OpenTelemetry.ReadOnlyTagCollection.ReadOnlyTagCollection() -> void +OpenTelemetry.Resources.IResourceDetector +OpenTelemetry.Resources.IResourceDetector.Detect() -> OpenTelemetry.Resources.Resource OpenTelemetry.Trace.BatchExportActivityProcessorOptions OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void override OpenTelemetry.BaseExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 79e52486ff0..dd09baf95e8 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -104,6 +104,8 @@ OpenTelemetry.ReadOnlyTagCollection.Enumerator.Enumerator() -> void OpenTelemetry.ReadOnlyTagCollection.Enumerator.MoveNext() -> bool OpenTelemetry.ReadOnlyTagCollection.GetEnumerator() -> OpenTelemetry.ReadOnlyTagCollection.Enumerator OpenTelemetry.ReadOnlyTagCollection.ReadOnlyTagCollection() -> void +OpenTelemetry.Resources.IResourceDetector +OpenTelemetry.Resources.IResourceDetector.Detect() -> OpenTelemetry.Resources.Resource OpenTelemetry.Trace.BatchExportActivityProcessorOptions OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void override OpenTelemetry.BaseExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 17e717053cb..4b8511ce1ed 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Make `IResourceDetector` public to allow custom implementations of resource detectors. + ([2897](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2897)) + ## 1.2.0-rc2 Released 2022-Feb-02 diff --git a/src/OpenTelemetry/Resources/IResourceDetector.cs b/src/OpenTelemetry/Resources/IResourceDetector.cs index 7fd4e652317..a55459807db 100644 --- a/src/OpenTelemetry/Resources/IResourceDetector.cs +++ b/src/OpenTelemetry/Resources/IResourceDetector.cs @@ -19,7 +19,7 @@ namespace OpenTelemetry.Resources /// /// An interface for Resource detectors. /// - internal interface IResourceDetector + public interface IResourceDetector { /// /// Called to get a resource with attributes from detector.