ololo3000 commented on a change in pull request #8204: URL: https://github.com/apache/ignite/pull/8204#discussion_r484302582
########## File path: modules/core/src/main/java/org/apache/ignite/internal/processors/tracing/TraceableIterator.java ########## @@ -0,0 +1,69 @@ +/* + * 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.ignite.internal.processors.tracing; + +import java.util.Iterator; + +import static org.apache.ignite.internal.processors.tracing.SpanTags.ERROR; + +/** + * Represents wrapper which allows the iterator methods to execute within context of a specified span. + */ +public class TraceableIterator<T> implements Iterator<T> { + /** Iterator to which all calls will be delegated. */ + private final Iterator<T> iter; + + /** Span that reperesents trace context in which iterator runs. */ + private final Span span; + + /** + * @param iter Iterator to which all calls will be delegated. + */ + public TraceableIterator(Iterator<T> iter) { + this.iter = iter; + this.span = MTC.span(); + } + + /** {@inheritDoc} */ + @Override public boolean hasNext() { + MTC.supportInitial(span); Review comment: The main reason to use `MTC.supportInitial(span);` is that methods `hasNext` and `next` can be called from user threads for which MTC.span is not set. During this methods execution important spans produce and they should be part of span tree that represents SQL query to which current iterator belongs to. So if we don't use `MTC.supportInitial(span);` this spans will not be inherited from the query root span. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
