diff --git a/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs b/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs index 374ec30c48..86657cced5 100644 --- a/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs +++ b/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs @@ -110,7 +110,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) tcs.SetResult(true); }); - return tcs.Task.ContinueWith(antecedent => tokenRegistration.Dispose()); + return tcs.Task.ContinueWith(antecedent => tokenRegistration.Dispose(), stoppingToken); } } } diff --git a/examples/process-instrumentation/process-instrumentation-grafana-dashboard-sample.json b/examples/process-instrumentation/process-instrumentation-grafana-dashboard-sample.json new file mode 100644 index 0000000000..3d8dceff0c --- /dev/null +++ b/examples/process-instrumentation/process-instrumentation-grafana-dashboard-sample.json @@ -0,0 +1,640 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 2, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "The amount of committed virtual memory. One way to think of this is all the address space this process can read from without triggering an access violation; this includes memory backed solely by RAM, by a swapfile/pagefile and by other mapped files on disk.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "{__name__=\"process_memory_virtual_By\", instance=\"localhost:9464\", job=\"otel\"}" + ], + "prefix": "All except:", + "readOnly": true + } + }, + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] + } + ] + }, + "gridPos": { + "h": 5, + "w": 9, + "x": 0, + "y": 0 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "process_memory_virtual_By", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "virtual memory usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "the amount of physical memory allocated", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 10, + "x": 9, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "process_memory_usage_By", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "physical memory usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "Total CPU seconds broken down by states.\nProcess.UserProcessorTime: Gets the user processor time.\nProcess.PrivilegedProcessorTime: Gets the privileged processor time.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 9, + "x": 0, + "y": 5 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "process_cpu_time_s", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "cpu time", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "{instance=\"localhost:9464\", job=\"otel\"}" + ], + "prefix": "All except:", + "readOnly": true + } + }, + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] + } + ] + }, + "gridPos": { + "h": 6, + "w": 10, + "x": 9, + "y": 5 + }, + "id": 12, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "100 * (delta(process_cpu_time_s{state='system'}[30s])/ignoring(state)(process_cpu_count__processors_* 30))", + "legendFormat": "__auto", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "100 * (delta(process_cpu_time_s{state='user'}[30s])/ignoring(state)(process_cpu_count__processors_* 30))", + "hide": false, + "legendFormat": "__auto", + "range": true, + "refId": "B" + } + ], + "title": "cpu utilization", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "Process threads count.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 9, + "x": 0, + "y": 11 + }, + "id": 10, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "process_threads__threads_", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "thread count", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "description": "The number of processors (CPU cores) available.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 3, + "x": 9, + "y": 11 + }, + "id": 8, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "InQLY014z" + }, + "editorMode": "code", + "expr": "process_cpu_count__processors_", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "cpu count", + "type": "gauge" + } + ], + "refresh": "5s", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-2h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "process instrumentation", + "uid": "WPv6P0JVk", + "version": 6, + "weekStart": "" +} 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/src/OpenTelemetry.Exporter.Instana/CHANGELOG.md b/src/OpenTelemetry.Exporter.Instana/CHANGELOG.md index 6aa0f0db0f..3c164dd737 100644 --- a/src/OpenTelemetry.Exporter.Instana/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Instana/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## 1.0.3 + +Released 2023-Feb-21 + * Fixes issue in span serialization process introduced in 1.0.2 version. ([#979](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/979)) * Update OTel SDK version to `1.3.2`. 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/Internal/Serialization/CommonSchemaJsonSerializer.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializer.cs index 266d56fbcd..a6cf0d7a64 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializer.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializer.cs @@ -62,25 +62,20 @@ public void SerializeBatchOfItemsToStream(Resource resource, in Batch batch, var numberOfSerializedItems = 0; long payloadSizeInBytes = initialSizeOfPayloadInBytes; - var writer = ThreadStorageHelper.Utf8JsonWriter ??= new( - stream, - new JsonWriterOptions - { -#if DEBUG - SkipValidation = false, -#else - SkipValidation = true, -#endif - }); - - foreach (var item in batch) + var writer = ThreadStorageHelper.Utf8JsonWriter; + if (writer == null) + { + writer = ThreadStorageHelper.Utf8JsonWriter = new( + stream, + new JsonWriterOptions { SkipValidation = true }); + } + else { - // Note: This is a slow operation. We call this each iteration - // (instead of once per batch) to reset _currentDepth on - // Utf8JsonWriter so it doesn't write a comma after each record. - // Need a faster solution here! writer.Reset(stream); + } + foreach (var item in batch) + { this.SerializeItemToJson(resource, item, writer); var currentItemSizeInBytes = writer.BytesCommitted + writer.BytesPending + 1; @@ -88,6 +83,7 @@ public void SerializeBatchOfItemsToStream(Resource resource, in Batch batch, payloadSizeInBytes += currentItemSizeInBytes; writer.Flush(); + writer.Reset(); stream.Write(NewLine, 0, 1); 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/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt index fa997838e5..1fd1f60339 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt @@ -15,7 +15,7 @@ OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.StackdriverTraceExporter(string projectId) -> void OpenTelemetry.Exporter.Stackdriver.Utils.CommonUtils OpenTelemetry.Trace.TracerProviderBuilderExtensions -override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batchActivity) -> OpenTelemetry.ExportResult +override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetDefaultResource(string projectId) -> Google.Api.MonitoredResource static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetProjectId() -> string static OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration.Default.get -> OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration diff --git a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index fa997838e5..1fd1f60339 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -15,7 +15,7 @@ OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.StackdriverTraceExporter(string projectId) -> void OpenTelemetry.Exporter.Stackdriver.Utils.CommonUtils OpenTelemetry.Trace.TracerProviderBuilderExtensions -override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batchActivity) -> OpenTelemetry.ExportResult +override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetDefaultResource(string projectId) -> Google.Api.MonitoredResource static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetProjectId() -> string static OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration.Default.get -> OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs index 18a530fda9..240c2af077 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using Google.Cloud.Trace.V2; using Google.Protobuf.WellKnownTypes; @@ -27,7 +28,7 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation; internal static class ActivityExtensions { - private static Dictionary labelsToReplace = new Dictionary + private static readonly Dictionary LabelsToReplace = new Dictionary { { "component", "/component" }, { "http.method", "/http/method" }, @@ -94,7 +95,7 @@ public static Span ToSpan(this Activity activity, string projectId) // StackDriver uses different labels that are used to categorize spans // replace attribute keys with StackDriver version - foreach (var entry in labelsToReplace) + foreach (var entry in LabelsToReplace) { if (span.Attributes.AttributeMap.TryGetValue(entry.Key, out var attrValue)) { @@ -146,7 +147,7 @@ public static AttributeValue ToAttributeValue(this object? av) case double d: return new AttributeValue() { - StringValue = new TruncatableString() { Value = d.ToString() }, + StringValue = new TruncatableString() { Value = d.ToString(CultureInfo.InvariantCulture) }, }; case null: return new AttributeValue(); diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs index 9f20621d53..800a31aa74 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs @@ -20,30 +20,31 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation; internal class Constants { - public static readonly string PackagVersionUndefined = "undefined"; + public const string PackagVersionUndefined = "undefined"; - public static readonly string LabelDescription = "OpenTelemetry string"; - public static readonly string OpenTelemetryTask = "OpenTelemetry_task"; - public static readonly string OpenTelemetryTaskDescription = "OpenTelemetry task identifier"; + public const string LabelDescription = "OpenTelemetry string"; + public const string OpenTelemetryTask = "OpenTelemetry_task"; + public const string OpenTelemetryTaskDescription = "OpenTelemetry task identifier"; - public static readonly string GcpGkeContainer = "k8s_container"; - public static readonly string GcpGceInstance = "gce_instance"; - public static readonly string AwsEc2Instance = "aws_ec2_instance"; - public static readonly string Global = "global"; + public const string GcpGkeContainer = "k8s_container"; + public const string GcpGceInstance = "gce_instance"; + public const string AwsEc2Instance = "aws_ec2_instance"; + public const string Global = "global"; - public static readonly string ProjectIdLabelKey = "project_id"; - public static readonly string OpenTelemetryTaskValueDefault = GenerateDefaultTaskValue(); + public const string ProjectIdLabelKey = "project_id"; + + public const string GceGcpInstanceType = "cloud.google.com/gce/instance"; + public const string GcpInstanceIdKey = "cloud.google.com/gce/instance_id"; + public const string GcpAccountIdKey = "cloud.google.com/gce/project_id"; + public const string GcpZoneKey = "cloud.google.com/gce/zone"; - public static readonly string GceGcpInstanceType = "cloud.google.com/gce/instance"; - public static readonly string GcpInstanceIdKey = "cloud.google.com/gce/instance_id"; - public static readonly string GcpAccountIdKey = "cloud.google.com/gce/project_id"; - public static readonly string GcpZoneKey = "cloud.google.com/gce/zone"; + public const string K8sContainerType = "k8s.io/container"; + public const string K8sClusterNameKey = "k8s.io/cluster/name"; + public const string K8sContainerNameKey = "k8s.io/container/name"; + public const string K8sNamespaceNameKey = "k8s.io/namespace/name"; + public const string K8sPodNameKey = "k8s.io/pod/name"; - public static readonly string K8sContainerType = "k8s.io/container"; - public static readonly string K8sClusterNameKey = "k8s.io/cluster/name"; - public static readonly string K8sContainerNameKey = "k8s.io/container/name"; - public static readonly string K8sNamespaceNameKey = "k8s.io/namespace/name"; - public static readonly string K8sPodNameKey = "k8s.io/pod/name"; + public static readonly string OpenTelemetryTaskValueDefault = GenerateDefaultTaskValue(); private static string GenerateDefaultTaskValue() { diff --git a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs index 222c5c12f0..e109388329 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs @@ -37,7 +37,9 @@ public class StackdriverTraceExporter : BaseExporter private readonly TraceServiceSettings traceServiceSettings; private readonly TraceServiceClient traceServiceClient; +#pragma warning disable CA1810 // Initialize reference type static fields inline static StackdriverTraceExporter() +#pragma warning restore CA1810 // Initialize reference type static fields inline { try { @@ -87,7 +89,7 @@ internal StackdriverTraceExporter(string projectId, TraceServiceClient traceServ } /// - public override ExportResult Export(in Batch batchActivity) + public override ExportResult Export(in Batch batch) { TraceServiceClient traceWriter = this.traceServiceClient; if (this.traceServiceClient == null) @@ -103,7 +105,7 @@ public override ExportResult Export(in Batch batchActivity) ProjectName = this.googleCloudProjectId, }; - foreach (var activity in batchActivity) + foreach (var activity in batch) { // It should never happen that the time has no correct kind, only if OpenTelemetry is used incorrectly. if (activity.StartTimeUtc.Kind == DateTimeKind.Utc) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs index 6d08567660..e96e34b8cb 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs @@ -36,8 +36,10 @@ public static TracerProviderBuilder UseStackdriverExporter( { Guard.ThrowIfNull(builder); +#pragma warning disable CA2000 // Dispose objects before losing scope var activityExporter = new StackdriverTraceExporter(projectId); return builder.AddProcessor(new BatchActivityExportProcessor(activityExporter)); +#pragma warning restore CA2000 // Dispose objects before losing scope } } diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs b/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs index 3aac886d42..ef9067fc54 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs @@ -32,6 +32,11 @@ public static class CommonUtils /// . public static IEnumerable> Partition(this IEnumerable source, int size) { + if (source == null) + { + throw new System.ArgumentNullException(nameof(source)); + } + using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs index 146b30dce9..b1ea6d2a72 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading.Tasks; using Grpc.Core; using Grpc.Core.Interceptors; using OpenTelemetry.Context.Propagation; @@ -52,6 +53,9 @@ public override TResponse BlockingUnaryCall( ClientInterceptorContext context, BlockingUnaryCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try @@ -81,11 +85,16 @@ public override AsyncUnaryCall AsyncUnaryCall( ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 rpcScope.RecordRequest(request); var responseContinuation = continuation(request, rpcScope.Context); var responseAsync = responseContinuation.ResponseAsync.ContinueWith( @@ -103,7 +112,8 @@ public override AsyncUnaryCall AsyncUnaryCall( rpcScope.CompleteWithException(ex.InnerException); throw ex.InnerException; } - }); + }, + TaskScheduler.Current); return new AsyncUnaryCall( responseAsync, @@ -128,11 +138,16 @@ public override AsyncClientStreamingCall AsyncClientStreami ClientInterceptorContext context, AsyncClientStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 var responseContinuation = continuation(rpcScope.Context); var clientRequestStreamProxy = new ClientStreamWriterProxy( responseContinuation.RequestStream, @@ -154,7 +169,8 @@ public override AsyncClientStreamingCall AsyncClientStreami rpcScope.CompleteWithException(ex.InnerException); throw ex.InnerException; } - }); + }, + TaskScheduler.Current); return new AsyncClientStreamingCall( clientRequestStreamProxy, @@ -181,11 +197,16 @@ public override AsyncServerStreamingCall AsyncServerStreamingCall context, AsyncServerStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 rpcScope.RecordRequest(request); var responseContinuation = continuation(request, rpcScope.Context); @@ -218,11 +239,16 @@ public override AsyncDuplexStreamingCall AsyncDuplexStreami ClientInterceptorContext context, AsyncDuplexStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 var responseContinuation = continuation(rpcScope.Context); var requestStreamProxy = new ClientStreamWriterProxy( diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs index 5e7898b58d..79b23e9320 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs @@ -27,7 +27,7 @@ public class ClientTracingInterceptorOptions /// /// Gets or sets a value indicating whether or not to record individual message events. /// - public bool RecordMessageEvents { get; set; } = false; + public bool RecordMessageEvents { get; set; } /// /// Gets the propagator. diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs index a1a7c50cdf..d5c8c6d882 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs @@ -46,7 +46,7 @@ internal abstract class RpcScope : IDisposable /// /// The complete flag. /// - private long complete = 0; + private long complete; /// /// The request message counter. diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs index aaab133b95..919dd8a0da 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs @@ -54,6 +54,9 @@ public override async Task UnaryServerHandler( ServerCallContext context, UnaryServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -77,6 +80,9 @@ public override async Task ClientStreamingServerHandler continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -104,6 +110,9 @@ public override async Task ServerStreamingServerHandler( ServerCallContext context, ServerStreamingServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -127,6 +136,9 @@ public override async Task ServerStreamingServerHandler( /// public override async Task DuplexStreamingServerHandler(IAsyncStreamReader requestStream, IServerStreamWriter responseStream, ServerCallContext context, DuplexStreamingServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs index 94fbea9967..3b982d0c08 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs @@ -27,7 +27,7 @@ public class ServerTracingInterceptorOptions /// /// Gets or sets a value indicating whether or not to record individual message events. /// - public bool RecordMessageEvents { get; set; } = false; + public bool RecordMessageEvents { get; set; } /// /// Gets the propagator. diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs index 88279bedf7..dbddf6abf2 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs +++ b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs @@ -28,7 +28,7 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Implementation; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Trace; -internal class HangfireInstrumentationJobFilterAttribute : JobFilterAttribute, IServerFilter, IClientFilter +internal sealed class HangfireInstrumentationJobFilterAttribute : JobFilterAttribute, IServerFilter, IClientFilter { private readonly HangfireInstrumentationOptions options; @@ -37,6 +37,8 @@ public HangfireInstrumentationJobFilterAttribute(HangfireInstrumentationOptions this.options = options; } + public HangfireInstrumentationOptions Options { get; } + public void OnPerforming(PerformingContext performingContext) { // Short-circuit if nobody is listening @@ -123,7 +125,7 @@ private static void InjectActivityProperties(IDictionary jobPara private static IEnumerable ExtractActivityProperties(Dictionary telemetryData, string key) { - return telemetryData.ContainsKey(key) ? new[] { telemetryData[key] } : Enumerable.Empty(); + return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty(); } private void SetStatusAndRecordException(Activity activity, Exception exception) diff --git a/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs b/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs index 1cc31f9012..31f10c9968 100644 --- a/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs +++ b/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; +using System.Globalization; using System.Linq.Expressions; using System.Reflection; using MySql.Data.MySqlClient; @@ -113,7 +114,7 @@ public override void TraceEvent( break; case MySqlTraceEventType.QueryClosed: // args: [driverId] - this.AfterExecuteCommand(); + AfterExecuteCommand(); break; case MySqlTraceEventType.StatementPrepared: break; @@ -129,7 +130,7 @@ public override void TraceEvent( break; case MySqlTraceEventType.Error: // args: [driverId, exNumber, exMessage] - this.ErrorExecuteCommand(this.GetMySqlErrorException(args[2])); + this.ErrorExecuteCommand(GetMySqlErrorException(args[2])); break; case MySqlTraceEventType.QueryNormalized: // Should use QueryNormalized event when it exists. Because cmdText in QueryOpened event is incomplete when cmdText.length>300 @@ -137,13 +138,46 @@ public override void TraceEvent( this.OverwriteDbStatement(this.GetCommand(args[0], args[2])); break; default: - MySqlDataInstrumentationEventSource.Log.UnknownMySqlTraceEventType(id, string.Format(format, args)); + MySqlDataInstrumentationEventSource.Log.UnknownMySqlTraceEventType(id, string.Format(CultureInfo.InvariantCulture, format, args)); break; } } catch (Exception e) { - MySqlDataInstrumentationEventSource.Log.ErrorTraceEvent(id, string.Format(format, args), e.ToString()); + MySqlDataInstrumentationEventSource.Log.ErrorTraceEvent(id, string.Format(CultureInfo.InvariantCulture, format, args), e.ToString()); + } + } + + private static Exception GetMySqlErrorException(object errorMsg) + { +#pragma warning disable CA2201 // Do not raise reserved exception types + return new Exception(errorMsg?.ToString()); +#pragma warning restore CA2201 // Do not raise reserved exception types + } + + private static void AfterExecuteCommand() + { + var activity = Activity.Current; + if (activity == null) + { + return; + } + + if (activity.Source != MySqlActivitySourceHelper.ActivitySource) + { + return; + } + + try + { + if (activity.IsAllDataRequested) + { + activity.SetStatus(Status.Unset); + } + } + finally + { + activity.Stop(); } } @@ -198,32 +232,6 @@ private void OverwriteDbStatement(MySqlDataTraceCommand command) } } - private void AfterExecuteCommand() - { - var activity = Activity.Current; - if (activity == null) - { - return; - } - - if (activity.Source != MySqlActivitySourceHelper.ActivitySource) - { - return; - } - - try - { - if (activity.IsAllDataRequested) - { - activity.SetStatus(Status.Unset); - } - } - finally - { - activity.Stop(); - } - } - private void ErrorExecuteCommand(Exception exception) { var activity = Activity.Current; @@ -266,11 +274,6 @@ private MySqlDataTraceCommand GetCommand(object driverIdObj, object cmd) return command; } - private Exception GetMySqlErrorException(object errorMsg) - { - return new Exception($"{errorMsg}"); - } - private void AddConnectionLevelDetailsToActivity(MySqlConnectionStringBuilder dataSource, Activity sqlActivity) { if (!this.options.EnableConnectionLevelAttributes) diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md index 89c3c949b6..83686c293b 100644 --- a/src/OpenTelemetry.Instrumentation.Process/README.md +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -5,13 +5,12 @@ This is an [Instrumentation Library](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library), -which instruments [.NET](https://docs.microsoft.com/dotnet) and -collect telemetry about process behavior. +which instruments [.NET](https://docs.microsoft.com/dotnet) and collects +telemetry about process behavior. The process metric instruments being implemented are following OpenTelemetry -[metrics semantic conventions][1]. - -[1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md#metric-instruments +[metrics semantic +conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md#metric-instruments). ## Steps to enable OpenTelemetry.Instrumentation.Process @@ -46,7 +45,23 @@ using var meterProvider = Sdk.CreateMeterProviderBuilder() ``` Refer to [Program.cs](../../examples/process-instrumentation/Program.cs) for a -complete demo. +complete demo. This examples sets up the OpenTelemetry Prometheus exporter, +which requires adding the package +[`OpenTelemetry.Exporter.Prometheus.HttpListener`](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.Prometheus.HttpListener/README.md) +to the application. + +Additionally, this +[document](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/metrics/getting-started-prometheus-grafana/README.md) +shows how to use Prometheus and Grafana to build a dashboard for your +application. +[This](../../examples/process-instrumentation/process-instrumentation-grafana-dashboard-sample.json) +is the Grafana dashboard template which has all the metrics currently supported +by this package; plus an additional aggregated metric `CPU utilization` +calculated with the raw metrics, `CPU time` and `CPU count`. + +Please follow the instructions in this +[document](https://grafana.com/docs/grafana/v9.0/dashboards/export-import/) to +import a Grafana dashboard by uploading the JSON template file. ## Metrics @@ -61,15 +76,15 @@ The amount of physical memory allocated for this process. The API used to retrieve the value is: * [Process.WorkingSet64](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.workingset64): -Gets the amount of physical memory, in bytes, -allocated for the associated process. +Gets the amount of physical memory, in bytes, allocated for the associated +process. ### process.memory.virtual -The amount of committed virtual memory for this process. -One way to think of this is all the address space this process can read from -without triggering an access violation; this includes memory backed solely by RAM, -by a swapfile/pagefile and by other mapped files on disk. +The amount of committed virtual memory for this process. One way to think of +this is all the address space this process can read from without triggering an +access violation; this includes memory backed solely by RAM, by a +swapfile/pagefile and by other mapped files on disk. | Units | Instrument Type | Value Type | |-------|-------------------------|------------| @@ -78,8 +93,8 @@ by a swapfile/pagefile and by other mapped files on disk. The API used to retrieve the value is: * [Process.VirtualMemorySize64](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.virtualmemorysize64): -Gets the amount of the virtual memory, in bytes, -allocated for the associated process. +Gets the amount of the virtual memory, in bytes, allocated for the associated +process. ### process.cpu.time @@ -105,14 +120,14 @@ The number of processors (CPU cores) available to the current process. |---------------|-------------------------|------------| | `{processors}`| ObservableUpDownCounter | `Int32` | -The API used to retrieve the value is [System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). - -> **Note** -> This metric is under [discussion][2] and not part of the -[Process Metrics Spec][3] at this time. +The API used to retrieve the value is +[System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount). -[2]: https://github.com/open-telemetry/opentelemetry-specification/issues/3200 -[3]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md +> **Note** This metric is under +> [discussion](https://github.com/open-telemetry/opentelemetry-specification/issues/3200) +and not part of the [Process Metrics +Spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md) +at this time. ### process.threads @@ -125,8 +140,7 @@ Process threads count. The API used to retrieve the value is: * [Process.Threads](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.threads): -Gets the set of threads that are running -in the associated process. +Gets the set of threads that are running in the associated process. ## References diff --git a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs index 9208c22bad..6e38ee2f7f 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs @@ -53,10 +53,10 @@ public override void OnStartActivity(Activity activity, object payload) return; } - activity.DisplayName = this.GetDisplayName(activity); + activity.DisplayName = GetDisplayName(activity); ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource); - ActivityInstrumentationHelper.SetKindProperty(activity, this.GetActivityKind(activity)); + ActivityInstrumentationHelper.SetKindProperty(activity, GetActivityKind(activity)); try { @@ -115,17 +115,17 @@ public override void OnException(Activity activity, object payload) } } - private string GetDisplayName(Activity activity) + private static string GetDisplayName(Activity activity) { return activity.OperationName switch { - OperationName.Job.Execute => $"execute {this.GetTag(activity.Tags, TagName.JobName)}", - OperationName.Job.Veto => $"veto {this.GetTag(activity.Tags, TagName.JobName)}", + OperationName.Job.Execute => $"execute {GetTag(activity.Tags, TagName.JobName)}", + OperationName.Job.Veto => $"veto {GetTag(activity.Tags, TagName.JobName)}", _ => activity.DisplayName, }; } - private ActivityKind GetActivityKind(Activity activity) + private static ActivityKind GetActivityKind(Activity activity) { return activity.OperationName switch { @@ -135,7 +135,7 @@ private ActivityKind GetActivityKind(Activity activity) }; } - private string GetTag(IEnumerable> tags, string tagName) + private static string GetTag(IEnumerable> tags, string tagName) { var tag = tags.SingleOrDefault(kv => kv.Key == tagName); return tag.Value; diff --git a/src/OpenTelemetry.Instrumentation.Quartz/OperationName.cs b/src/OpenTelemetry.Instrumentation.Quartz/OperationName.cs index b173e14041..4a1e6ed492 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/OperationName.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/OperationName.cs @@ -24,7 +24,9 @@ public static class OperationName /// /// Quartz Job category constants. /// +#pragma warning disable CA1034 // Nested types should not be visible public static class Job +#pragma warning restore CA1034 // Nested types should not be visible { /// /// Quartz job execute diagnostic source operation name. diff --git a/src/OpenTelemetry.Instrumentation.Quartz/QuartzInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Quartz/QuartzInstrumentationOptions.cs index ac9572ef54..4e726f3f72 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/QuartzInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/QuartzInstrumentationOptions.cs @@ -56,5 +56,7 @@ public class QuartzInstrumentationOptions /// /// Gets or sets traced operations set. /// +#pragma warning disable CA2227 // Collection properties should be read only public HashSet TracedOperations { get; set; } = new(DefaultTracedOperations); +#pragma warning restore CA2227 // Collection properties should be read only } diff --git a/src/OpenTelemetry.Instrumentation.Quartz/TraceProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.Quartz/TraceProviderBuilderExtensions.cs index dd84eb51f4..9461dcc585 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/TraceProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/TraceProviderBuilderExtensions.cs @@ -17,6 +17,7 @@ using System; using OpenTelemetry.Instrumentation.Quartz; using OpenTelemetry.Instrumentation.Quartz.Implementation; +using OpenTelemetry.Internal; // ReSharper disable once CheckNamespace namespace OpenTelemetry.Trace; @@ -44,6 +45,8 @@ public static TracerProviderBuilder AddQuartzInstrumentation( this TracerProviderBuilder builder, Action configure) { + Guard.ThrowIfNull(builder); + var options = new QuartzInstrumentationOptions(); configure?.Invoke(options); 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; } } 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"); + })); + }); + } +} diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs index 816c34a496..c4a55c3755 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs @@ -34,20 +34,20 @@ 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 activity) + public override void OnStart(Activity data) { - this.StartAction?.Invoke(activity); + this.StartAction?.Invoke(data); } - public override void OnEnd(Activity activity) + public override void OnEnd(Activity data) { - this.EndAction?.Invoke(activity); + this.EndAction?.Invoke(data); } protected override bool OnShutdown(int timeoutMilliseconds) diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs index 09a4c2dfd2..7bb3af2851 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs @@ -33,7 +33,17 @@ internal class FoobarService : Foobar.FoobarBase /// /// Default traceparent header value with the sampling bit on. /// - internal static readonly string DefaultTraceparentWithSampling = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; + internal const string DefaultTraceparentWithSampling = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; + + /// + /// The request header fail with status code. + /// + internal const string RequestHeaderFailWithStatusCode = "failurestatuscode"; + + /// + /// The request header error description. + /// + internal const string RequestHeaderErrorDescription = "failuredescription"; /// /// The default parent from a traceparent header. @@ -60,16 +70,6 @@ internal class FoobarService : Foobar.FoobarBase /// internal static readonly int DefaultResponseMessageSize = ((IMessage)DefaultResponseMessage).CalculateSize(); - /// - /// The request header fail with status code. - /// - internal static readonly string RequestHeaderFailWithStatusCode = "failurestatuscode"; - - /// - /// The request header error description. - /// - internal static readonly string RequestHeaderErrorDescription = "failuredescription"; - /// /// Starts the specified service. /// diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs index 458075c61e..53e8b810f0 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs @@ -35,7 +35,7 @@ public class GrpcCoreClientInterceptorTests /// /// A bogus server uri. /// - private static readonly string BogusServerUri = "dns:i.dont.exist:77923"; + private const string BogusServerUri = "dns:i.dont.exist:77923"; /// /// The default metadata func. @@ -49,7 +49,7 @@ public class GrpcCoreClientInterceptorTests [Fact] public async Task AsyncUnarySuccess() { - await this.TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -59,7 +59,7 @@ public async Task AsyncUnarySuccess() [Fact] public async Task AsyncUnaryUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeUnaryAsyncRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -73,7 +73,7 @@ await this.TestHandlerFailure( [Fact] public async Task AsyncUnaryFail() { - await this.TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -97,7 +97,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task ClientStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeClientStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeClientStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -107,7 +107,7 @@ public async Task ClientStreamingSuccess() [Fact] public async Task ClientStreamingUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeClientStreamingRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -121,7 +121,7 @@ await this.TestHandlerFailure( [Fact] public async Task ClientStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -145,7 +145,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task ServerStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeServerStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeServerStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -155,7 +155,7 @@ public async Task ServerStreamingSuccess() [Fact] public async Task ServerStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -179,7 +179,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task DuplexStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -189,7 +189,7 @@ public async Task DuplexStreamingSuccess() [Fact] public async Task DuplexStreamingUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeDuplexStreamingRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -203,7 +203,7 @@ await this.TestHandlerFailure( [Fact] public async Task DuplexStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -376,7 +376,7 @@ static void ValidateCommonEventAttributes(ActivityEvent activityEvent) /// The client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata) + private static async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata) { var mockPropagator = new Mock(); PropagationContext capturedPropagationContext = default; @@ -482,7 +482,7 @@ private async Task TestHandlerSuccess(Func /// /// A Task. /// - private async Task TestHandlerFailure( + private static async Task TestHandlerFailure( Func clientRequestFunc, StatusCode statusCode = StatusCode.ResourceExhausted, bool validateErrorDescription = true, diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs index 947f6cc88b..916f5779dd 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs @@ -35,7 +35,7 @@ public class GrpcCoreServerInterceptorTests [Fact] public async Task UnaryServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -45,7 +45,7 @@ public async Task UnaryServerHandlerSuccess() [Fact] public async Task UnaryServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -55,7 +55,7 @@ public async Task UnaryServerHandlerFail() [Fact] public async Task ClientStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -65,7 +65,7 @@ public async Task ClientStreamingServerHandlerSuccess() [Fact] public async Task ClientStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -75,7 +75,7 @@ public async Task ClientStreamingServerHandlerFail() [Fact] public async Task ServerStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -85,7 +85,7 @@ public async Task ServerStreamingServerHandlerSuccess() [Fact] public async Task ServerStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -95,7 +95,7 @@ public async Task ServerStreamingServerHandlerFail() [Fact] public async Task DuplexStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -105,7 +105,7 @@ public async Task DuplexStreamingServerHandlerSuccess() [Fact] public async Task DuplexStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -114,7 +114,7 @@ public async Task DuplexStreamingServerHandlerFail() /// The specific client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata = null) + private static async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata = null) { // starts the server with the server interceptor var interceptorOptions = new ServerTracingInterceptorOptions { Propagator = new TraceContextPropagator(), RecordMessageEvents = true, ActivityIdentifierValue = Guid.NewGuid() }; @@ -155,7 +155,7 @@ private async Task TestHandlerSuccess(Func /// The specific client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerFailure(Func clientRequestFunc, Metadata additionalMetadata = null) + private static async Task TestHandlerFailure(Func clientRequestFunc, Metadata additionalMetadata = null) { // starts the server with the server interceptor var interceptorOptions = new ServerTracingInterceptorOptions { Propagator = new TraceContextPropagator(), ActivityIdentifierValue = Guid.NewGuid() }; diff --git a/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs b/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs index 3f4c105897..0f29d966f6 100644 --- a/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs +++ b/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs @@ -55,7 +55,7 @@ public void SuccessTraceEventTest( var traceListener = (TraceListener)Assert.Single(MySqlTrace.Listeners); - this.ExecuteSuccessQuery(traceListener, commandText, isFailure); + ExecuteSuccessQuery(traceListener, commandText, isFailure); Assert.Equal(3, activityProcessor.Invocations.Count); @@ -170,7 +170,7 @@ private static void VerifyActivityData( } } - private void ExecuteSuccessQuery(TraceListener listener, string query, bool isFailure) + private static void ExecuteSuccessQuery(TraceListener listener, string query, bool isFailure) { // Connection opened listener.TraceEvent( diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs index b5f98b7d07..10a3e9ff76 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs @@ -106,9 +106,9 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() if (payload is IJobDetail jobDetail) { var dataMap = jobDetail.JobDataMap; - if (dataMap.ContainsKey("TestId")) + if (dataMap.TryGetValue("TestId", out var value)) { - a.SetTag("test.id", dataMap["TestId"]); + a.SetTag("test.id", value); } } }) @@ -229,9 +229,9 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri if (p is IJobDetail jobDetail) { var dataMap = jobDetail.JobDataMap; - if (dataMap.ContainsKey("TestId")) + if (dataMap.TryGetValue("TestId", out var value)) { - a.SetTag("test.id", dataMap["TestId"]); + a.SetTag("test.id", value); } } };