Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-08-14 Thread via GitHub


stankiewicz commented on PR #39151:
URL: https://github.com/apache/beam/pull/39151#issuecomment-5294578825

   related to https://github.com/apache/beam/issues/33176


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-07-28 Thread via GitHub


stankiewicz merged PR #39151:
URL: https://github.com/apache/beam/pull/39151


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-07-27 Thread via GitHub


github-actions[bot] commented on PR #39151:
URL: https://github.com/apache/beam/pull/39151#issuecomment-5090378898

   Assigning reviewers:
   
   R: @kennknowles for label java.
   R: @sjvanrossum for label kafka.
   
   
   Note: If you would like to opt out of this review, comment `assign to next 
reviewer`.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any 
comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review 
comments).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-06-29 Thread via GitHub


github-actions[bot] commented on PR #39151:
URL: https://github.com/apache/beam/pull/39151#issuecomment-4836325569

   Checks are failing. Will not request review until checks are succeeding. If 
you'd like to override that behavior, comment `assign set of reviewers`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-06-29 Thread via GitHub


gemini-code-assist[bot] commented on PR #39151:
URL: https://github.com/apache/beam/pull/39151#issuecomment-4832888522

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request 
and will post my feedback shortly. In the meantime, here's a summary to help 
you and other reviewers quickly get up to speed!
   
   This pull request enhances observability in Apache Beam KafkaIO by 
integrating OpenTelemetry. It enables distributed tracing by propagating trace 
contexts through Kafka record headers, ensuring that end-to-end traces are 
maintained when messages are produced and consumed within a pipeline. The 
implementation includes configurable toggles and utilizes standard W3C Trace 
Context propagation.
   
   ### Highlights
   
   * **OpenTelemetry Integration**: Introduced OpenTelemetry tracing support 
for KafkaIO, allowing for distributed tracing across Kafka producers and 
consumers in Apache Beam pipelines.
   * **Context Propagation**: Added OpenTelemetryHeaderPropagator and 
OpenTelemetryHeaderConsumer to inject and extract W3C Trace Context headers 
from Kafka records.
   * **Configuration**: Exposed withEnableOpenTelemetryTracing() methods in 
KafkaIO builders to allow users to toggle tracing support.
   
   
   New Features
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code 
Assist** learn from your team's feedback. This makes future code reviews more 
consistent and personalized to your project's style. **Click 
[here](https://codeassist.google/code-review/login) to enable Memory in your 
admin console.**
   
   
   
   Using Gemini Code Assist
   
   
   The full guide for Gemini Code Assist can be found on our [documentation 
page](https://developers.google.com/gemini-code-assist/docs/review-github-code),
 here are some quick tips.
   
   Invoking Gemini
   
   You can request assistance from Gemini at any point by creating a comment 
using either `/gemini ` or `@gemini-code-assist `. Below is a 
summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull 
request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current 
pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, 
both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   Customization
   
   To customize the Gemini Code Assist for GitHub experience, repository 
maintainers can create a configuration file and/or provide a custom code review 
style guide (such as PEP-8 for Python) by creating and adding files to a 
`.gemini/` folder in the base of the repository. Detailed instructions can be 
found 
[here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   Limitations & Feedback
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances 
where its feedback is incorrect or counterproductive. You can react with 
:thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're 
interested in giving your feedback about your experience with Gemini Code 
Assist for GitHub and other Google products, sign up 
[here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), 
[Generative AI Prohibited Use 
Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of 
Service](https://policies.google.com/terms), and learn how to configure Gemini 
Code Assist in GitHub 
[here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
 Gemini can make mistakes, so double check it and [use code with 
caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] [OpenTelemetry] Add tracing support to KafkaIO [beam]

2026-06-29 Thread via GitHub


gemini-code-assist[bot] commented on code in PR #39151:
URL: https://github.com/apache/beam/pull/39151#discussion_r3491885616


##
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##
@@ -2218,6 +2254,76 @@ public void populateDisplayData(DisplayData.Builder 
builder) {
 }
   }
 
+  static class OpenTelemetryHeaderConsumer
+  extends DoFn, KafkaRecord> {
+@Nullable Tracer trace = null;
+
+@Setup
+public void setup(PipelineOptions options) {
+  // inject tracer via options
+  io.opentelemetry.api.OpenTelemetry openTelemetry =
+  options.as(SdkHarnessOptions.class).getOpenTelemetry();
+  if (openTelemetry != null) {
+trace = openTelemetry.getTracer("KafkaIO");
+  }
+}
+
+Context extractSpanContext(KafkaRecord message) {
+  TextMapGetter> extractMessageAttributes =
+  new TextMapGetter>() {
+
+@Override
+public @Nullable String get(@Nullable KafkaRecord carrier, 
String key) {
+
+  Headers headers = 
Preconditions.checkArgumentNotNull(carrier).getHeaders();
+  if (headers == null) return null;
+  Header header = headers.lastHeader(key);
+  if (header == null) return null;
+  return new String(header.value(), UTF_8);
+}
+
+@Override
+public Iterable keys(KafkaRecord carrier) {
+  if (carrier.getHeaders() == null) return ImmutableList.of();
+  return StreamSupport.stream(carrier.getHeaders().spliterator(), 
false)
+  .map(Header::key)
+  .collect(Collectors.toList());
+}
+  };
+  return W3CTraceContextPropagator.getInstance()
+  .extract(Context.current(), message, extractMessageAttributes);
+}

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The `TextMapGetter` implementation should be fully null-safe. The `carrier` 
parameter in `get` and `keys` is annotated as `@Nullable` (or can be null in 
some contexts), so dereferencing it directly without a null check can lead to 
`NullPointerException`s. Additionally, using 
`Preconditions.checkArgumentNotNull` will throw an exception on null, whereas 
the getter should gracefully return `null` or an empty list.
   
   ```java
   Context extractSpanContext(KafkaRecord message) {
 TextMapGetter> extractMessageAttributes =
 new TextMapGetter>() {
   
   @Override
   public @Nullable String get(@Nullable KafkaRecord carrier, 
String key) {
 if (carrier == null) {
   return null;
 }
 Headers headers = carrier.getHeaders();
 if (headers == null) {
   return null;
 }
 Header header = headers.lastHeader(key);
 if (header == null) {
   return null;
 }
 return new String(header.value(), UTF_8);
   }
   
   @Override
   public Iterable keys(@Nullable KafkaRecord 
carrier) {
 if (carrier == null || carrier.getHeaders() == null) {
   return ImmutableList.of();
 }
 return 
StreamSupport.stream(carrier.getHeaders().spliterator(), false)
 .map(Header::key)
 .collect(Collectors.toList());
   }
 };
 return W3CTraceContextPropagator.getInstance()
 .extract(Context.current(), message, extractMessageAttributes);
   }
   ```



##
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##
@@ -2218,6 +2254,76 @@ public void populateDisplayData(DisplayData.Builder 
builder) {
 }
   }
 
+  static class OpenTelemetryHeaderConsumer
+  extends DoFn, KafkaRecord> {
+@Nullable Tracer trace = null;
+
+@Setup
+public void setup(PipelineOptions options) {
+  // inject tracer via options
+  io.opentelemetry.api.OpenTelemetry openTelemetry =
+  options.as(SdkHarnessOptions.class).getOpenTelemetry();
+  if (openTelemetry != null) {
+trace = openTelemetry.getTracer("KafkaIO");
+  }
+}
+
+Context extractSpanContext(KafkaRecord message) {
+  TextMapGetter> extractMessageAttributes =
+  new TextMapGetter>() {
+
+@Override
+public @Nullable String get(@Nullable KafkaRecord carrier, 
String key) {
+
+  Headers headers = 
Preconditions.checkArgumentNotNull(carrier).getHeaders();
+  if (headers == null) return null;
+  Header header = headers.lastHeader(key);
+  if (header == null) return null;
+  return new String(header.value(), UTF_8);
+}
+
+@Override
+public Iterable keys(KafkaRecord carrier) {
+