-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kafka-tracing: injects init context on forward (#1409)
Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
1 parent
328107c
commit 6224d3f
Showing
11 changed files
with
315 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...tion/kafka-streams/src/main/java/brave/kafka/streams/TracingFixedKeyProcessorContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2013-2024 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package brave.kafka.streams; | ||
|
||
import brave.propagation.TraceContext; | ||
import org.apache.kafka.common.header.Headers; | ||
import org.apache.kafka.streams.processor.api.FixedKeyProcessorContext; | ||
import org.apache.kafka.streams.processor.api.FixedKeyRecord; | ||
|
||
/** Injects the initialization tracing context to record headers on forward */ | ||
final class TracingFixedKeyProcessorContext<KForward, VForward> | ||
extends TracingProcessingContext<FixedKeyProcessorContext<KForward, VForward>> | ||
implements FixedKeyProcessorContext<KForward, VForward> { | ||
|
||
TracingFixedKeyProcessorContext(FixedKeyProcessorContext<KForward, VForward> delegate, | ||
TraceContext.Injector<Headers> injector, TraceContext context) { | ||
super(delegate, injector, context); | ||
} | ||
|
||
@Override public <K extends KForward, V extends VForward> void forward(FixedKeyRecord<K, V> r) { | ||
injector.inject(context, r.headers()); | ||
delegate.forward(r); | ||
} | ||
|
||
@Override | ||
public <K extends KForward, V extends VForward> void forward(FixedKeyRecord<K, V> r, String s) { | ||
injector.inject(context, r.headers()); | ||
delegate.forward(r, s); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...rumentation/kafka-streams/src/main/java/brave/kafka/streams/TracingProcessingContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2013-2024 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package brave.kafka.streams; | ||
|
||
import brave.propagation.TraceContext; | ||
import brave.propagation.TraceContext.Injector; | ||
import java.io.File; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.apache.kafka.common.header.Headers; | ||
import org.apache.kafka.common.serialization.Serde; | ||
import org.apache.kafka.streams.StreamsMetrics; | ||
import org.apache.kafka.streams.processor.Cancellable; | ||
import org.apache.kafka.streams.processor.PunctuationType; | ||
import org.apache.kafka.streams.processor.Punctuator; | ||
import org.apache.kafka.streams.processor.StateStore; | ||
import org.apache.kafka.streams.processor.TaskId; | ||
import org.apache.kafka.streams.processor.api.ProcessingContext; | ||
import org.apache.kafka.streams.processor.api.RecordMetadata; | ||
|
||
abstract class TracingProcessingContext<C extends ProcessingContext> implements ProcessingContext { | ||
final C delegate; | ||
final Injector<Headers> injector; | ||
final TraceContext context; | ||
|
||
TracingProcessingContext(C delegate, Injector<Headers> injector, | ||
TraceContext context) { | ||
this.delegate = delegate; | ||
this.injector = injector; | ||
this.context = context; | ||
} | ||
|
||
@Override public String applicationId() { | ||
return delegate.applicationId(); | ||
} | ||
|
||
@Override public TaskId taskId() { | ||
return delegate.taskId(); | ||
} | ||
|
||
@Override public Optional<RecordMetadata> recordMetadata() { | ||
return delegate.recordMetadata(); | ||
} | ||
|
||
@Override public Serde<?> keySerde() { | ||
return delegate.keySerde(); | ||
} | ||
|
||
@Override public Serde<?> valueSerde() { | ||
return delegate.valueSerde(); | ||
} | ||
|
||
@Override public File stateDir() { | ||
return delegate.stateDir(); | ||
} | ||
|
||
@Override public StreamsMetrics metrics() { | ||
return delegate.metrics(); | ||
} | ||
|
||
@Override public <S extends StateStore> S getStateStore(String s) { | ||
return delegate.getStateStore(s); | ||
} | ||
|
||
@Override public Cancellable schedule(Duration duration, PunctuationType punctuationType, | ||
Punctuator punctuator) { | ||
return delegate.schedule(duration, punctuationType, punctuator); | ||
} | ||
|
||
@Override public void commit() { | ||
delegate.commit(); | ||
} | ||
|
||
@Override public Map<String, Object> appConfigs() { | ||
return delegate.appConfigs(); | ||
} | ||
|
||
@Override public Map<String, Object> appConfigsWithPrefix(String s) { | ||
return delegate.appConfigsWithPrefix(s); | ||
} | ||
|
||
@Override public long currentSystemTimeMs() { | ||
return delegate.currentSystemTimeMs(); | ||
} | ||
|
||
@Override public long currentStreamTimeMs() { | ||
return delegate.currentStreamTimeMs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
instrumentation/kafka-streams/src/main/java/brave/kafka/streams/TracingProcessorContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2013-2024 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package brave.kafka.streams; | ||
|
||
import brave.propagation.TraceContext; | ||
import brave.propagation.TraceContext.Injector; | ||
import org.apache.kafka.common.header.Headers; | ||
import org.apache.kafka.streams.processor.api.ProcessorContext; | ||
import org.apache.kafka.streams.processor.api.Record; | ||
|
||
/** Injects the initialization tracing context to record headers on forward */ | ||
final class TracingProcessorContext<KForward, VForward> | ||
extends TracingProcessingContext<ProcessorContext<KForward, VForward>> | ||
implements ProcessorContext<KForward, VForward> { | ||
|
||
TracingProcessorContext(ProcessorContext<KForward, VForward> delegate, | ||
Injector<Headers> injector, TraceContext context) { | ||
super(delegate, injector, context); | ||
} | ||
|
||
@Override public <K extends KForward, V extends VForward> void forward(Record<K, V> r) { | ||
injector.inject(context, r.headers()); | ||
delegate.forward(r); | ||
} | ||
|
||
@Override | ||
public <K extends KForward, V extends VForward> void forward(Record<K, V> r, String s) { | ||
injector.inject(context, r.headers()); | ||
delegate.forward(r, s); | ||
} | ||
} |
Oops, something went wrong.