diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props
index 38928926cf..29cd1456ea 100644
--- a/build/Common.nonprod.props
+++ b/build/Common.nonprod.props
@@ -28,7 +28,7 @@
net8.0;net6.0
[2.8.2,3.0)
[2.9.0,3.0)
- [1.6.1,2.0)
+ [1.6.3,2.0)
diff --git a/build/Common.props b/build/Common.props
index 3c4da312f4..52f8c3bcc0 100644
--- a/build/Common.props
+++ b/build/Common.props
@@ -14,8 +14,7 @@
enable
enable
true
-
-
+ all
low
diff --git a/examples/wcf/client-core/Examples.Wcf.Client.DotNet.csproj b/examples/wcf/client-core/Examples.Wcf.Client.DotNet.csproj
index f87ebac82a..38ac618f6a 100644
--- a/examples/wcf/client-core/Examples.Wcf.Client.DotNet.csproj
+++ b/examples/wcf/client-core/Examples.Wcf.Client.DotNet.csproj
@@ -9,8 +9,10 @@
-
+
+
+
diff --git a/examples/wcf/shared/Examples.Wcf.Shared.csproj b/examples/wcf/shared/Examples.Wcf.Shared.csproj
index 265744f7ed..bcef073cb9 100644
--- a/examples/wcf/shared/Examples.Wcf.Shared.csproj
+++ b/examples/wcf/shared/Examples.Wcf.Shared.csproj
@@ -2,7 +2,7 @@
- netstandard2.0;net462
+ net8.0;net462
@@ -10,8 +10,15 @@
-
+
+
+
+
+
+
+
+
diff --git a/src/OpenTelemetry.Exporter.InfluxDB/CHANGELOG.md b/src/OpenTelemetry.Exporter.InfluxDB/CHANGELOG.md
index a919418175..271706b380 100644
--- a/src/OpenTelemetry.Exporter.InfluxDB/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.InfluxDB/CHANGELOG.md
@@ -5,6 +5,11 @@
* Updated OpenTelemetry core component version(s) to `1.9.0`.
([#1888](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1888))
+* Updated `InfluxDB.Client` to `4.18.0` to mitigate [CVE-2024-45302](https://github.com/advisories/GHSA-4rr6-2v9v-wcpc)
+ and [CVE-2024-30105](https://github.com/advisories/GHSA-hh2w-p6rv-4g7w)
+ in transitive dependencies.
+ ([#2073](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2073))
+
## 1.0.0-alpha.3
Released 2023-Oct-13
diff --git a/src/OpenTelemetry.Exporter.InfluxDB/OpenTelemetry.Exporter.InfluxDB.csproj b/src/OpenTelemetry.Exporter.InfluxDB/OpenTelemetry.Exporter.InfluxDB.csproj
index f1c7da1493..9da39c289a 100644
--- a/src/OpenTelemetry.Exporter.InfluxDB/OpenTelemetry.Exporter.InfluxDB.csproj
+++ b/src/OpenTelemetry.Exporter.InfluxDB/OpenTelemetry.Exporter.InfluxDB.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.ConfluentKafka/.publicApi/PublicAPI.Unshipped.txt
index a577dafdcd..33f9216f8b 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/.publicApi/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/.publicApi/PublicAPI.Unshipped.txt
@@ -17,14 +17,18 @@ static Confluent.Kafka.OpenTelemetryConsumeResultExtensions.TryExtractPropagatio
static Confluent.Kafka.OpenTelemetryProducerBuilderExtensions.AsInstrumentedProducerBuilder(this Confluent.Kafka.ProducerBuilder! producerBuilder) -> Confluent.Kafka.InstrumentedProducerBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, Confluent.Kafka.InstrumentedConsumerBuilder! consumerBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
+static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, string? name) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, string? name, Confluent.Kafka.InstrumentedConsumerBuilder? consumerBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, Confluent.Kafka.InstrumentedProducerBuilder! producerBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
+static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, string? name) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, string? name, Confluent.Kafka.InstrumentedProducerBuilder? producerBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, Confluent.Kafka.InstrumentedConsumerBuilder! consumerBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder!
+static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, string? name) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaConsumerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, string? name, Confluent.Kafka.InstrumentedConsumerBuilder? consumerBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, Confluent.Kafka.InstrumentedProducerBuilder! producerBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder!
+static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, string? name) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddKafkaProducerInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, string? name, Confluent.Kafka.InstrumentedProducerBuilder? producerBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder!
virtual Confluent.Kafka.OpenTelemetryConsumeAndProcessMessageHandler.Invoke(Confluent.Kafka.ConsumeResult! consumeResult, System.Diagnostics.Activity? activity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md
index 42980dd334..ce758fbebc 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/CHANGELOG.md
@@ -2,8 +2,15 @@
## Unreleased
+## 0.1.0-alpha.2
+
+Released 2024-Sep-18
+
+- Add named instrumentation support
+ ([#2074](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2074))
+
## 0.1.0-alpha.1
Released 2024-Sep-16
-* Initial release
+- Initial release
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedConsumerBuilder.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedConsumerBuilder.cs
index edc70f9085..8affdfa5fd 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedConsumerBuilder.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedConsumerBuilder.cs
@@ -1,7 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
-using System.Diagnostics;
using OpenTelemetry.Instrumentation.ConfluentKafka;
namespace Confluent.Kafka;
@@ -13,6 +12,8 @@ namespace Confluent.Kafka;
/// Type of value.
public sealed class InstrumentedConsumerBuilder : ConsumerBuilder
{
+ private readonly ConfluentKafkaConsumerInstrumentationOptions options = new();
+
///
/// Initializes a new instance of the class.
///
@@ -22,7 +23,17 @@ public InstrumentedConsumerBuilder(IEnumerable> con
{
}
- internal ConfluentKafkaConsumerInstrumentationOptions? Options { get; set; }
+ internal bool EnableMetrics
+ {
+ get => this.options.Metrics;
+ set => this.options.Metrics = value;
+ }
+
+ internal bool EnableTraces
+ {
+ get => this.options.Traces;
+ set => this.options.Traces = value;
+ }
///
/// Build a new IConsumer instance.
@@ -30,11 +41,9 @@ public InstrumentedConsumerBuilder(IEnumerable> con
/// an .
public override IConsumer Build()
{
- Debug.Assert(this.Options != null, "Options should not be null.");
-
ConsumerConfig config = (ConsumerConfig)this.Config;
- var consumer = new InstrumentedConsumer(base.Build(), this.Options!);
+ var consumer = new InstrumentedConsumer(base.Build(), this.options);
consumer.GroupId = config.GroupId;
return consumer;
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducer.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducer.cs
index a91c04314c..b47caa3591 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducer.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducer.cs
@@ -27,8 +27,6 @@ public InstrumentedProducer(
public string Name => this.producer.Name;
- internal ConfluentKafkaProducerInstrumentationOptions Options => this.options;
-
public int AddBrokers(string brokers)
{
return this.producer.AddBrokers(brokers);
@@ -326,6 +324,11 @@ private static void RecordPublish(TopicPartition topicPartition, TimeSpan durati
private Activity? StartPublishActivity(DateTimeOffset start, string topic, Message message, int? partition = null)
{
+ if (!this.options.Traces)
+ {
+ return null;
+ }
+
var spanName = string.Concat(topic, " ", ConfluentKafkaCommon.PublishOperationName);
var activity = ConfluentKafkaCommon.ActivitySource.StartActivity(name: spanName, kind: ActivityKind.Producer, startTime: start);
if (activity == null)
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducerBuilder.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducerBuilder.cs
index eaefacdc19..79e9a25748 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducerBuilder.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/InstrumentedProducerBuilder.cs
@@ -1,7 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
-using System.Diagnostics;
using OpenTelemetry.Instrumentation.ConfluentKafka;
namespace Confluent.Kafka;
@@ -13,6 +12,8 @@ namespace Confluent.Kafka;
/// Type of value.
public sealed class InstrumentedProducerBuilder : ProducerBuilder
{
+ private readonly ConfluentKafkaProducerInstrumentationOptions options = new();
+
///
/// Initializes a new instance of the class.
///
@@ -22,7 +23,17 @@ public InstrumentedProducerBuilder(IEnumerable> con
{
}
- internal ConfluentKafkaProducerInstrumentationOptions? Options { get; set; }
+ internal bool EnableMetrics
+ {
+ get => this.options.Metrics;
+ set => this.options.Metrics = value;
+ }
+
+ internal bool EnableTraces
+ {
+ get => this.options.Traces;
+ set => this.options.Traces = value;
+ }
///
/// Build a new IProducer instance.
@@ -30,8 +41,6 @@ public InstrumentedProducerBuilder(IEnumerable> con
/// an .
public override IProducer Build()
{
- Debug.Assert(this.Options != null, "Options should not be null.");
-
- return new InstrumentedProducer(base.Build(), this.Options!);
+ return new InstrumentedProducer(base.Build(), this.options);
}
}
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Consumer.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Consumer.cs
index c2bb25f490..b10b715b2b 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Consumer.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Consumer.cs
@@ -3,7 +3,6 @@
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.ConfluentKafka;
using OpenTelemetry.Internal;
@@ -25,6 +24,18 @@ public static MeterProviderBuilder AddKafkaConsumerInstrumentation
this MeterProviderBuilder builder)
=> AddKafkaConsumerInstrumentation(builder, name: null, consumerBuilder: null);
+ ///
+ /// Enables automatic data collection of outgoing requests to Kafka.
+ ///
+ /// The type of the key.
+ /// The type of the value.
+ /// being configured.
+ /// The name of the instrumentation.
+ /// The instance of to chain the calls.
+ public static MeterProviderBuilder AddKafkaConsumerInstrumentation(
+ this MeterProviderBuilder builder, string? name)
+ => AddKafkaConsumerInstrumentation(builder, name: name, consumerBuilder: null);
+
///
/// Enables automatic data collection of outgoing requests to Kafka.
///
@@ -58,34 +69,21 @@ public static MeterProviderBuilder AddKafkaConsumerInstrumentation
{
Guard.ThrowIfNull(builder);
- name ??= Options.DefaultName;
-
- builder.ConfigureServices(services =>
- {
- services.Configure>(name, EnableMetrics);
- });
-
return builder
.AddMeter(ConfluentKafkaCommon.InstrumentationName)
.AddInstrumentation(sp =>
{
- if (consumerBuilder == null)
+ if (name == null)
{
- consumerBuilder = sp.GetRequiredService>();
- var options = sp.GetRequiredService>>();
- consumerBuilder.Options = options.Get(name);
+ consumerBuilder ??= sp.GetRequiredService>();
}
-
- if (consumerBuilder.Options == null)
+ else
{
- consumerBuilder.Options = new ConfluentKafkaConsumerInstrumentationOptions();
- EnableMetrics(consumerBuilder.Options);
+ consumerBuilder ??= sp.GetRequiredKeyedService>(name);
}
+ consumerBuilder.EnableMetrics = true;
return new ConfluentKafkaConsumerInstrumentation(consumerBuilder);
});
}
-
- private static void EnableMetrics(ConfluentKafkaConsumerInstrumentationOptions options) =>
- options.Metrics = true;
}
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Producer.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Producer.cs
index e5fb587066..387761679e 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Producer.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/MeterProviderBuilderExtensions.Producer.cs
@@ -3,7 +3,6 @@
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.ConfluentKafka;
using OpenTelemetry.Internal;
@@ -25,6 +24,18 @@ public static MeterProviderBuilder AddKafkaProducerInstrumentation
this MeterProviderBuilder builder)
=> AddKafkaProducerInstrumentation(builder, name: null, producerBuilder: null);
+ ///
+ /// Enables automatic data collection of outgoing requests to Kafka.
+ ///
+ /// The type of the key.
+ /// The type of the value.
+ /// being configured.
+ /// The name of the instrumentation.
+ /// The instance of to chain the calls.
+ public static MeterProviderBuilder AddKafkaProducerInstrumentation(
+ this MeterProviderBuilder builder, string? name)
+ => AddKafkaProducerInstrumentation(builder, name: name, producerBuilder: null);
+
///
/// Enables automatic data collection of outgoing requests to Kafka.
///
@@ -58,34 +69,21 @@ public static MeterProviderBuilder AddKafkaProducerInstrumentation
{
Guard.ThrowIfNull(builder);
- name ??= Options.DefaultName;
-
- builder.ConfigureServices(services =>
- {
- services.Configure>(name, EnableMetrics);
- });
-
return builder
.AddMeter(ConfluentKafkaCommon.InstrumentationName)
.AddInstrumentation(sp =>
{
- if (producerBuilder == null)
+ if (name == null)
{
- producerBuilder = sp.GetRequiredService>();
- var options = sp.GetRequiredService>>();
- producerBuilder.Options = options.Get(name);
+ producerBuilder ??= sp.GetRequiredService>();
}
-
- if (producerBuilder.Options == null)
+ else
{
- producerBuilder.Options = new ConfluentKafkaProducerInstrumentationOptions();
- EnableMetrics(producerBuilder.Options);
+ producerBuilder ??= sp.GetRequiredKeyedService>(name);
}
+ producerBuilder.EnableMetrics = true;
return new ConfluentKafkaProducerInstrumentation(producerBuilder);
});
}
-
- private static void EnableMetrics(ConfluentKafkaProducerInstrumentationOptions options) =>
- options.Metrics = true;
}
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Consumer.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Consumer.cs
index ee6025f885..bf1a4e95a5 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Consumer.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Consumer.cs
@@ -3,7 +3,6 @@
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.ConfluentKafka;
using OpenTelemetry.Internal;
@@ -25,6 +24,18 @@ public static TracerProviderBuilder AddKafkaConsumerInstrumentation AddKafkaConsumerInstrumentation(builder, name: null, consumerBuilder: null);
+ ///
+ /// Enables automatic data collection of outgoing requests to Kafka.
+ ///
+ /// The type of the key.
+ /// The type of the value.
+ /// being configured.
+ /// The name of the instrumentation.
+ /// The instance of to chain the calls.
+ public static TracerProviderBuilder AddKafkaConsumerInstrumentation(
+ this TracerProviderBuilder builder, string? name)
+ => AddKafkaConsumerInstrumentation(builder, name: name, consumerBuilder: null);
+
///
/// Enables automatic data collection of outgoing requests to Kafka.
///
@@ -48,7 +59,7 @@ public static TracerProviderBuilder AddKafkaConsumerInstrumentationThe type of the key.
/// The type of the value.
/// being configured.
- /// Optional name which is used when retrieving options.
+ /// The name of the instrumentation.
/// Optional to instrument.
/// The instance of to chain the calls.
public static TracerProviderBuilder AddKafkaConsumerInstrumentation(
@@ -58,34 +69,21 @@ public static TracerProviderBuilder AddKafkaConsumerInstrumentation
- {
- services.Configure>(name, EnableTracing);
- });
-
return builder
.AddSource(ConfluentKafkaCommon.InstrumentationName)
.AddInstrumentation(sp =>
{
- if (consumerBuilder == null)
+ if (name == null)
{
- consumerBuilder = sp.GetRequiredService>();
- var options = sp.GetRequiredService>>();
- consumerBuilder.Options = options.Get(name);
+ consumerBuilder ??= sp.GetRequiredService>();
}
-
- if (consumerBuilder.Options == null)
+ else
{
- consumerBuilder.Options = new ConfluentKafkaConsumerInstrumentationOptions();
- EnableTracing(consumerBuilder.Options);
+ consumerBuilder ??= sp.GetRequiredKeyedService>(name);
}
+ consumerBuilder.EnableTraces = true;
return new ConfluentKafkaConsumerInstrumentation(consumerBuilder);
});
}
-
- private static void EnableTracing(ConfluentKafkaConsumerInstrumentationOptions options) =>
- options.Traces = true;
}
diff --git a/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Producer.cs b/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Producer.cs
index 5f8adbfb84..8e427c7a32 100644
--- a/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Producer.cs
+++ b/src/OpenTelemetry.Instrumentation.ConfluentKafka/TracerProviderBuilderExtensions.Producer.cs
@@ -3,7 +3,6 @@
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.ConfluentKafka;
using OpenTelemetry.Internal;
@@ -25,6 +24,18 @@ public static TracerProviderBuilder AddKafkaProducerInstrumentation AddKafkaProducerInstrumentation(builder, name: null, producerBuilder: null);
+ ///
+ /// Enables automatic data collection of outgoing requests to Kafka.
+ ///
+ /// The type of the key.
+ /// The type of the value.
+ /// being configured.
+ /// The name of the instrumentation.
+ /// The instance of to chain the calls.
+ public static TracerProviderBuilder AddKafkaProducerInstrumentation(
+ this TracerProviderBuilder builder, string? name)
+ => AddKafkaProducerInstrumentation(builder, name: name, producerBuilder: null);
+
///
/// Enables automatic data collection of outgoing requests to Kafka.
///
@@ -48,7 +59,7 @@ public static TracerProviderBuilder AddKafkaProducerInstrumentationThe type of the key.
/// The type of the value.
/// being configured.
- /// Optional name which is used when retrieving options.
+ /// The name of the instrumentation.
/// Optional to instrument.
/// The instance of to chain the calls.
public static TracerProviderBuilder AddKafkaProducerInstrumentation(
@@ -58,34 +69,21 @@ public static TracerProviderBuilder AddKafkaProducerInstrumentation
- {
- services.Configure>(name, EnableTracing);
- });
-
return builder
.AddSource(ConfluentKafkaCommon.InstrumentationName)
.AddInstrumentation(sp =>
{
- if (producerBuilder == null)
+ if (name == null)
{
- producerBuilder = sp.GetRequiredService>();
- var options = sp.GetRequiredService>>();
- producerBuilder.Options = options.Get(name);
+ producerBuilder ??= sp.GetRequiredService>();
}
-
- if (producerBuilder.Options == null)
+ else
{
- producerBuilder.Options = new ConfluentKafkaProducerInstrumentationOptions();
- EnableTracing(producerBuilder.Options);
+ producerBuilder ??= sp.GetRequiredKeyedService>(name);
}
+ producerBuilder.EnableTraces = true;
return new ConfluentKafkaProducerInstrumentation(producerBuilder);
});
}
-
- private static void EnableTracing(ConfluentKafkaProducerInstrumentationOptions options) =>
- options.Traces = true;
}
diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj
index c4d79207e0..fb9ef875d2 100644
--- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj
+++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj
@@ -13,6 +13,11 @@
+
+
+
+
+
+
+
+
diff --git a/test/OpenTelemetry.Extensions.Enrichment.Tests/OpenTelemetry.Extensions.Enrichment.Tests.csproj b/test/OpenTelemetry.Extensions.Enrichment.Tests/OpenTelemetry.Extensions.Enrichment.Tests.csproj
index c7400ad0a6..b86cc62d34 100644
--- a/test/OpenTelemetry.Extensions.Enrichment.Tests/OpenTelemetry.Extensions.Enrichment.Tests.csproj
+++ b/test/OpenTelemetry.Extensions.Enrichment.Tests/OpenTelemetry.Extensions.Enrichment.Tests.csproj
@@ -11,6 +11,10 @@
+
+
+
+
diff --git a/test/OpenTelemetry.Instrumentation.ConfluentKafka.Tests/HostedTracingAndMeteringTests.cs b/test/OpenTelemetry.Instrumentation.ConfluentKafka.Tests/HostedTracingAndMeteringTests.cs
index adeb619e0d..c49f03deb1 100644
--- a/test/OpenTelemetry.Instrumentation.ConfluentKafka.Tests/HostedTracingAndMeteringTests.cs
+++ b/test/OpenTelemetry.Instrumentation.ConfluentKafka.Tests/HostedTracingAndMeteringTests.cs
@@ -17,41 +17,147 @@ namespace OpenTelemetry.Instrumentation.ConfluentKafka.Tests;
public class HostedTracingAndMeteringTests(ITestOutputHelper outputHelper)
{
[Trait("CategoryName", "KafkaIntegrationTests")]
- [SkipUnlessEnvVarFoundFact(KafkaHelpers.KafkaEndPointEnvVarName)]
- public async Task ResolveInstrumentedBuildersFromHostServiceProviderTest()
+ [SkipUnlessEnvVarFoundTheory(KafkaHelpers.KafkaEndPointEnvVarName)]
+ [InlineData(true, true, true, true, true, true)]
+ [InlineData(true, true, true, true, true, false)]
+ [InlineData(true, true, true, true, false, true)]
+ [InlineData(true, true, true, true, false, false)]
+ [InlineData(true, true, true, false, true, true)]
+ [InlineData(true, true, true, false, true, false)]
+ [InlineData(true, true, true, false, false, true)]
+ [InlineData(true, true, true, false, false, false)]
+ [InlineData(true, true, false, true, true, true)]
+ [InlineData(true, true, false, true, true, false)]
+ [InlineData(true, true, false, true, false, true)]
+ [InlineData(true, true, false, true, false, false)]
+ [InlineData(true, true, false, false, true, true)]
+ [InlineData(true, true, false, false, true, false)]
+ [InlineData(true, true, false, false, false, true)]
+ [InlineData(true, true, false, false, false, false)]
+ [InlineData(true, false, true, true, true, true)]
+ [InlineData(true, false, true, true, true, false)]
+ [InlineData(true, false, true, true, false, true)]
+ [InlineData(true, false, true, true, false, false)]
+ [InlineData(true, false, true, false, true, true)]
+ [InlineData(true, false, true, false, true, false)]
+ [InlineData(true, false, true, false, false, true)]
+ [InlineData(true, false, true, false, false, false)]
+ [InlineData(true, false, false, true, true, true)]
+ [InlineData(true, false, false, true, true, false)]
+ [InlineData(true, false, false, true, false, true)]
+ [InlineData(true, false, false, true, false, false)]
+ [InlineData(true, false, false, false, true, true)]
+ [InlineData(true, false, false, false, true, false)]
+ [InlineData(true, false, false, false, false, true)]
+ [InlineData(true, false, false, false, false, false)]
+ [InlineData(false, true, true, true, true, true)]
+ [InlineData(false, true, true, true, true, false)]
+ [InlineData(false, true, true, true, false, true)]
+ [InlineData(false, true, true, true, false, false)]
+ [InlineData(false, true, true, false, true, true)]
+ [InlineData(false, true, true, false, true, false)]
+ [InlineData(false, true, true, false, false, true)]
+ [InlineData(false, true, true, false, false, false)]
+ [InlineData(false, true, false, true, true, true)]
+ [InlineData(false, true, false, true, true, false)]
+ [InlineData(false, true, false, true, false, true)]
+ [InlineData(false, true, false, true, false, false)]
+ [InlineData(false, true, false, false, true, true)]
+ [InlineData(false, true, false, false, true, false)]
+ [InlineData(false, true, false, false, false, true)]
+ [InlineData(false, true, false, false, false, false)]
+ [InlineData(false, false, true, true, true, true)]
+ [InlineData(false, false, true, true, true, false)]
+ [InlineData(false, false, true, true, false, true)]
+ [InlineData(false, false, true, true, false, false)]
+ [InlineData(false, false, true, false, true, true)]
+ [InlineData(false, false, true, false, true, false)]
+ [InlineData(false, false, true, false, false, true)]
+ [InlineData(false, false, true, false, false, false)]
+ [InlineData(false, false, false, true, true, true)]
+ [InlineData(false, false, false, true, true, false)]
+ [InlineData(false, false, false, true, false, true)]
+ [InlineData(false, false, false, true, false, false)]
+ [InlineData(false, false, false, false, true, true)]
+ [InlineData(false, false, false, false, true, false)]
+ [InlineData(false, false, false, false, false, true)]
+ [InlineData(false, false, false, false, false, false)]
+ public async Task ResolveInstrumentedBuildersFromHostServiceProviderTest(bool enableProducerMetrics, bool enableProducerTraces, bool useNamedProducerInstrumentation, bool enableConsumerMetrics, bool enableConsumerTraces, bool useNamedConsumerInstrumentation)
{
+ string? producerInstrumentationName = useNamedProducerInstrumentation ? "MyProducer" : null;
+ string? consumerInstrumentationName = useNamedConsumerInstrumentation ? "MyConsumer" : null;
List metrics = new();
List activities = new();
var builder = Host.CreateDefaultBuilder();
builder.ConfigureServices(services =>
{
- services.AddSingleton(_ =>
- new InstrumentedProducerBuilder(new ProducerConfig()
- {
- BootstrapServers = KafkaHelpers.KafkaEndPoint,
- }));
- services.AddSingleton(_ =>
- new InstrumentedConsumerBuilder(new ConsumerConfig()
- {
- BootstrapServers = KafkaHelpers.KafkaEndPoint,
- GroupId = Guid.NewGuid().ToString(),
- AutoOffsetReset = AutoOffsetReset.Earliest,
- EnablePartitionEof = true,
- }));
+ if (useNamedProducerInstrumentation)
+ {
+ services.AddKeyedSingleton(producerInstrumentationName, (_, _) =>
+ new InstrumentedProducerBuilder(new ProducerConfig()
+ {
+ BootstrapServers = KafkaHelpers.KafkaEndPoint,
+ }));
+ }
+ else
+ {
+ services.AddSingleton(_ =>
+ new InstrumentedProducerBuilder(new ProducerConfig()
+ {
+ BootstrapServers = KafkaHelpers.KafkaEndPoint,
+ }));
+ }
+
+ if (useNamedConsumerInstrumentation)
+ {
+ services.AddKeyedSingleton(consumerInstrumentationName, (_, _) =>
+ new InstrumentedConsumerBuilder(new ConsumerConfig()
+ {
+ BootstrapServers = KafkaHelpers.KafkaEndPoint,
+ GroupId = Guid.NewGuid().ToString(),
+ AutoOffsetReset = AutoOffsetReset.Earliest,
+ EnablePartitionEof = true,
+ }));
+ }
+ else
+ {
+ services.AddSingleton(_ =>
+ new InstrumentedConsumerBuilder(new ConsumerConfig()
+ {
+ BootstrapServers = KafkaHelpers.KafkaEndPoint,
+ GroupId = Guid.NewGuid().ToString(),
+ AutoOffsetReset = AutoOffsetReset.Earliest,
+ EnablePartitionEof = true,
+ }));
+ }
services.AddOpenTelemetry().WithTracing(tracingBuilder =>
{
tracingBuilder
.AddInMemoryExporter(activities)
- .SetSampler(new TestSampler())
- .AddKafkaProducerInstrumentation()
- .AddKafkaConsumerInstrumentation();
+ .SetSampler(new TestSampler());
+ if (enableProducerTraces)
+ {
+ tracingBuilder.AddKafkaProducerInstrumentation(name: producerInstrumentationName, producerBuilder: null);
+ }
+
+ if (enableConsumerTraces)
+ {
+ tracingBuilder.AddKafkaConsumerInstrumentation(name: consumerInstrumentationName, consumerBuilder: null);
+ }
}).WithMetrics(metricsBuilder =>
{
metricsBuilder
- .AddInMemoryExporter(metrics)
- .AddKafkaProducerInstrumentation()
- .AddKafkaConsumerInstrumentation();
+ .AddInMemoryExporter(metrics);
+ if (enableProducerMetrics)
+ {
+ metricsBuilder.AddKafkaProducerInstrumentation(name: producerInstrumentationName, producerBuilder: null);
+ }
+
+ if (enableConsumerMetrics)
+ {
+ metricsBuilder.AddKafkaConsumerInstrumentation(name: consumerInstrumentationName, consumerBuilder: null);
+ }
});
});
@@ -59,8 +165,21 @@ public async Task ResolveInstrumentedBuildersFromHostServiceProviderTest()
{
await host.StartAsync();
+ var producerBuilder = useNamedProducerInstrumentation
+ ? host.Services.GetRequiredKeyedService>(producerInstrumentationName)
+ : host.Services.GetRequiredService>();
+ Assert.Equal(enableProducerMetrics, producerBuilder.EnableMetrics);
+ Assert.Equal(enableProducerTraces, producerBuilder.EnableTraces);
+ var consumerBuilder = useNamedConsumerInstrumentation
+ ? host.Services.GetRequiredKeyedService>(consumerInstrumentationName)
+ : host.Services.GetRequiredService>();
+ Assert.Equal(enableConsumerMetrics, consumerBuilder.EnableMetrics);
+ Assert.Equal(enableConsumerTraces, consumerBuilder.EnableTraces);
+
string topic = $"otel-topic-{Guid.NewGuid()}";
- using (var producer = host.Services.GetRequiredService>().Build())
+ using (var producer = (useNamedProducerInstrumentation
+ ? host.Services.GetRequiredKeyedService>(producerInstrumentationName)
+ : host.Services.GetRequiredService>()).Build())
{
for (int i = 0; i < 100; i++)
{
@@ -75,7 +194,16 @@ public async Task ResolveInstrumentedBuildersFromHostServiceProviderTest()
await producer.FlushAsync();
}
- using (var consumer = host.Services.GetRequiredService>().Build())
+ if (enableProducerTraces)
+ {
+ Assert.Equal(100, activities.Count);
+ }
+
+ activities.Clear();
+
+ using (var consumer = (useNamedConsumerInstrumentation
+ ? host.Services.GetRequiredKeyedService>(consumerInstrumentationName)
+ : host.Services.GetRequiredService>()).Build())
{
consumer.Subscribe(topic);
@@ -102,13 +230,36 @@ public async Task ResolveInstrumentedBuildersFromHostServiceProviderTest()
await host.StopAsync();
- Assert.Equal(200, activities.Count);
+ if (enableConsumerTraces)
+ {
+ Assert.Equal(100, activities.Count);
+ }
host.Services.GetRequiredService().EnsureMetricsAreFlushed();
}
IGrouping[] groups = metrics.GroupBy(x => x.Name).ToArray();
- Assert.Equal(4, groups.Length);
+ if (enableProducerMetrics)
+ {
+ Assert.Contains("messaging.publish.messages", groups.Select(x => x.Key));
+ Assert.Contains("messaging.publish.duration", groups.Select(x => x.Key));
+ }
+ else
+ {
+ Assert.DoesNotContain("messaging.publish.messages", groups.Select(x => x.Key));
+ Assert.DoesNotContain("messaging.publish.duration", groups.Select(x => x.Key));
+ }
+
+ if (enableConsumerMetrics)
+ {
+ Assert.Contains("messaging.receive.messages", groups.Select(x => x.Key));
+ Assert.Contains("messaging.receive.duration", groups.Select(x => x.Key));
+ }
+ else
+ {
+ Assert.DoesNotContain("messaging.receive.messages", groups.Select(x => x.Key));
+ Assert.DoesNotContain("messaging.receive.duration", groups.Select(x => x.Key));
+ }
}
}
diff --git a/test/OpenTelemetry.Instrumentation.Wcf.Tests/OpenTelemetry.Instrumentation.Wcf.Tests.csproj b/test/OpenTelemetry.Instrumentation.Wcf.Tests/OpenTelemetry.Instrumentation.Wcf.Tests.csproj
index f95d11bd98..017682e469 100644
--- a/test/OpenTelemetry.Instrumentation.Wcf.Tests/OpenTelemetry.Instrumentation.Wcf.Tests.csproj
+++ b/test/OpenTelemetry.Instrumentation.Wcf.Tests/OpenTelemetry.Instrumentation.Wcf.Tests.csproj
@@ -22,6 +22,8 @@
+
+
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj b/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
index 6892d723eb..d8db5a8c05 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
@@ -7,6 +7,8 @@
+
+