Skip to content

Commit

Permalink
add documentation (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhatsura authored Aug 10, 2022
1 parent c93e763 commit ca9e68f
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# confluent-kafka-extensions-opentelemetry
# Confluent.Kafka.Extensions.OpenTelemetry

![GitHub Actions Badge](https://github.com/vhatsura/confluent-kafka-extensions-opentelemetry/actions/workflows/continuous.integration.yml/badge.svg)
[![NuGet Badge](https://buildstats.info/nuget/Confluent.Kafka.Extensions.OpenTelemetry)](https://www.nuget.org/packages/Confluent.Kafka.Extensions.OpenTelemetry/)

The `Confluent.Kafka.Extensions.OpenTelemetry` package enables collection of instrumentation data of the `Confluent.Kafka` library.
The actual instrumentation of the `Confluent.Kafka` library should be configured using
[Confluent.Kafka.Extensions.Diagnostics](https://github.com/vhatsura/confluent-kafka-extensions-diagnostics).

## Installation

```powershell
Install-Package Confluent.Kafka.Extensions.OpenTelemetry
```

## Usage

### Confluent.Kafka configuration

As `Confluent.Kafka` does not expose any instrumentation data, additional, configuration is required.
Full documentation is available at [Confluent.Kafka.Extensions.Diagnostics docs](https://github.com/vhatsura/confluent-kafka-extensions-diagnostics#usage).
There is also an [example](./examples/WebExample) on how to use the package in real world application.

#### Producer

```csharp
using Confluent.Kafka;
using Confluent.Kafka.Extensions.Diagnostics;


using var producer =
new ProducerBuilder<Null, string>(new ProducerConfig(new ClientConfig { BootstrapServers = "localhost:9092" }))
.SetKeySerializer(Serializers.Null)
.SetValueSerializer(Serializers.Utf8)
.BuildWithInstrumentation();

await producer.ProduceAsync("topic", new Message<Null, string> { Value = "Hello World!" });
```

#### Consumer

```csharp
using Confluent.Kafka;
using Confluent.Kafka.Extensions.Diagnostics;

using var consumer = new ConsumerBuilder<Ignore, string>(
new ConsumerConfig(new ClientConfig { BootstrapServers = "localhost:9092" })
{
GroupId = "group", AutoOffsetReset = AutoOffsetReset.Earliest
})
.SetValueDeserializer(Deserializers.Utf8)
.Build();

consumer.Subscribe("topic");

consumer.ConsumeWithInstrumentation((result) =>
{
Console.WriteLine(result.Message.Value);
});
```

### OpenTelemetry configuration

```csharp
using Confluent.Kafka.Extensions.OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

builder.Services.AddOpenTelemetryTracing(traceBuilder =>
{
traceBuilder
.AddInMemoryExporter()
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation()
.AddConfluentKafkaInstrumentation(); // <-- Add Confluent.Kafka OpenTelemetry support
});
```

0 comments on commit ca9e68f

Please sign in to comment.