dpol1 commented on code in PR #9154: URL: https://github.com/apache/storm/pull/9154#discussion_r4275628025
########## storm-client/src/jvm/org/apache/storm/tracing/TupleTracer.java: ########## @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 org.apache.storm.tracing; + +import java.util.List; +import java.util.Map; +import org.apache.storm.Config; +import org.apache.storm.task.WorkerTopologyContext; +import org.apache.storm.tuple.Tuple; + +/** + * Attaches a trace context to tuples and records how their tuple trees are processed. Each worker creates one instance from the + * class named in {@link Config#TOPOLOGY_TRACING_TRACER}, through its zero-arg constructor, and shares it between its executors + * and the threads that serialize and deserialize tuples, so implementations must be thread safe. + * + * <p>A context is any object the implementation chooses; null means not traced. Storm keeps it on the tuple and, for the tuple + * trees a spout starts, until the tree completes. Tuples sent to another worker carry the bytes {@link #encode} returns, and the + * receiving worker turns them back into a context with {@link #decode}. + * + * <p>An exception from {@link #decode} leaves the tuple without a context. Exceptions from the other methods propagate to the Review Comment: Yes, it was deliberate, since the OpenTelemetry API doesn't throw. dcc6eaef5 does what you suggest for every method except `prepare()`, and also catches `LinkageError`, which a tracer built against another library version can throw. ########## storm-client/src/jvm/org/apache/storm/executor/bolt/BoltExecutor.java: ########## @@ -224,7 +225,18 @@ public void tupleActionFn(int taskId, TupleImpl tuple) throws Exception { if (isExecuteSampler) { tuple.setExecuteSampleStartTime(now); } - boltObject.execute(tuple); + Object received = tupleTracer == null ? null : tuple.getTraceContext(); + TupleTracer.ExecuteScope scope = + received == null ? null : tupleTracer.startExecute(taskId, tuple, received); + if (scope == null) { + boltObject.execute(tuple); + } else { + try (scope) { + // anchored emits and fail() read the context from the tuple, also after execute() returns + tuple.setTraceContext(scope.context()); + boltObject.execute(tuple); + } + } Long ms = tuple.getExecuteSampleStartTime(); Review Comment: Done in 23de5814c: the execute latency now starts after the scope opens and ends before it closes, while the process latency still includes opening it. `BoltExecutorTest` checks both with simulated time and a mocked tracer that advances the clock. ########## storm-client/src/jvm/org/apache/storm/executor/bolt/BoltOutputCollectorImpl.java: ########## @@ -117,6 +126,26 @@ private List<Integer> boltEmit(String streamId, Collection<Tuple> anchors, List< return outTasks; } + /** + * Returns the trace contexts of the anchors, in anchor order, skipping anchors without one. + */ + private static List<Object> traceContexts(Collection<Tuple> anchors) { Review Comment: Documented in 59f06daf3: "Costs and limits" in Tracing.md says the tracing cost of an emit grows with the number of anchors, for example in windowed bolts. `boltEmit` still gets every anchor's context, since the 128-link cap is an OpenTelemetry SDK setting that another tracer may not have. ########## storm-client/src/jvm/org/apache/storm/executor/spout/SpoutExecutor.java: ########## @@ -379,6 +385,12 @@ public void failSpoutMsg(SpoutExecutor executor, Task taskData, Long timeDelta, if (executor.getIsDebug()) { LOG.info("SPOUT Failing {} : {} REASON: {}", tupleInfo.getRootId(), tupleInfo, reason); } + Object traceContext = tupleInfo.getTraceContext(); + if (traceContext != null) { + TupleTracer.Outcome outcome = "TIMEOUT".equals(reason) ? TupleTracer.Outcome.TIMEOUT : TupleTracer.Outcome.FAIL; Review Comment: Done in 59f06daf3: both places use a `TIMEOUT_REASON` constant. ########## storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java: ########## @@ -662,6 +674,17 @@ public final WorkerUserContext getWorkerUserContext() { } } + private TupleTracer mkTupleTracer() { + String className = (String) topologyConf.get(Config.TOPOLOGY_TRACING_TRACER); + if (className == null) { + return null; + } + TupleTracer tracer = ReflectionUtils.newInstance(className); Review Comment: Documented in 59f06daf3 under "Costs and limits" in Tracing.md: if Storm can't create the tracer class or `prepare()` throws, the worker exits at startup and the supervisor keeps restarting it. The exception is in the worker log. -- 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]
