From d0190c349d624417685b01ec44528e768db02b55 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 22 Feb 2023 12:56:48 -0800 Subject: [PATCH 1/2] [OneCollector] Registration extension + tenant token tweaks (#1032) * OneCollector registration extension + tenant token tweaks. * CHANGELOG patch. --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 14 ++- .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 14 ++- .../.publicApi/net7.0/PublicAPI.Unshipped.txt | 14 ++- .../netstandard2.0/PublicAPI.Unshipped.txt | 14 ++- .../netstandard2.1/PublicAPI.Unshipped.txt | 14 ++- .../CHANGELOG.md | 5 + .../Logs/OneCollectorLogExporterBuilder.cs | 118 ++++++++++++++++++ .../Logs/OneCollectorLogExporterOptions.cs | 4 +- ...torOpenTelemetryLoggerOptionsExtensions.cs | 104 +++++++++++++-- .../OneCollectorExporterOptions.cs | 31 +++-- .../OneCollectorExporterTransportOptions.cs | 6 +- .../README.md | 6 +- ...enTelemetryLoggerOptionsExtensionsTests.cs | 52 ++++++++ 13 files changed, 350 insertions(+), 46 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterBuilder.cs create mode 100644 test/OpenTelemetry.Exporter.OneCollector.Tests/OneCollectorOpenTelemetryLoggerOptionsExtensionsTests.cs diff --git a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net462/PublicAPI.Unshipped.txt index 8e36c38895..80dca438b6 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net462/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorExporter OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.get -> string? OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.set -> void -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.get -> string? -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TransportOptions.get -> OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions! OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions.Endpoint.get -> System.Uri! @@ -15,7 +13,15 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.BatchOptions. OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.get -> string! OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.OneCollectorLogExporterOptions() -> void +OpenTelemetry.Logs.OneCollectorLogExporterBuilder +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureBatchOptions(System.Action!>! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureTransportOptions(System.Action! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetDefaultEventName(string! defaultEventName) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetInstrumentationKey(string! instrumentationKey) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions override sealed OpenTelemetry.Exporter.OneCollector.OneCollectorExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net6.0/PublicAPI.Unshipped.txt index 8e36c38895..80dca438b6 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorExporter OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.get -> string? OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.set -> void -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.get -> string? -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TransportOptions.get -> OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions! OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions.Endpoint.get -> System.Uri! @@ -15,7 +13,15 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.BatchOptions. OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.get -> string! OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.OneCollectorLogExporterOptions() -> void +OpenTelemetry.Logs.OneCollectorLogExporterBuilder +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureBatchOptions(System.Action!>! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureTransportOptions(System.Action! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetDefaultEventName(string! defaultEventName) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetInstrumentationKey(string! instrumentationKey) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions override sealed OpenTelemetry.Exporter.OneCollector.OneCollectorExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net7.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net7.0/PublicAPI.Unshipped.txt index 8e36c38895..80dca438b6 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net7.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/net7.0/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorExporter OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.get -> string? OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.set -> void -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.get -> string? -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TransportOptions.get -> OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions! OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions.Endpoint.get -> System.Uri! @@ -15,7 +13,15 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.BatchOptions. OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.get -> string! OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.OneCollectorLogExporterOptions() -> void +OpenTelemetry.Logs.OneCollectorLogExporterBuilder +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureBatchOptions(System.Action!>! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureTransportOptions(System.Action! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetDefaultEventName(string! defaultEventName) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetInstrumentationKey(string! instrumentationKey) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions override sealed OpenTelemetry.Exporter.OneCollector.OneCollectorExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 8e36c38895..80dca438b6 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorExporter OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.get -> string? OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.set -> void -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.get -> string? -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TransportOptions.get -> OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions! OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions.Endpoint.get -> System.Uri! @@ -15,7 +13,15 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.BatchOptions. OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.get -> string! OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.OneCollectorLogExporterOptions() -> void +OpenTelemetry.Logs.OneCollectorLogExporterBuilder +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureBatchOptions(System.Action!>! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureTransportOptions(System.Action! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetDefaultEventName(string! defaultEventName) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetInstrumentationKey(string! instrumentationKey) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions override sealed OpenTelemetry.Exporter.OneCollector.OneCollectorExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index 8e36c38895..80dca438b6 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OneCollector/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorExporter OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.get -> string? OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.InstrumentationKey.set -> void -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.get -> string? -OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TenantToken.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorExporterOptions.TransportOptions.get -> OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions! OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions OpenTelemetry.Exporter.OneCollector.OneCollectorExporterTransportOptions.Endpoint.get -> System.Uri! @@ -15,7 +13,15 @@ OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.BatchOptions. OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.get -> string! OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.DefaultEventName.set -> void OpenTelemetry.Exporter.OneCollector.OneCollectorLogExporterOptions.OneCollectorLogExporterOptions() -> void +OpenTelemetry.Logs.OneCollectorLogExporterBuilder +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureBatchOptions(System.Action!>! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.ConfigureTransportOptions(System.Action! configure) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetDefaultEventName(string! defaultEventName) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! +OpenTelemetry.Logs.OneCollectorLogExporterBuilder.SetInstrumentationKey(string! instrumentationKey) -> OpenTelemetry.Logs.OneCollectorLogExporterBuilder! OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions override sealed OpenTelemetry.Exporter.OneCollector.OneCollectorExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, Microsoft.Extensions.Configuration.IConfiguration! configuration, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, string! instrumentationKey, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! +static OpenTelemetry.Logs.OneCollectorOpenTelemetryLoggerOptionsExtensions.AddOneCollectorExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md index 22e4a43d8d..621c997c8f 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Tenant token is no longer exposed on `OneCollectorExporterOptions` and will be + set automatically from the instrumentation key. Added new registration + overloads and a builder to help with configuration. + ([#1032](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1032)) + ## 0.1.0-alpha.1 Released 2023-Feb-16 diff --git a/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterBuilder.cs b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterBuilder.cs new file mode 100644 index 0000000000..25b5b5cad3 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterBuilder.cs @@ -0,0 +1,118 @@ +// +// 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.Diagnostics; +using Microsoft.Extensions.Configuration; +using OpenTelemetry.Exporter.OneCollector; +using OpenTelemetry.Internal; + +namespace OpenTelemetry.Logs; + +/// +/// Contains methods for building instances. +/// +public sealed class OneCollectorLogExporterBuilder +{ + internal OneCollectorLogExporterBuilder(string? instrumentationKey) + { + this.Options = new() + { + InstrumentationKey = instrumentationKey, + }; + } + + internal OneCollectorLogExporterBuilder(IConfiguration configuration) + : this(instrumentationKey: null) + { + Debug.Assert(configuration != null, "configuration was null"); + + configuration.Bind(this.Options); + } + + internal OneCollectorLogExporterOptions Options { get; } + + /// + /// Register a callback action for configuring the batch options of . + /// + /// Callback action for configuring . + /// The supplied for + /// call chaining. + public OneCollectorLogExporterBuilder ConfigureBatchOptions(Action> configure) + { + Guard.ThrowIfNull(configure); + + configure(this.Options.BatchOptions); + + return this; + } + + /// + /// Register a callback action for configuring the transport options of . + /// + /// Callback action for configuring . + /// The supplied for + /// call chaining. + public OneCollectorLogExporterBuilder ConfigureTransportOptions(Action configure) + { + Guard.ThrowIfNull(configure); + + configure(this.Options.TransportOptions); + + return this; + } + + /// + /// Sets the + /// property. Default value: Log. + /// + /// + /// Default event name. + /// The supplied for + /// call chaining. + public OneCollectorLogExporterBuilder SetDefaultEventName(string defaultEventName) + { + Guard.ThrowIfNullOrWhitespace(defaultEventName); + + this.Options.DefaultEventName = defaultEventName; + + return this; + } + + /// + /// Sets the + /// property. + /// + /// + /// Instrumentation key. + /// The supplied for + /// call chaining. + public OneCollectorLogExporterBuilder SetInstrumentationKey(string instrumentationKey) + { + Guard.ThrowIfNullOrWhitespace(instrumentationKey); + + this.Options.InstrumentationKey = instrumentationKey; + + return this; + } +} diff --git a/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterOptions.cs b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterOptions.cs index e08641f56a..ef02b0733f 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExporterOptions.cs @@ -25,7 +25,7 @@ namespace OpenTelemetry.Exporter.OneCollector; public sealed class OneCollectorLogExporterOptions : OneCollectorExporterOptions, ISinkFactory { /// - /// Gets or sets the default event name. Default value: Log. + /// Gets or sets the default event name. Default value: Log. /// /// /// Note: The default event name is used when an /// Gets or sets the default event namespace. Default value: - /// OpenTelemetry.Logs. + /// OpenTelemetry.Logs. /// /// /// Note: The default event namespace is used if a +using Microsoft.Extensions.Configuration; using OpenTelemetry.Exporter.OneCollector; using OpenTelemetry.Internal; @@ -24,6 +25,8 @@ namespace OpenTelemetry.Logs; /// public static class OneCollectorOpenTelemetryLoggerOptionsExtensions { + /* + TODO: Enable this once logging supports DI/options binding. /// /// Add OneCollector exporter to the . @@ -34,32 +37,119 @@ public static class OneCollectorOpenTelemetryLoggerOptionsExtensions public static OpenTelemetryLoggerOptions AddOneCollectorExporter( this OpenTelemetryLoggerOptions options) => AddOneCollectorExporter(options, _ => { }); + */ /// /// Add OneCollector exporter to the . /// /// . - /// Callback action for configuring . + /// Callback action for configuring . /// The supplied for call /// chaining. public static OpenTelemetryLoggerOptions AddOneCollectorExporter( this OpenTelemetryLoggerOptions options, - Action configure) + Action configure) { - Guard.ThrowIfNull(options); Guard.ThrowIfNull(configure); - var logExporterOptions = new OneCollectorLogExporterOptions(); + return AddOneCollectorExporter(options, instrumentationKey: null, configuration: null, configure); + } + + /// + /// Add OneCollector exporter to the . + /// + /// . + /// OneCollector instrumentation key. + /// The supplied for call + /// chaining. + public static OpenTelemetryLoggerOptions AddOneCollectorExporter( + this OpenTelemetryLoggerOptions options, + string instrumentationKey) + { + Guard.ThrowIfNullOrWhitespace(instrumentationKey); + + return AddOneCollectorExporter(options, instrumentationKey, configuration: null, configure: null); + } + + /// + /// Add OneCollector exporter to the . + /// + /// . + /// OneCollector instrumentation key. + /// Callback action for configuring . + /// The supplied for call + /// chaining. + public static OpenTelemetryLoggerOptions AddOneCollectorExporter( + this OpenTelemetryLoggerOptions options, + string instrumentationKey, + Action configure) + { + Guard.ThrowIfNullOrWhitespace(instrumentationKey); + + return AddOneCollectorExporter(options, instrumentationKey, configuration: null, configure); + } + + /// + /// Add OneCollector exporter to the . + /// + /// . + /// Configuration used to build . + /// The supplied for call + /// chaining. + public static OpenTelemetryLoggerOptions AddOneCollectorExporter( + this OpenTelemetryLoggerOptions options, + IConfiguration configuration) + { + Guard.ThrowIfNull(configuration); + + return AddOneCollectorExporter(options, instrumentationKey: null, configuration, configure: null); + } + + /// + /// Add OneCollector exporter to the . + /// + /// . + /// Configuration used to build . + /// Callback action for configuring . + /// The supplied for call + /// chaining. + public static OpenTelemetryLoggerOptions AddOneCollectorExporter( + this OpenTelemetryLoggerOptions options, + IConfiguration configuration, + Action configure) + { + Guard.ThrowIfNull(configuration); + + return AddOneCollectorExporter(options, instrumentationKey: null, configuration, configure); + } + + internal static OpenTelemetryLoggerOptions AddOneCollectorExporter( + this OpenTelemetryLoggerOptions options, + string? instrumentationKey, + IConfiguration? configuration, + Action? configure) + { + Guard.ThrowIfNull(options); + + var builder = configuration == null + ? new OneCollectorLogExporterBuilder(instrumentationKey) + : new OneCollectorLogExporterBuilder(configuration); + + configure?.Invoke(builder); - configure?.Invoke(logExporterOptions); + var exporterOptions = builder.Options; - var batchOptions = logExporterOptions.BatchOptions; + var batchOptions = exporterOptions.BatchOptions; #pragma warning disable CA2000 // Dispose objects before losing scope options.AddProcessor( new BatchLogRecordExportProcessor( - new OneCollectorLogExporter(logExporterOptions), + new OneCollectorLogExporter(exporterOptions), batchOptions.MaxQueueSize, batchOptions.ScheduledDelayMilliseconds, batchOptions.ExporterTimeoutMilliseconds, diff --git a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs index fae8c8a977..533e14d3c7 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs @@ -14,6 +14,8 @@ // limitations under the License. // +using System.ComponentModel.DataAnnotations; + namespace OpenTelemetry.Exporter.OneCollector; /// @@ -25,14 +27,13 @@ internal OneCollectorExporterOptions() { } - /// - /// Gets or sets the OneCollector tenant token. - /// - public string? TenantToken { get; set; } - /// /// Gets or sets the OneCollector instrumentation key. /// + /// + /// Note: Instrumentation key is required. + /// + [Required] public string? InstrumentationKey { get; set; } /// @@ -40,18 +41,30 @@ internal OneCollectorExporterOptions() /// public OneCollectorExporterTransportOptions TransportOptions { get; } = new(); + /// + /// Gets the OneCollector tenant token. + /// + internal string? TenantToken { get; private set; } + internal virtual void Validate() { - if (string.IsNullOrWhiteSpace(this.TenantToken)) + if (string.IsNullOrWhiteSpace(this.InstrumentationKey)) { - throw new InvalidOperationException($"{nameof(this.TenantToken)} was not specified on {this.GetType().Name} options."); + throw new InvalidOperationException($"{nameof(this.InstrumentationKey)} was not specified on {this.GetType().Name} options."); } - if (string.IsNullOrWhiteSpace(this.InstrumentationKey)) +#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER + var positionOfFirstDash = this.InstrumentationKey.IndexOf('-', StringComparison.OrdinalIgnoreCase); +#else + var positionOfFirstDash = this.InstrumentationKey!.IndexOf('-'); +#endif + if (positionOfFirstDash < 0) { - throw new InvalidOperationException($"{nameof(this.InstrumentationKey)} was not specified on {this.GetType().Name} options."); + throw new InvalidOperationException($"{nameof(this.InstrumentationKey)} specified on {this.GetType().Name} options is invalid."); } + this.TenantToken = this.InstrumentationKey.Substring(0, positionOfFirstDash); + this.TransportOptions.Validate(); } } diff --git a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterTransportOptions.cs b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterTransportOptions.cs index ef82e213ef..bc59b956ee 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterTransportOptions.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterTransportOptions.cs @@ -33,7 +33,7 @@ internal OneCollectorExporterTransportOptions() /// /// Gets or sets OneCollector endpoint address. Default value: - /// https://mobile.events.data.microsoft.com/OneCollector/1.0/. + /// https://mobile.events.data.microsoft.com/OneCollector/1.0/. /// public Uri Endpoint { get; set; } = new Uri(DefaultOneCollectorEndpoint); @@ -45,7 +45,7 @@ internal OneCollectorExporterTransportOptions() /// /// Gets or sets the maximum request payload size in bytes when sending data - /// to OneCollector. Default value: 4,194,304. + /// to OneCollector. Default value: 4,194,304. /// /// /// Note: Set to -1 for unlimited request payload size. @@ -54,7 +54,7 @@ internal OneCollectorExporterTransportOptions() /// /// Gets or sets the maximum number of items per request payload when - /// sending data to OneCollector. Default value: 1500. + /// sending data to OneCollector. Default value: 1500. /// /// /// Note: Set to -1 for unlimited number of items per request payload. diff --git a/src/OpenTelemetry.Exporter.OneCollector/README.md b/src/OpenTelemetry.Exporter.OneCollector/README.md index c20dc71759..d587afa987 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/README.md +++ b/src/OpenTelemetry.Exporter.OneCollector/README.md @@ -25,11 +25,7 @@ using var logFactory = LoggerFactory.Create(builder => builder { builder.ParseStateValues = true; builder.IncludeScopes = true; - builder.AddOneCollectorExporter(o => - { - o.TenantToken = "tenant-token-here"; - o.InstrumentationKey = "instrumentation-key-here"; - }); + builder.AddOneCollectorExporter("instrumentation-key-here"); })); var logger = logFactory.CreateLogger(); diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/OneCollectorOpenTelemetryLoggerOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/OneCollectorOpenTelemetryLoggerOptionsExtensionsTests.cs new file mode 100644 index 0000000000..08a61d6bbd --- /dev/null +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/OneCollectorOpenTelemetryLoggerOptionsExtensionsTests.cs @@ -0,0 +1,52 @@ +// +// 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 Microsoft.Extensions.Logging; +using OpenTelemetry.Logs; +using Xunit; + +namespace OpenTelemetry.Exporter.OneCollector.Tests; + +public class OneCollectorOpenTelemetryLoggerOptionsExtensionsTests +{ + [Fact] + public void InstrumentationKeyAndTenantTokenValidationTest() + { + Assert.Throws(() => + { + using var loggerFactory = LoggerFactory.Create(builder => builder + .AddOpenTelemetry(builder => + { + builder.AddOneCollectorExporter(options => { }); + })); + }); + + using var loggerFactory = LoggerFactory.Create(builder => builder + .AddOpenTelemetry(builder => + { + builder.AddOneCollectorExporter("token-extrainformation"); + })); + + Assert.Throws(() => + { + using var loggerFactory = LoggerFactory.Create(builder => builder + .AddOpenTelemetry(builder => + { + builder.AddOneCollectorExporter("invalidinstrumentationkey"); + })); + }); + } +} From 978784693c570283e6105aaec3732d61defe9627 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Wed, 22 Feb 2023 21:34:24 +0000 Subject: [PATCH 2/2] [Shared] Fix analysis warnings (#953) * [Shared] Fix analysis warnings Fix/suppress code analysis warnings in OpenTelemetry.Contrib.Shared. Contributes to #950. * Condense IDisposable implemnetation Apply code review feedback and put the code to dispose inline. --------- --- .../DiagnosticSourceListener.cs | 2 +- .../DiagnosticSourceSubscriber.cs | 10 +++------- .../InstrumentationEventSource.cs | 2 +- .../MultiTypePropertyFetcher.cs | 10 +++++++--- .../DiagnosticSourceInstrumentation/PropertyFetcher.cs | 10 +++++++--- .../TestActivityProcessor.cs | 9 +++++---- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs index ef3a0c46be..9dc3f74a7b 100644 --- a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs +++ b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs @@ -21,7 +21,7 @@ namespace OpenTelemetry.Instrumentation; -internal class DiagnosticSourceListener : IObserver> +internal sealed class DiagnosticSourceListener : IObserver> { private readonly ListenerHandler handler; diff --git a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceSubscriber.cs b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceSubscriber.cs index f0065c97ac..99a25bbf7f 100644 --- a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceSubscriber.cs +++ b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/DiagnosticSourceSubscriber.cs @@ -21,7 +21,9 @@ namespace OpenTelemetry.Instrumentation; -internal class DiagnosticSourceSubscriber : IDisposable, IObserver +#pragma warning disable CA1812 +internal sealed class DiagnosticSourceSubscriber : IDisposable, IObserver +#pragma warning restore CA1812 { private readonly Func handlerFactory; private readonly Func diagnosticSourceFilter; @@ -86,12 +88,6 @@ public void OnError(Exception error) /// public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) { if (Interlocked.CompareExchange(ref this.disposed, 1, 0) == 1) { diff --git a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/InstrumentationEventSource.cs b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/InstrumentationEventSource.cs index 53b684f707..07f9f56057 100644 --- a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/InstrumentationEventSource.cs +++ b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/InstrumentationEventSource.cs @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation; /// EventSource events emitted from the project. /// [EventSource(Name = "OpenTelemetry-Instrumentation")] -internal class InstrumentationEventSource : EventSource +internal sealed class InstrumentationEventSource : EventSource { public static InstrumentationEventSource Log = new InstrumentationEventSource(); diff --git a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/MultiTypePropertyFetcher.cs b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/MultiTypePropertyFetcher.cs index 8ed27681e4..122d40743f 100644 --- a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/MultiTypePropertyFetcher.cs +++ b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/MultiTypePropertyFetcher.cs @@ -25,7 +25,9 @@ namespace OpenTelemetry.Instrumentation; /// PropertyFetcher fetches a property from an object. /// /// The type of the property being fetched. -internal class MultiTypePropertyFetcher +#pragma warning disable CA1812 +internal sealed class MultiTypePropertyFetcher +#pragma warning restore CA1812 { private readonly string propertyName; private readonly ConcurrentDictionary innerFetcher = new ConcurrentDictionary(); @@ -55,7 +57,7 @@ public T Fetch(object obj) PropertyFetch fetcher = null; if (!this.innerFetcher.TryGetValue(type, out fetcher)) { - var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase)); + var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.OrdinalIgnoreCase)); if (property == null) { property = type.GetProperty(this.propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); @@ -100,7 +102,9 @@ public virtual T Fetch(object obj) return default; } - private class TypedPropertyFetch : PropertyFetch +#pragma warning disable CA1812 + private sealed class TypedPropertyFetch : PropertyFetch +#pragma warning restore CA1812 where TDeclaredProperty : T { private readonly Func propertyFetch; diff --git a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/PropertyFetcher.cs b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/PropertyFetcher.cs index 15e3d099b6..8aab31e0be 100644 --- a/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/PropertyFetcher.cs +++ b/src/OpenTelemetry.Contrib.Shared/DiagnosticSourceInstrumentation/PropertyFetcher.cs @@ -24,7 +24,9 @@ namespace OpenTelemetry.Instrumentation; /// PropertyFetcher fetches a property from an object. /// /// The type of the property being fetched. -internal class PropertyFetcher +#pragma warning disable CA1812 +internal sealed class PropertyFetcher +#pragma warning restore CA1812 { private readonly string propertyName; private PropertyFetch innerFetcher; @@ -70,7 +72,7 @@ public bool TryFetch(object obj, out T value) if (this.innerFetcher == null) { var type = obj.GetType().GetTypeInfo(); - var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase)); + var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.OrdinalIgnoreCase)); if (property == null) { property = type.GetProperty(this.propertyName); @@ -109,7 +111,9 @@ public virtual bool TryFetch(object obj, out T value) return false; } - private class TypedPropertyFetch : PropertyFetch +#pragma warning disable CA1812 + private sealed class TypedPropertyFetch : PropertyFetch +#pragma warning restore CA1812 where TDeclaredProperty : T { private readonly Func propertyFetch; diff --git a/test/OpenTelemetry.Contrib.Tests.Shared/TestActivityProcessor.cs b/test/OpenTelemetry.Contrib.Tests.Shared/TestActivityProcessor.cs index dc127c38f8..21ab4cf235 100644 --- a/test/OpenTelemetry.Contrib.Tests.Shared/TestActivityProcessor.cs +++ b/test/OpenTelemetry.Contrib.Tests.Shared/TestActivityProcessor.cs @@ -19,7 +19,7 @@ namespace OpenTelemetry.Tests; -internal class TestActivityProcessor : BaseProcessor +internal sealed class TestActivityProcessor : BaseProcessor { public Action StartAction; public Action EndAction; @@ -34,11 +34,11 @@ public TestActivityProcessor(Action onStart, Action onEnd) this.EndAction = onEnd; } - public bool ShutdownCalled { get; private set; } = false; + public bool ShutdownCalled { get; private set; } - public bool ForceFlushCalled { get; private set; } = false; + public bool ForceFlushCalled { get; private set; } - public bool DisposedCalled { get; private set; } = false; + public bool DisposedCalled { get; private set; } public override void OnStart(Activity span) { @@ -64,6 +64,7 @@ protected override bool OnShutdown(int timeoutMilliseconds) protected override void Dispose(bool disposing) { + base.Dispose(disposing); this.DisposedCalled = true; } }