Comments (2)
Update:
I just realized that the InstrumentedProducerBuilder derives from the Confluent ProducerBuilder and has all the methods I need. Please ignore my original comment.
Original comment: (Obsolete)
@g7ed6e
I'd love to use this package. I am trying to use the InstrumentedProducerBuilder
in my project but I see no way to extend it with my additional ProducerBuilder
methods.
I could have my own ProducerBuilder
implementation and create the InstrumentedProducer
, but it is internal. Could you make both the InstrumentedProducer
and InstrumentedConsumer
public? I'd like to build the Confluent.Kafka.Producer
and Confluent.Kafka.Consumer
myself and then wrap them with the InstrumentedProducer
and InstrumentedConsumer
classes.
using Confluent.Kafka;
public static class ProducerBuilderExtensions
{
public static ProducerBuilder<TKey, TValue> UseDefaultErrorHandler<TKey, TValue>(this ProducerBuilder<TKey, TValue> builder, ILogger logger)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(logger);
builder.SetErrorHandler((self, e) =>
{
// TODO: figure out how periodic Local_AllBrokersDown could be avoided via configuration
var logLevel = e.Code == ErrorCode.Local_AllBrokersDown ? LogLevel.Debug : LogLevel.Error;
logger.Log(logLevel, "Kafka producer error: ErrorCode:{ErrorCode}, Reason:{Reason}, Name:{Name}", e.Code, e.Reason, self.Name);
});
return builder;
}
public static ProducerBuilder<TKey, TValue> UseDefaultLogHandler<TKey, TValue>(this ProducerBuilder<TKey, TValue> builder, ILogger logger)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(logger);
builder.SetLogHandler((_, log) => log.LogWithLogger("Kafka producer", logger));
return builder;
}
}
from opentelemetry-dotnet-contrib.
It seems I can only use InstrumentedProducerBuilder
using DI. Depending on the complexity of the application this can make the migration from the ProducerBuilder
to the InstrumentedProducerBuilder
very painful. I wish there would be a way to just replace the ProducerBuilder
with the InstrumentedProducerBuilder
.
Could we have another constructor with an additional Options parameter?
Update 1:
I hacked these constructors to the library and I was able to replace all of my ProducerBuilder and ConsumerBuilder lines.
I also needed to make the ConfluentKafkaCommon.InstrumentationName public so that I could enable metrics and traces without changing my DI. Now all the Kafka metrics and traces are showing up for my application. InstrumentedConsumer and InstrumentedProducer are very nice.
Please let us use this library without having all the Kafka consumers and producers needed to be migrated to DI.
public InstrumentedConsumerBuilder(IEnumerable<KeyValuePair<string, string>> config, bool enableMetrics, bool enabledTraces)
: base(config)
{
this.Options = new ConfluentKafkaConsumerInstrumentationOptions<TKey, TValue>
{
Metrics = enableMetrics,
Traces = enabledTraces,
};
}
public InstrumentedProducerBuilder(IEnumerable<KeyValuePair<string, string>> config, bool enableMetrics, bool enabledTraces)
: base(config)
{
this.Options = new ConfluentKafkaProducerInstrumentationOptions<TKey, TValue>
{
Metrics = enableMetrics,
Traces = enabledTraces,
};
}
builder.Services.AddOpenTelemetry()
.WithMetrics(c =>
{
c.AddMeter(ConfluentKafkaCommon.InstrumentationName);
c.AddOtlpExporter();
})
.WithTracing(c =>
{
c.AddSource(ConfluentKafkaCommon.InstrumentationName);
c.AddOtlpExporter();
})
from opentelemetry-dotnet-contrib.
Related Issues (20)
- [Resources.Azure] Rename `AddAppServiceDetector` to `AddAzureAppServiceDetector` HOT 1
- Rename `OpenTelemetry.Instrumentation.StackExchangeRedis` to a more generic name HOT 1
- [HttpClient] add {target} to span name
- RuntimeInstrumentationOptions has no properties HOT 1
- AWS X-Ray traces without span info
- [ConfluentKafka] Implement a process span to ease connecting traces
- Add unit tests to ConfluentKafka instrumentration
- Add CoreWCF Instrumentation HOT 1
- Migrate semantic conventions generation to Weaver
- Activity.DisplayName is overwritten by instrumentation libraries HOT 10
- Missing documentation for `OTEL_DOTNET_EXPERIMENTAL_OWIN_DISABLE_URL_QUERY_REDACTION` HOT 5
- [Instrumentation.StackExchangeRedis] Vunerability warning due to transitive dependency HOT 1
- AWS Instrumenting doesn't work when AWS DynamoDb Client is created in a DI class
- Make DisableUrlQueryRedaction option in OpenTelemetry.Instrumentation.Http public HOT 2
- Add additional os.types HOT 1
- Populate additional os fields HOT 1
- Provide OS Platform HOT 2
- `OTEL_DOTNET_EXPERIMENTAL_{component}_DISABLE_URL_QUERY_REDACTION` is not honored via `Configuration` for `Owin` and `AspNet` instrumentations HOT 6
- Registering instrumentation libraries more than once adds duplicate Activity listeners
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opentelemetry-dotnet-contrib.