Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OTEL messaging semantic conventions to Kafka integration #5765

Merged
merged 3 commits into from
Jan 11, 2025

Conversation

g7ed6e
Copy link
Contributor

@g7ed6e g7ed6e commented Sep 18, 2024

Description

Add OTEL messaging semantic conventions to Aspire.ConfluentKafka component/integration.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
      • Link to aspire-docs issue:
    • No
Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 18, 2024
@g7ed6e g7ed6e changed the title Add OTEL messaging semantic conventions Add OTEL messaging semantic conventions to Kafka integration Sep 18, 2024
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Sep 18, 2024

@mitchdenny
Copy link
Member

@mitchdenny Could you add this package https://www.nuget.org/packages/OpenTelemetry.Instrumentation.ConfluentKafka/0.1.0-alpha.2 ?

Its importing now.

@g7ed6e
Copy link
Contributor Author

g7ed6e commented Sep 18, 2024

/azp run

Copy link

Commenter does not have sufficient privileges for PR 5765 in repo dotnet/aspire

@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from 10cb4cb to d19b556 Compare September 18, 2024 11:54
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Sep 18, 2024

@davidfowl / @eerhardt We now have 2 metrics sources.
image

Should we still emit both ? Should we add an AppContext.Switch ?

@g7ed6e g7ed6e marked this pull request as ready for review September 18, 2024 12:06
@eerhardt
Copy link
Member

Should we still emit both ? Should we add an AppContext.Switch ?

I think we should start deprecating the existing one. Either removing it entirely now, or putting it behind an AppContext switch first, and then remove it later.

@eerhardt
Copy link
Member

Can you update

Aspire.Confluent.Kafka:
- Log categories:
- "Aspire.Confluent.Kafka"
- Activity source names:
- none (currently not supported by Confluent.Kafka library)
- Metric names:
- "Aspire.Confluent.Kafka"
- "messaging.kafka.consumer.queue.message_count"
- "messaging.kafka.producer.queue.message_count"
- "messaging.kafka.producer.queue.size"
- "messaging.kafka.network.tx"
- "messaging.kafka.network.transmitted"
- "messaging.kafka.network.rx"
- "messaging.kafka.network.received"
- "messaging.kafka.message.tx"
- "messaging.kafka.message.transmitted"
- "messaging.kafka.message.rx"
- "messaging.kafka.message.received"

@@ -139,6 +139,7 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.ConfluentKafka" Version="0.1.0-alpha.2" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan for shipping this library stable? We won't be able to ship Aspire.Confluent.Kafka stable again until this package goes stable.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that isn't going to happen this calendar year, is that correct?

If that is the case, maybe we need to think about "vendoring" this code and compiling it into the Aspire.Confluent.Kafka library like we do with SqlServer and Redis here:

https://github.com/dotnet/aspire/tree/main/src/Vendoring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're going to need to copy the implementation @eerhardt ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not found any ETA for this. My feeling is more likely - early next year.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're going to need to copy the implementation @eerhardt ?

If we want to continue shipping "stable" versions of the Kafka client integration library.

Copy link
Contributor Author

@g7ed6e g7ed6e Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aspire.Component.Kafka is a bit more than 10k dl while Aspire.Hosting.Kafka is 7-8k. Aspire.Hosting.AppHost is 400-500k.

@eerhardt
Copy link
Member

Can you add some tests?

@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages kafka Issues related to Kafka integrations labels Sep 30, 2024
@davidfowl
Copy link
Member

davidfowl commented Sep 30, 2024

@g7ed6e we're marching towards the date for Aspire 9 shutdown, are you interested in having this support land in 9? (I ask because I think this is a high value change for 9)

@g7ed6e
Copy link
Contributor Author

g7ed6e commented Sep 30, 2024

@davidfowl Yes that would be great. I will try to copy/paste the code from the otel repo this week so we can drop the dependency to the alpha otel package.

@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch 2 times, most recently from ace513b to f9df469 Compare October 4, 2024 06:40
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Oct 4, 2024

Can you update

Aspire.Confluent.Kafka:
- Log categories:
- "Aspire.Confluent.Kafka"
- Activity source names:
- none (currently not supported by Confluent.Kafka library)
- Metric names:
- "Aspire.Confluent.Kafka"
- "messaging.kafka.consumer.queue.message_count"
- "messaging.kafka.producer.queue.message_count"
- "messaging.kafka.producer.queue.size"
- "messaging.kafka.network.tx"
- "messaging.kafka.network.transmitted"
- "messaging.kafka.network.rx"
- "messaging.kafka.network.received"
- "messaging.kafka.message.tx"
- "messaging.kafka.message.transmitted"
- "messaging.kafka.message.rx"
- "messaging.kafka.message.received"

done

@g7ed6e
Copy link
Contributor Author

g7ed6e commented Oct 4, 2024

Should we still emit both ? Should we add an AppContext.Switch ?

I think we should start deprecating the existing one. Either removing it entirely now, or putting it behind an AppContext switch first, and then remove it later.

done.
Behavior is that legacy metrics are no longer emitted, an AppContext switch let users re-enable these metrics. The switch is named EnableAspire8ConfluentKafkaMetrics.

@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from f9df469 to ae1f616 Compare October 9, 2024 15:15
[ModuleInitializer]
public static void Initialize()
{
AppContext.SetSwitch("EnableAspire8ConfluentKafkaMetrics", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do this in the runtimeconfig instead. See

<!-- Enable Azure ActivitySources so Azure Components participate in tracing. -->
<ItemGroup>
<RuntimeHostConfigurationOption Include="Azure.Experimental.EnableActivitySource"
Value="true" />
</ItemGroup>

for an example how to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file isn't removed, it should have a decent name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it contains a ModuleInitializer that set the AppContext switch. How would you name it ? Program.cs ?

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add real tests here. Verify traces are working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt These tests would require a Kafka container running (this is how I wrote the tests in the OTEL repo). Is this what you would like to see here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum I did not noticed yet we were pulling TestContainers. Let's write integration tests :)

Copy link
Contributor Author

@g7ed6e g7ed6e Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt / @mitchdenny TestContainers.Kafka default image is confluentinc/cp-kafka:6.1.9 can you please:

  • add confluentinc/cp-kafka:6.1.9 to netaspireci.azurecr.io
  • add TestContainers.Kafka 3.10.0 to the nuget feed

edit: using the default TestContainers.Kafka default image will ease further maintenance of the UT.

@g7ed6e g7ed6e requested a review from eerhardt October 11, 2024 09:39
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Oct 11, 2024

@davidfowl I updated the PR with integration tests similar to those present in otel repo, i hope we are still able to make this land for .NET9.

CI is failing but should work once:

  • confluentinc/cp-kafka:6.1.9 is added to netaspireci.azurecr.io registry
  • TestContainers.Kafka 3.10.0 to nuget feed

edit: /cc @mitchdenny / @eerhardt

@g7ed6e g7ed6e requested a review from davidfowl October 11, 2024 09:46
@mitchdenny
Copy link
Member

Testcontainers package should be in there in a few moments. I'm working on getting my access sorted for the container image.

@eerhardt
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@eerhardt
Copy link
Member

confluentinc/cp-kafka:6.1.9 is added to netaspireci.azurecr.io registry

We shouldn't be using this container for tests. Instead we should use the Kafka container we reference in our Hosting package -

public const string Image = "confluentinc/confluent-local";
/// <summary>7.7.1</summary>
public const string Tag = "7.7.1";

You can override the TestContainer's image like the following:

public static async Task<RabbitMqContainer> CreateContainerAsync()
{
var container = new RabbitMqBuilder()
.WithImage($"{TestConstants.AspireTestContainerRegistry}/{RabbitMQContainerImageTags.Image}:{RabbitMQContainerImageTags.Tag}")
.Build();

@g7ed6e
Copy link
Contributor Author

g7ed6e commented Oct 16, 2024

confluentinc/cp-kafka:6.1.9 is added to netaspireci.azurecr.io registry

We shouldn't be using this container for tests. Instead we should use the Kafka container we reference in our Hosting package -

public const string Image = "confluentinc/confluent-local";
/// <summary>7.7.1</summary>
public const string Tag = "7.7.1";

You can override the TestContainer's image like the following:

public static async Task<RabbitMqContainer> CreateContainerAsync()
{
var container = new RabbitMqBuilder()
.WithImage($"{TestConstants.AspireTestContainerRegistry}/{RabbitMQContainerImageTags.Image}:{RabbitMQContainerImageTags.Tag}")
.Build();

@eerhardt confluentinc/cp-kafka:6.1.9 and confluentinc/confluent-local do not need the same env variables and startup script won't be compatible between the 2.
So we have 2 posibilities:

  1. drop the dependency on TestContainers.Kafka, pull TestContainer and implement our own KafakContainer and KafkaBuilder.
  2. use the community provided TestContainers.Kafka nuget package and get benefit on its probable future upgrade to confluentinc/confluent-local.

One thought: As the aim of these tests is to validate that the kafka clients behave correctly we could rely on whatever Kafka implementation and should not rely on the actual kafka server version. I mean that the aspire kafka integration should be compatible with others implementation like RedPanda for which a TestContainer.RedPanda NuGet package is published too.

Update: @eerhardt what do you think about not relying to a specific kafka version ?

@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch 2 times, most recently from 0350894 to d025618 Compare November 18, 2024 09:48
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Nov 18, 2024

@eerhardt I've updated the PR adding a specific KafkaContainerBuilder for the requirements of the confluentinc/confluent-local:7.7.1 image. The implementation is inspired by the TestContainers go library which uses a confluentinc/confluent-local 7.x image too. (In opposition to the .NET one which uses a confluentinc/cp-kafka 6.x image).

@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from f0239c7 to 5b2218f Compare November 18, 2024 16:31
@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from 5b2218f to b1748b2 Compare November 27, 2024 15:17
@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from b1748b2 to b283275 Compare December 4, 2024 16:43
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Dec 4, 2024

Hi @mitchdenny it looks like TestContainers.Kafka 4.0.0 package is missing in the feed. Could you please add it ?

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @g7ed6e. This is looking really good. I just have a few comments. Once those are addressed I think we should be able to merge this.

I have added Testcontainers.Kafka 4.0.0 to our nuget mirror so CI should be unblocked.

{
return base.Init()
.WithImage(KafkaImage)
.WithPortBinding(KafkaPort, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to copy all this from test containers? Can't we just override the Image like we do elsewhere?

var container = new RabbitMqBuilder()
.WithImage($"{ComponentTestConstants.AspireTestContainerRegistry}/{RabbitMQContainerImageTags.Image}:{RabbitMQContainerImageTags.Tag}")

Copy link
Contributor Author

@g7ed6e g7ed6e Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can't, that's why i first used the kafka 6.x images.

Please notice that client side packages should not be bound to a specific version of kafka. Confluent.Kafka producer and consumer can be used with other queue system that support the kafka protocol like redpanda or Azure Event Hub. Thus unit tests should not be tied to a specific service provider.

Add a specific KafkaContainerBuilder matching confluentinc/confluent-local:7.7.1 requirements

Update tests/Aspire.Confluent.Kafka.Tests/MeterProviderExtensions.cs

Co-authored-by: Eric Erhardt <[email protected]>

Update ConfigurationSchema.json

Update src/Vendoring/README.md

Co-authored-by: Eric Erhardt <[email protected]>

Use constants
@g7ed6e g7ed6e force-pushed the feature/add-otel-confluentkafka branch from 3077e79 to b0d74c3 Compare December 14, 2024 07:05
@g7ed6e
Copy link
Contributor Author

g7ed6e commented Dec 14, 2024

Sorry for the delay @g7ed6e. This is looking really good. I just have a few comments. Once those are addressed I think we should be able to merge this.

I have added Testcontainers.Kafka 4.0.0 to our nuget mirror so CI should be unblocked.

@eerhardt Thanks. CI is all green now. I updated the PR according to your comments and rebased main branch.

@g7ed6e
Copy link
Contributor Author

g7ed6e commented Jan 10, 2025

@eerhardt may i ask a review ?

@g7ed6e g7ed6e requested a review from eerhardt January 10, 2025 08:14
@eerhardt
Copy link
Member

@eerhardt may i ask a review ?

Yep. Sorry was lost after coming back from the holidays. Looking now.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks for the great work and contribution here.

I just had one nit to follow coding conventions (use a property when used outside of the class). But I think this can be merged.

Since the PR validation hasn't run in a while, we should re-run with the current code just to make sure everything is still green.

@eerhardt eerhardt enabled auto-merge (squash) January 11, 2025 00:14
@eerhardt eerhardt merged commit 7ed8d42 into dotnet:main Jan 11, 2025
9 checks passed
@davidfowl
Copy link
Member

@lmolkova wheh you have some time can you look

@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member kafka Issues related to Kafka integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants