<commit_before>package bio.terra.common.stairway;

import bio.terra.stairway.DynamicHook;
import bio.terra.stairway.Flight;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.FlightMap;
import bio.terra.stairway.HookAction;
import bio.terra.stairway.StairwayHook;
import bio.terra.stairway.Step;
import io.opencensus.common.Scope;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Link;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanContext;
import io.opencensus.trace.Tracer;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.propagation.SpanContextParseException;
import java.util.Base64;
import java.util.Optional;
import org.apache.commons.lang3.ClassUtils;

/**
 * A {@link StairwayHook} to add support for tracing execution of Stairway flights with OpenCensus.
 *
 * <p>This hook uses Spans at 3 different levels. From lowest to highest:
 * <li>A Span around the execution of each Step, one Span per Step execution. All of the {@link
 *     Step#doStep(FlightContext)} {@link Step#undoStep(FlightContext)} will be executed in the
 *     context of this Span.
 * <li>A Span around the execution of each Flight, one Span per {@link Flight#run()}. Note that a
 *     single Flight may be run multiple times if its execution is paused and resumed. Each Step
 *     Span is a child Span of a Flight Span.
 * <li>A linked Span for the entire Flight submission. Each Flight Span has a parent link to the
 *     submission span. See <a href="https://opencensus.io/tracing/span/link/">OpenCensus Link</a>.
 *     The submission span is used to correlate all of the Flight Spans together. The submission
 *     Span may be created outside of the context of this hook and passed in with the input
 *     FlightMap; this allows all of the Flight Spans to be linked to the request Span that
 *     initiated the Flight. See {@link #serializeCurrentTracingContext()} {@link
 *     #SUBMISSION_SPAN_CONTEXT_MAP_KEY}. If no submission Span is passed into the Flight, a dummy
 *     Submission span is created by this hook so that all Flight Spans are still correlated.
 *
 *     <p>If a Span is not ended, it will not be exported to the tracing service.
 *
 * @see <a href="https://opencensus.io/tracing/">https://opencensus.io/tracing/</a>
 */
public class TracingHook implements StairwayHook {
  private final Tracer tracer = Tracing.getTracer();<commit_msg>PF-281 Try to fix the javadoc so that we can publish to artifactory. (#16)<commit_after>package bio.terra.common.stairway;

import bio.terra.stairway.DynamicHook;
import bio.terra.stairway.Flight;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.FlightMap;
import bio.terra.stairway.HookAction;
import bio.terra.stairway.StairwayHook;
import bio.terra.stairway.Step;
import io.opencensus.common.Scope;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Link;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanContext;
import io.opencensus.trace.Tracer;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.propagation.SpanContextParseException;
import java.util.Base64;
import java.util.Optional;
import org.apache.commons.lang3.ClassUtils;

/**
 * A {@link StairwayHook} to add support for tracing execution of Stairway flights with OpenCensus.
 *
 * <p>This hook uses Spans at 3 different levels. From lowest to highest:
 *
 * <ul>
 *   <li>A Span around the execution of each Step, one Span per Step execution. All of the {@link
 *       Step#doStep(FlightContext)} {@link Step#undoStep(FlightContext)} will be executed in the
 *       context of this Span.
 *   <li>A Span around the execution of each Flight, one Span per {@link Flight#run()}. Note that a
 *       single Flight may be run multiple times if its execution is paused and resumed. Each Step
 *       Span is a child Span of a Flight Span.
 *   <li>A linked Span for the entire Flight submission. Each Flight Span has a parent link to the
 *       submission span. See <a href="https://opencensus.io/tracing/span/link/">OpenCensus
 *       Link</a>. The submission span is used to correlate all of the Flight Spans together. The
 *       submission Span may be created outside of the context of this hook and passed in with the
 *       input FlightMap; this allows all of the Flight Spans to be linked to the request Span that
 *       initiated the Flight. See {@link #serializeCurrentTracingContext()} {@link
 *       #SUBMISSION_SPAN_CONTEXT_MAP_KEY}. If no submission Span is passed into the Flight, a dummy
 *       Submission span is created by this hook so that all Flight Spans are still correlated.
 * </ul>
 *
 * <p>If a Span is not ended, it will not be exported to the tracing service.
 *
 * @see <a href="https://opencensus.io/tracing/">https://opencensus.io/tracing/</a>
 */
public class TracingHook implements StairwayHook {
  private final Tracer tracer = Tracing.getTracer();
{'fraction_non_alphanumeric': 0.08766956873861105, 'fraction_numerical': 0.0026321117635148814, 'mean_word_length': 4.108583247156153, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3518902', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1485, 'n_words': 548}